[antlr-interest] A simple question in my antlr code. Is it a antlr code bug or some thing wrong with my code

Gnanasegaran Vinayagamoorthy Vinayagamoorthy.Gnanasegaran at statkraft.com
Thu Jun 26 05:58:26 PDT 2008


I am a new antlr user. I have made a simple code to decode a string. Here comes the code.

*********************************************************************************************************
grammar test;

options {
            language = Java;
}

@parser::members {
            String month = "NONE";
}

generateName
            :           columnkey SEPARATOR namekey SEPARATOR dateKey SEPARATOR;

columnkey :  (   '5'         {System.out.println("digit1 : " + "5");}     |
                                    '6'         {}          |
                        '7'         {}          |
                        '8'         {}          |
                        '9'         {}          |
                        '10'       {}          |
                        '12'       {}
            );

namekey : KEY digit_key  ('M' {System.out.println("Char : " + "M");} | 'Q' {} | 'Y'{});

digit_key :        ( '2'{System.out.println("digit2 : " + "2");} | '4'{});

dateKey : monthKey yearKey({System.out.println("Finished"); });

monthKey
            : MONTH_LABEL_EN ({month = $MONTH_LABEL_EN.text; System.out.println("month : " +  month); } );

yearKey            : YEAR_TWO_DIGIT(
            {System.out.println("year : " +  $YEAR_TWO_DIGIT.text);}
);

DIG:'0'..'9';
MONTH_LABEL_EN : ('JAN' | 'FEB' | 'MAR' | 'APR' | 'MAY' | 'JUN' | 'JUL' | 'AUG' | 'SEP' | 'OCT' | 'NOV' | 'DEC');
SEPARATOR : ';';
KEY : ('FT') ;
YEAR_TWO_DIGIT : DIG+;


When I test the method "yearKey" with a value "10;" it gives me "mismatched input '10'" error. Number '10' is used in method "columnkey". Is it any thing wrong in my code or a bug in antlr. Can anybody help me in this.

Regards,
Seagr

Gnanasegaran Vinayagamoorthy
System developer, GTSS

_ _ DIRECT +47 24 06 70 16
_ _ MOBILE +47 95 85 62 56
_ _ SWITCHBOARD +47 24 06 70 00

Statkraft Energi AS
Lilleakerveien 6, P.O. Box 200 Lilleaker, 0216 Oslo, Norway
www.statkraft.com<http://www.statkraft.com/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080626/0f0e466e/attachment-0001.html 


More information about the antlr-interest mailing list