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 char by hexadecimal ascii
19 ch_hex = '#' ('x'|'X') ('0'..'9'|'a'..'z'|'A'..'Z')+ ;
21 // A single-line comment
22 comment = '//' ch* '\n'?;
26 not_star_not_slash = not_star - '/';
28 ccomment = '/*' not_star* ('*' (not_star_not_slash not_star*)?)* '*/';
30 unknown_keyword = 'A'..'Z'('A'..'Z'|'a'..'z'|'0'..'9'|'_')*;
33 blank = '\r' | '\n' | '\t' | ' ' | comment | ccomment;
38 Rejected unknown_keyword;
40 grammar = 'Grammar' id ';' lexer_part? parser_part? tree_part?;
42 lexer_part = 'Lexer' expr*;
46 // No priority (yet) so just decompose
52 {minus:} re1 '-' re2 |
53 {except:} re1 'Except' re2 |
54 {and:} re1 'And' re2 |
65 {shortest:} 'Shortest' '(' re ')' |
66 {longest:} 'Longest' '(' re ')' |
67 {prefixes:} 'Prefixes' '(' re ')' |
70 {class:} text '.' '.' text |
71 {openclass:} text '.' '.' '.' |
81 parser_part = 'Parser' ign? rej? prod*;
83 ign = 'Ignored' elem_list ';' ;
85 rej = 'Rejected' elem_list ';' ;
87 prod = id ptrans? '=' alts priority* ';';
89 ptrans = '{' '->' id '}';
90 atrans = '{' '->' '}';
93 {more:} alts '|' alt |
96 alt = altid? nelem* atrans?;
98 altid = '{' id ':' '}' | '{' id '}';
100 nelem = elem | elemid elem;
102 elemid = '[' id ':' ']' | '[' id ']' ':';
105 {more:} elem_list ',' elem |
117 {left:} 'Left' alts |
118 {right:} 'Right' alts |
119 {unary:} 'Unary' alts ;
121 tree_part = 'Tree' prod*;