Thread: Lemon parser generator & embedded actions

  1. #1
    Making mistakes
    Join Date
    Dec 2008

    Lemon parser generator & embedded actions

    Hi everyone,
    I'm currently translating a program from yacc to lemon for thread-safety, but I have a single problem with that. I'm using some more complicated rules where there are actions between the terminals, for example:

    rule: token { token_count++; } something { token_count += $3->token_count; } end { $$ = whatever(); }
    It is necessary that the actions are performed in order, that means, that token_count should be increased before reducing something.

    Is there any possibility to use this feature in lemon?
    Last edited by Brafil; 05-16-2010 at 07:45 AM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Lemon can only trigger an action after the whole rule is reduced. So break the yacc rule into several Lemon ones.

    rule ::= token_action something_action(A) end_action. { result = whatever(); }
    token_action ::= token. { token_count++; }
    something_action ::= something. { token_count += A->token_count; }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 09:54 AM