[antlr-interest] warning: redefinition of token in tokens (was Re: ambiguous grammar)

beeh1973 <bendt at inf.fu-berlin.de> bendt at inf.fu-berlin.de
Sat Jan 25 06:51:41 PST 2003


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> The easiest way to get the tree you want will be to modify your 
lexer to
> remember that you just saw a $ and that you need to produce DOT, 
not FLOAT.
> "Lexer states" is one approach to this (see docs).  Another would 
be to use
> semantic predicates in the lexer.

thanks a lot. it took me some time to understand but this is exactly 
what i was looking for.

unfortunately i encountered a new problem, maybe someone can help me:

as both lexers need to share a common vocabulary i created a file 
CommonTokenTypes.txt, put in the common tokens and imported it in 
both lexers and the parser. compare with example below.

in the parser i am adding the AST Option to the imported Tokens.
this causes a warning for Example: 'warning:Redefinition of token in 
tokens {...}: AND'

The generated Parser works as expected. So maybe theres just a switch 
to turn the warning off?

example:

CommonTokenTypes.txt:

AND=4
...

lexer1.g:

options {
 importVocab=Common
}

...

parser.g:

options {
 importVocab=Common
}

tokens {
 AND <AST=AndOperator>;
}

...


> 
> Monty
> 
> -----Original Message-----
> From: beeh1973 <hastur4711 at b...> [mailto:hastur4711 at b...]
> Sent: Monday, January 20, 2003 7:23 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Re: ambiguous grammar
> 
> 
> --- In antlr-interest at yahoogroups.com, Anakreon Mejdi <amejdi at e...> 
> wrote:
> >   component:
> >     DOLLAR^ FLOAT
> >     ;
> > This should work.
> > There is no DOT because in the NUMBER rule if an DIGIT is matched 
> the 
> > type is made FLOAT and the DOT is consumed.
> > For the same reason there is no NUMBER Token.
> >
> hi,
> 
> it works but does not produce the result i need.
> this would create the tree
> ($ .1)
> instead i need the tree
> ($ . 1)
> 
> in fact i do not need DOT to be part of the tree. just to display 
the
> difference. ($ 1) would suffice.
> 
> .1 is just a float literal
> $.1 is a positional notation: "the first element in $"
> 
> another reply gave me the hint to check the provided Java and C 
> Grammars.
> i will check this way.
> 
> thanks a lot,
>   alphonse
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list