help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Debugging "$4"


From: Hans Åberg
Subject: Re: Debugging "$4"
Date: Thu, 8 Oct 2020 18:06:15 +0200

> On 7 Oct 2020, at 22:52, Maury Markowitz <maury.markowitz@gmail.com> wrote:
> 
> I have these rules in my BASIC.y:
> 
> statements:
>       statement
>       {
>         $$ = g_list_prepend(NULL, $1);
>       }
>       |
>        statement ':' statements
>        {
>         $$ = g_list_prepend($3, $1);
>        }
>       ;

When you compile, did you get a shift/reduce conflict? —I recall Bison chooses 
the reduce over shift.

One can see these in the .output file, generated when invoking the verbose 
option, see the Bison manual, 8.1 Understanding Your Parser.

Also, left recursion is preferred, see 3.3.3 Recursive Rules.

And one can use $ variable names, more readable and avoid mistakes:
  IF expression[x] THEN statements[y] { … $x … $y … }

> statement:
> (among others...)
>       IF expression THEN statements
>       {
>         statement_t *new = make_statement(IF);
>         new->parms._if.condition = $2;
>         new->parms._if.then_expression = $4;
>         new->parms._if.then_linenumber = 0;
>         $$ = new;
>       }
> 
> There is a single routine that runs the statements. When I feed it this:
> 
> 100 PRINT "1":PRINT"2"
> 
> I get 1\n2 as expected. However, when I tell it to run then_expression with 
> statements
> 
> 200 IF 1=1 THEN PRINT"3":PRINT"4"
> 
> I get only 3. I *believe* that $4 is a correctly formatted g_list of 
> statements, but how do I test that assumption? How does one print out the 
> value of $4 in the debugger? 

Also perhaps try using a terminator on the rule, just to see if something 
changes.
  IF expression THEN statements "."

In BASIC, there is probably an expected implicit line terminator. It might help 
simplifying the grammar by implementing it in the lexer.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]