Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple grammar error #77

Open
jtejido opened this issue Sep 17, 2023 · 1 comment
Open

Simple grammar error #77

jtejido opened this issue Sep 17, 2023 · 1 comment

Comments

@jtejido
Copy link

jtejido commented Sep 17, 2023

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
Copy link
Collaborator

kaby76 commented Sep 17, 2023

  • Make sure you select the "Lexer" tab and clear out the contents. You did not, which is why you get the error message "<missing 'fsm'>".
  • Make sure you have a whitespace rule that shunts spaces to the off-channel. WS: [ \t\n] -> channel(HIDDEN);
  • Make sure you use the +-operator in the definition of ID. ID: Letter+ ; not ID: Letter ;
  • Make sure you use an EOF-terminated start rule in order to avoid the parser not reading all the input on failure. fsm: 'fsm' ID EOF;. If you do all three changes I listed before this fourth suggestion, and give fsm Test foobar as input, the parse will succeed, but not fail on foobar.

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'
    ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants