An ambiguous grammar solution without resorting to GLR-Parser

I have a grammar that has two different possibilities in the analysis 'if' expr 'then'. There is a simple "assignment", for example if foo then bar=1; else bar=0;, that is, what I call "if_block" code, which may contain one or more "assignments":

if foo then
{
    bar = 1;
    if xyz then abc = -1;
}
else
{
    bar = 0;
    if xyz then
    {
       abc = 0;
    }
}

I handle nested if_blocks with the dangling else of a matched / inconsistent block.

My ( very simplified) grammar is basically:

program : if_blocks
if_blocks : if_block | if_block if_blocks
if_block : assignments
assignments : assignment | assignment assignments
assignment : simple_assignment | if_assignment

So, my predicament is related to the assignment, followed by if_block. For instance:

foo = bar;
if foo then
{
   foo = foo + 1;
}

foo = bar; - , if_block. if foo then { ... } if_block. , if_block + if_block ( if_blocks). , foo = bar; , , if foo then ( foo = bar; if_block), if_block.

%glr-parser, , , , , , S/R. , / ( , ) ( )? (- %dprec?) GLR ?

+3
1

-else , , else , , () . - , .

( YACC Bison) , shift-vs-reduce "", else. , YACC Bison, .

( GLR, , ).

+1

Source: https://habr.com/ru/post/1777957/


All Articles