Question

so, I am parsing Hayes modem AT commands. Not read from a file, but passed as char * (I am using C).

1) what happens if I get something that I totally don't recognize? How do I handle that? 2) what if I have something like

my_token: "cmd param=" ("value_1" | "value_2");

and receive an invalid value for "param"?

I see some advice to let the back-end program (in C) handle it, but that goes against the grain for me. Catch teh problem as early as you can, is my motto.

Is there any way to catch "else" conditions in lexer/parser rules?

Thanks in advance ...

Was it helpful?

Solution

I think you're looking for Custom Syntax Error Recovery to embed in your grammar.

EDIT

I've no experience with ANTLR and C (or C alone for that matter), so follow this advice with caution! :)

Looking at the page: http://www.antlr.org/api/C/using.html, perhaps the part at the bottom, Implementing Customized Methods is what you're after.

HTH

OTHER TIPS

That's the thing: the whole point of your parser and lexer is to blow up if you get bad input, then you catch the blow up and present a pretty error message to the user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top