Hi all
I took the NL_Xlator grammar (see javacc-4.0\examples\SimpleExamples
\NL_Xlator.jj) as starting point for my grammar (named GpL) for a
relatively simple "arithmetic" language enriched with a limited set of
other features.
Currently the application has some entities with a string description
and its micro grammar
(identifiers, string and number literals, group names, and so on).
Current entities have their hand-coded token analyzers which have been
already unit tested.
E.g.
The Identifiers ("names" in the application jargon) do correspond to
the token
<ID : ["a"-"z", "A"-"Z","_"] ( ["a"-"z", "A"-"Z", "_", "0"-"9"] )* >
and have their domain class NameDom with its method canHadfle() that
analyzes if the provided string does respect the grammar rule quoted
just above.
The same holds for other enties (terminals).
I have the first skeleton of GpL.jj NL_XLator derived grammar.
I wrote the terminal
TOKEN :
{ <ID : ["a"-"z", "A"-"Z","_"] ( ["a"-"z", "A"-"Z", "_", "0"-"9"] )* >
| <NUM: (["0"-"9"])+ >
| <STRING_LITERAL
: "\"" ( ~["\"","\\","\n","\r"]
| "\\" ( ["n","t","r","f","\\","\'","\""] )?
| ( ["\n","\r"] | "\r\n" )
)* "\""
>
}
and some non-terrminal rules (see javacc-4.0\examples\SimpleExamples
\NL_Xlator.jj)
ExpresssionList
-> Expression
-> Term
-> Factor()
To test a single, specific rule I isolated an Id() rule to call it
from the unit test class
String
Id() :
{
Token lToken;
String lResult;
}
{
lToken = <ID>
{
lResult = lToken.image;
return lResult;
}
} // end GpL.Id()
Well, to test specifically the <ID> / Id() rule for identifiers, I
called the GpL.Id() method from the UT class and it would seem to
work.
Identifiers as
Call: Id
Consumed token: <<ID>: "myName_1_isOk" at line 1 column 1>
Return: Id
Call: Id
Consumed token: <<ID>: "_Foo2_boo2_goo2" at line 1 column 1>
Return: Id
are may others are all correctly "approved".
Instead the
"foo2 boo2"
string (that is NOT an <ID>) is wrogly approved (no ParseExpceptin is
thrown)
GpL.jj does contain the production
SKIP :
{ " "
| "\t"
| "\n"
| "\r"
}
as well, but I would like that no skipping would be performed during
the <ID> / Id() rule.
Any suggestion?
Thanks in advance for any reply.
Ciao
Cesare


|