[antlr-interest] Code generation bug in tree parser (ANTLRV3b6)
Terence Parr
parrt at cs.usfca.edu
Wed Mar 14 10:33:19 PDT 2007
Hi. DOWN is defined in TreeParser:
public class TreeParser extends BaseRecognizer {
public static final int DOWN = Token.DOWN;
public static final int UP = Token.UP;
...
Probably you used ^(A B) in a parser.
Ter
On Feb 28, 2007, at 3:04 PM, Dr. Hartmut Kocher wrote:
> In my tree parser I get several instances of the form:
>
>
>
> case 45:
>
> int LA7_4 = input.LA(2);
>
> if ( (LA7_4 == DOWN) )
>
> {
>
>
>
> This doesn’t compile as there is no token constant “DOWN” defined
> in the parser.
>
>
>
> There are two possible ways to fix this: Either generate public
> const int DOWN = 2; into the file, or generate “Token.DOWN”
> wherever it is used.
>
>
>
> As I don’t know which is the intended behavior, I hacked
> Target.java for now to return “Token.DOWN” instead of “DOWN”.
>
>
>
> /** Target must be able to override the labels used for token types */
>
> public String getTokenTypeAsTargetLabel(CodeGenerator
> generator, int ttype) {
>
> String name =
> generator.grammar.getTokenDisplayName(ttype);
>
> // If name is a literal, return the token
> type instead
>
> if ( name.charAt(0)=='\'' ) {
>
> return String.valueOf(ttype);
>
> }
>
> // HACK!!!
>
> if(name.equals("DOWN")) {
>
> name = "Token.DOWN";
>
> }
>
> return name;
>
> }
>
>
>
> Same might happen with „UP“ as this is also excluded from the token
> definition list…
>
>
>
> Please put his in the bug list.
>
>
>
> Kind regards
>
>
>
> Dr. Hartmut Kocher
>
> Cortex Brainware Consulting & Training GmbH
>
> Kirchplatz 5
> D-82049 Pullach
>
> Tel: +49 (89) 744 850 0
> Fax: +49 (89) 744 850 11
>
> http://www.cortex-brainware.de
>
> E-Mail: hwk at cortex-brainware.de
>
> Handelsregister:
> Registergericht: Amtsgericht München
> HRB-Nr. 120614
>
> Vertretungsberechtigte Geschäftsführer:
> Dipl.-Inform. Dorothea Burger, Dr.-Ing. Hartmut Kocher, Dr.-Ing.
> Martin Lang, Dr. rer. nat. Rolf Peter Wehrum
>
>
>
>
More information about the antlr-interest
mailing list