antlr / antlr4-lab

A client/server for trying out and learning about ANTLR
MIT License
39 stars 11 forks source link

Simple grammar error #77

Open jtejido opened 1 year ago

jtejido commented 1 year ago

Hi,

Just wanted to test something simple at first. I'd like to test a program that only start with the word 'fsm' and it out an error saying "<missing 'fsm'>"

the grammar to be tested:

grammar Fsm;

fsm
    :   'fsm' ID
    ;

ID
    :   Letter
    ;

fragment
Letter
    :  '\u0024'           /* $   */ |
       '\u0041'..'\u005a' /* A-Z */ |
       '\u005f'           /* _   */ |
       '\u0061'..'\u007a' /* a-z */ |
       '\u00c0'..'\u00d6' |
       '\u00d8'..'\u00f6' |
       '\u00f8'..'\u00ff' |
       '\u0100'..'\u1fff' |
       '\u3040'..'\u318f' |
       '\u3300'..'\u337f' |
       '\u3400'..'\u3d2d' |
       '\u4e00'..'\u9fff' |
       '\uf900'..'\ufaff'
    ;

The simple test is: fsm Test

kaby76 commented 1 year ago

Your grammar should looke like this:

grammar Fsm;
fsm :   'fsm' ID ;
ID:   Letter+  ;
WS: [ \t\n] -> channel(HIDDEN);
fragment
Letter
    :  '\u0024'           /* $   */ |
       '\u0041'..'\u005a' /* A-Z */ |
       '\u005f'           /* _   */ |
       '\u0061'..'\u007a' /* a-z */ |
       '\u00c0'..'\u00d6' |
       '\u00d8'..'\u00f6' |
       '\u00f8'..'\u00ff' |
       '\u0100'..'\u1fff' |
       '\u3040'..'\u318f' |
       '\u3300'..'\u337f' |
       '\u3400'..'\u3d2d' |
       '\u4e00'..'\u9fff' |
       '\uf900'..'\ufaff'
    ;