Hi all
I've found a number of discussions (almost all discussions) about non
reserved keywords (aka "soft" keywords)
http://groups.google.com/group/comp.compilers.tools.javacc/search?group=comp.compilers.tools.javacc&q=keywords&qt_g=Ricerca+in+questo+gruppo
I glanced to some JavaCC grammars in the the repository, as well, to
understand how to handle regular (reserved) keywords.
In the Gpl.jj file there is now the following token definition
TOKEN : // reserved words
{ < FALSE: "false" >
| < IF: "if" >
| < TRUE: "true" >
}
A short run on comman line of the grammar with the "a + if" input lead
to the following output and diagnostic
Call: ExpressionList
Type in an expression followed by a ";" or ^D to quit:
a + if;
Call: Expression
Call: Term
Call: Factor
Call: Primary
Consumed token: <<GROUP_ID>: "a" at line 1 column 1>
Return: Primary
Return: Factor
Return: Term
Consumed token: <"+" at line 1 column 3>
Call: Term
Call: Factor
Return: Factor
Return: Term
Return: Expression
Return: ExpressionList
Exception in thread "main"
it.finmatica.gpj.ec.istruzioni.gpl.ParseException: Encountered "if" at
line 1, column 5.
Was expecting one of:
<PAR_OPEN> ...
<NUMBER_LITERAL> ...
"-" ...
<GROUP_ID> ...
at
it.finmatica.gpj.ec.istruzioni.gpl.Gpl.generateParseException(Gpl.jav
a:471)
at
it.finmatica.gpj.ec.istruzioni.gpl.Gpl.jj_consume_token(Gpl.java:406)
....
The "if" string literal now is correctly recognized as <IF> token that
is NOT accepted by the the given definition of the Primary() /
Factor() productions.
Anyway, the diagnostic does not mention at all that... "if" is a
reserved keyword.
I have no idea if the diagnostic will be better (more clear) when the
definition of the IfStatement() production will be ready.
Any suggestion?
ciao
Cesare