help-bison
[Top][All Lists]
Advanced

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

Re: Can one prune the parse stack?


From: Mike Aubury
Subject: Re: Can one prune the parse stack?
Date: Thu, 26 Aug 2010 22:17:55 +0100

Ok - theres the problem..
Firstly - the parser probably wont see blank lines - they'll have been
taken out by your tokeniser (lex/flex - whatever)..
So - the 'stream' should probably be written something like :

stream :
     stmt
    | stream stmt
;

and similarly for the assignments :

assignment_list:
          assignment
        | assignment_list SEMIKOLON assignment
;

(notice the assignment_list is moved to the left hand side in that
second portion)


I'm not too familar with 'error' - but from the docs - something like :

stmt:     LANGLE assignment_list RANGLE
    | LANGLE error RANGLE
;






On 26 August 2010 22:08, Christoph Lechner <address@hidden> wrote:
> Mike Aubury wrote:
>> I'm thinking your grammar is probably wrong - there shouldn't be any
>> problem with having lots of packets like that - so long and they are
>> not very recursive (packet within packet within packet .....)
>> What does your grammar look like ?
> @Mike: Sorry for sending my first reply to you and not to the list. So
> here is my mail to the list.
>
> Hi,
>
> thank you for your fast reply. I think I found the mistake now -- I
> guess it's the 'stream' rule.
>
> The beginning of my grammar is like:
>
> stream:   /* empty line */
>        | stmt stream
>        | error stream
>        ;
>
> stmt:     LANGLE assignment_list RANGLE         { /* here the data of the
> command is available */ }
>        ;
>
> assignment_list:
>          assignment
>        | assignment SEMIKOLON assignment_list
>        ;
> [..]
>
> So, I think I identified my mistake. When I remove the top 'stream' rule
> and make 'stmt' the new top rule, is it supposed to work then?
> As I think about it now, my grammar is more like one does when parsing a
> programming language. There, the all the statements as a whole form the
> program, so one needs something like my 'stream' rule. But here the
> statements are independent, so now I think the 'stream' rule isn't
> necessary.
>
> When I make stmt the new top rule, is yyparse supposed to exit (and
> clean up), once it parsed a single statement?
>
> Am I correct?
>
> CU
> - Christoph
>
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>



reply via email to

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