[antlr-interest] Parsing Best Practices---Where to check for predefined names
Matthew M. Burke
mmburke at gwu.edu
Mon May 4 18:12:46 PDT 2009
I am building a parser for a language that has the following syntax
<name args*>
for function invocations and a few "function-like" usages. In
particular, statements such as
Set <array 5> 17
are valid for a handful of predefined names. In my grammar, I have a
rule which describes what's allowed to be on the left-hand side of an
assignment and I'm trying to decide between two possibilities for
handling these "function-like" cases:
1) I could go with something that matches '<' ID expr* '>' and then in
the parser action, I can test ID.text and act as appropriate
or
2) I could do something like
lhs
: '<' 'array' expr '>' -> ^(ARRAY_REF expr)
| '<' 'socket' expr '>' -> ^(SOCKET_REF expr)
| ...
;
Is either alternative especially better than the other?
Matt
More information about the antlr-interest
mailing list