[antlr-interest] Context-dependent lexer?
Maurizio Tomasi
tomasi at lambrate.inaf.it
Mon Nov 13 01:16:34 PST 2006
Hi to all,
This is the first time I post to this list. I am using ANTLR 2.7.4 to
develop an interpreter for ESARAD, a language used for radiative thermal
analysis of satellites. This is a simple case-insensitive procedural
language, but supports a feature I am not able to model with ANTLR.
Variables must be declared, and there are plenty of types. To declare a
variable of type "COORDINATE" e.g. you write:
COORDINATE dummy;
The program supports procedure calls using keywords (like python):
CREATE_OBJECT (coordinate = my_position, bulk = my_bulk);
Some keywords share the same name with variable types, as in the case of
"COORDINATE". This is a problem for the lexer, as COORDINATE can be
considered either an identifier (when used inside a function call) or a
reserved word (anywhere else).
Using Flex, I would simply use a start condition when inside
parentheses, e.g.
coordinate { return TOK_COORDINATE; }
[a-z][a-z0-9]* { return TOK_IDENTIFIER; }
( BEGIN(PARENTHESES);
<PARENTHESES>[a-z][a-z0-9]* { return TOK_IDENTIFIER; }
and then taking care for nested parentheses and so on. How can I
implement this using ANTLR?
Thank you very much,
Maurizio Tomasi.
More information about the antlr-interest
mailing list