Add project files
This commit is contained in:
commit
ba5971a788
37 files changed
+11180
No files matched your search
@@ -0,0 +1,18 @@
|
||||
// Lexer and parser in separate files.
|
||||
// antlrlab examples/split/CalcLexer.g4 examples/split/CalcParser.g4 examples/split/input.txt
|
||||
lexer grammar CalcLexer;
|
||||
|
||||
PLUS : '+' ;
|
||||
MINUS : '-' ;
|
||||
STAR : '*' ;
|
||||
SLASH : '/' ;
|
||||
LPAREN : '(' ;
|
||||
RPAREN : ')' ;
|
||||
ASSIGN : '=' ;
|
||||
SEMI : ';' ;
|
||||
|
||||
NUMBER : [0-9]+ ('.' [0-9]+)? ;
|
||||
IDENT : [a-zA-Z_] [a-zA-Z_0-9]* ;
|
||||
|
||||
LINE_COMMENT : '//' ~[\r\n]* -> channel(HIDDEN) ;
|
||||
WS : [ \t\r\n]+ -> skip ;
|
||||
@@ -0,0 +1,15 @@
|
||||
parser grammar CalcParser;
|
||||
|
||||
options { tokenVocab = CalcLexer; }
|
||||
|
||||
program : statement* EOF ;
|
||||
|
||||
statement : IDENT ASSIGN expression SEMI ;
|
||||
|
||||
expression
|
||||
: expression (STAR | SLASH) expression
|
||||
| expression (PLUS | MINUS) expression
|
||||
| LPAREN expression RPAREN
|
||||
| NUMBER
|
||||
| IDENT
|
||||
;
|
||||
@@ -0,0 +1,3 @@
|
||||
// two statements
|
||||
width = 4;
|
||||
area = width * (width + 2.5) - 1;
|
||||
Reference in new issue
Block a user