1 // The grammar of nitcc (subset of sablecc4)
6 // Identifier, used for production, expressions, alternatives, etc.
7 id = ('a'..'z')('a'..'z'|'0'..'9'|'_')*;
9 // A printable character (inside strings)
13 str = '\'' (ch-'\\'-'\''|'\\'ch)* '\'';
15 // A char by decimal ascii
16 ch_dec = '#' ('0'..'9')+ ;
18 // A single-line comment
19 comment = '//' ch* '\n'?;
23 not_star_not_slash = not_star - '/';
25 ccomment = '/*' not_star* ('*' (not_star_not_slash not_star*)?)* '*/';
27 unknown_keyword = 'A..Z'('A'..'Z'|'a'..'z'|'0'..'9'|'_')*;
30 blank = '\n' | '\t' | ' ' | comment | ccomment;
36 grammar = 'Grammar' id ';' lexer_part? parser_part? reject?;
38 reject = 'XXX' unknown_keyword ';';
40 lexer_part = 'Lexer' expr*;
44 // No priority (yet) so just decompose
50 {minus:} re1 '-' re2 |
64 {class:} str '.' '.' str |
69 parser_part = 'Parser' ign? prod*;
71 ign = 'Ignored' id ';' ;
73 prod = id ptrans? '=' alts ';';
75 ptrans = '{' '->' id '}';
76 atrans = '{' '->' id '}';
79 {more:} alts '|' alt |
82 alt = altid? nelem* atrans?;
84 altid = '{' id ':' '}' | '{' id '}';
86 nelem = elem | elemid elem;
88 elemid = '[' id ':' ']' | '[' id ']' ':';