-
Notifications
You must be signed in to change notification settings - Fork 0
Antlr introduce
benhaben edited this page Jun 9, 2017
·
1 revision
grammar Strings;
lispy : expr*;
expr : NUMBER | SYMBOL | sexpr | qexpr | string ;
sexpr : LP expr* RP;
qexpr : LB expr* RB ;
NUMBER : '-'?[0-9]+ ;
COMMENT: ';' ~[\r\n]* -> skip ;
string : STRING ;
STRING : '"' ( ~'"' | '\\' '"' )* '"' ;
SYMBOL : ([0-9]|'a'..'z'|'A'.. 'Z'|'_'|ADD|SUB|MUL|DIV|'$'|'!'|'&'|'\\'|'>'|'<'|'>='|'<='|'=='|'!='|'=' )+;
LP : '(';
RP : ')';
LB : '{';
RB : '}';
MUL : '*' ; // assigns token name to '*' used above in grammar
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
WS : [ \t\r\n]+ -> skip ;
-
x ⇒ Match token, rule reference, or subrule x.
-
x y … z ⇒ Match a sequence of rule elements.
-
(… | … | …) ⇒ Subrule with multiple alternatives.
-
x? ⇒ Match x or skip it.
-
x* ⇒ Match x zero or more times.
-
x+ ⇒ Match x one or more times
-
r : … ; ⇒ Define rule r.
-
r : … | … | … ; ⇒ Define rule r with multiple alternatives.
*capitals means token
*lower-case means rule