Thank you for all your answers. The language I am trying to implement is quite complex, unfortunately. It has various --and also optional-- block-like structures. Hence I personally would prefer setting the context variable for the lexer, over rearranging the whole grammar just for this nagging semicolon-rule. What I tried was following:

Block
    : '{' Statements '}'
    ;

Statements
    :            Statement Semicolon
    | Statements Statement Semicolon
    ;

Semicolon
    : { driver.expect_semicolon = 1; } ';'
    ;

If expect_semicolon is set and the lexer reads a '}', it then will unput this character and return a ';' instead. My problem is, expect_semicolon is set _after_ the next is already read and the ';'-injection is too late. What am I missing?


_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to