antlr4 grammar errors when parsing

24 views
Skip to first unread message

Thiago Andrade

unread,
Oct 6, 2014, 12:02:48 PM10/6/14
to antlr-di...@googlegroups.com
http://stackoverflow.com/questions/26220104/antlr4-grammar-errors-when-parsing

I have the following grammar:

    grammar Token;

    prog: (expr NL?)+ EOF;

    expr: '[' type ']';

    type : typeid ':' value;

    typeid : 'TXT' | 'ENC' | 'USR';

    value: Text | INT;

    INT :   '0' | [1-9] [0-9]*;

    //WS : [ \t]+;
    WS  :   [ \t\n\r]+ -> skip ;
    NL:  '\r'? '\n';
    Text : ~[\]\[\n\r"]+ ;

and the text I need to parse is something like this below 

    [TXT:look at me!]
    [USR:19700]
    [TXT:, can I go there?]
    [ENC:124124]
    [TXT:this is needed for you to go...]

I need to split this text but I getting some errors when I run `grun.bat Token prog -gui -trace -diagnostics` 

enter   prog, LT(1)=[
enter   expr, LT(1)=[
consume [@0,0:0='[',<3>,1:0] rule expr
enter   type, LT(1)=TXT:look at me!
enter   typeid, LT(1)=TXT:look at me!
line 1:1 mismatched input 'TXT:look at me!' expecting {'TXT', 'ENC', 'USR'}
... much more ...



what is wrong with my grammar? please, help me!


Reply all
Reply to author
Forward
0 new messages