[antlr-interest] Diference bettew Tokens and Lexical Rules
John B. Brodie
jbb at acm.org
Wed Aug 11 19:37:10 PDT 2010
Greetings!
On Wed, 2010-08-11 at 22:57 -0300, Victor Giordano wrote:
> Hi there!!. How you doing guys? Hope good!.
I am fine, I hope you are too!
> A have another question about tokens and lexical rules, i really don't
> get the idea...
> For example, assume we have this:
>
> 1)
> tokens
> {
> PLUS= '+';
> }
>
> 2) PLUS : '+';
>
> and then a rule
> expr: INT (PLUS INT)*;
>
> so... if a use one of another is exactly the same. The parse tree is the
> same, and the generated AST is also the same.
> Can you help me, and try to explain it to me. I read the book, but i
> don't understand.
>
As you have discovered, in this instance, ANTLR has 2 ways to express
the same concept.
There is, I believe, nothing else to explain here. You have correctly
analyzed that specifying a string value in the tokens{} block is
equivalent to specifying a lexical rule. Not a problem.
Perhaps I have mis-understood your question, please try to re-state your
question if you are still confused by these two equivalent
meta-syntactic constructs.
Hope this helps...
-jbb
More information about the antlr-interest
mailing list