[antlr-interest] Re: Handling identifiers
mafw14
98vdxjfr02 at sneakemail.com
Thu Jul 24 01:24:03 PDT 2003
--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> Do identifiers get declared?
>
> You may need to handle this in the parser, the same way I handle
typedefs in
> the gcc grammar http://www.codetransform.com/gcc.html with a
semantic
> predicate.
>
> Could you give some sample text?
> How do you know when to put an identifier into the literals hash
table?
Thanks for your reply. The identifiers are not declared within
the language but are predefined. I do not want to include them
as keywords in the language but have a class that defines them
so the identifiers can be changed and that each identifier can
have attributes (such as data type). The language is stronly
typed so I want to prevent an integer being compared with a
float etc.
I think I have partly figured it out now - I have modified
the rule for an identifier as follows:
IDENTIFIER
options {testLiterals=true; }
: t:LETTERS
{
if (Identifier.isNotIdentifier(t.getText()))
{
$setType(STRING_T);
}
}
;
I wish to save the data type of each literal or identifier on
the AST. Is there an easy way to extend the AST to store
additional attibutes? BTW: This parser is only used as a
checker and does not generate any code.
A sample of the text of the language is:
(MSG_TYPE = XXX) AND (VALUE > 0.001) OR NOT (SOURCE IN ["S1", "S22"])
where MSG_TYPE and SOURCE are identifiers of type STRING_T and
VALUE is of type REAL_T. XXX is a literal string (does not have to
be enclosed in quotes). The square brackets enclose a set of
strings.
Thanks, Mark.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list