Parsing some particular statements with antlr3 in C target

Posted by JCD on Stack Overflow See other posts from Stack Overflow or by JCD
Published on 2010-05-25T13:36:05Z Indexed on 2010/05/25 13:41 UTC
Read the original article Hit count: 488

Filed under:
|
|
|

Hello all!

I have some questions about antlr3 with tree grammar in C target.

I have almost done my interpretor (functions, variables, boolean and math expressions ok) and i have kept the most difficult statements for the end (like if, switch, etc.)

1) I would like interpreting a simple loop statement:

repeat: ^(REPEAT DIGIT stmt);

I've seen many examples but nothing about the tree walker (only a topic here with the macros MARK() / REWIND(m) + @init / @after but not working (i've antlr errors: "unexpected node at offset 0")). How can i interpret this statement in C?

2) Same question with a simple if statement:

if: ^(IF condition stmt elseifstmt* elsestmt?);

The problem is to skip the statement if the condition is false and test the other elseif/else statements.

3) I have some statements which can stop the script (like "break" or "exit"). How can i interrupt the tree walker and skip the following tokens?

4) When a lexer or parser error is detected, antlr returns an error. But i would like to make my homemade error messages. How can i have the line number where parser crashed?

Ask me if you want more details.

Thanks you very much (and i apologize for my poor english)

© Stack Overflow or respective owner

Related posts about c

    Related posts about parsing