Add project files
build / linux-clang (push) Canceled after 0s
build / linux-gcc (push) Canceled after 0s
build / macos-clang (push) Canceled after 0s
build / windows-mingw (push) Canceled after 0s
build / windows-msvc (push) Canceled after 0s

This commit is contained in:
alejo committed 2026-10-07 00:25:24 -03:00
commit ba5971a788
37 files changed
+11180

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
// A small expression grammar in one combined file.
// antlrlab examples/combined/Expr.g4 examples/combined/input.txt
grammar Expr;
prog : expr EOF ;
expr
: expr op=(MUL | DIV) expr # MulDiv
| expr op=(ADD | SUB) expr # AddSub
| INT # Int
| ID # Id
| '(' expr ')' # Parens
;
MUL : '*' ;
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
INT : [0-9]+ ;
ID : [a-zA-Z_] [a-zA-Z_0-9]* ;
WS : [ \t\r\n]+ -> skip ;
+1
View File
@@ -0,0 +1 @@
1 + 2 * (width - 3)
+1
View File
@@ -0,0 +1 @@
1 + * 2 (width
+31
View File
@@ -0,0 +1,31 @@
// JSON, straight from the ANTLR book. Try it on a .json file:
// antlrlab examples/json/JSON.g4 examples/json/example.json
grammar JSON;
json : value EOF ;
obj : '{' pair (',' pair)* '}'
| '{' '}'
;
pair : STRING ':' value ;
arr : '[' value (',' value)* ']'
| '[' ']'
;
value : STRING | NUMBER | obj | arr | 'true' | 'false' | 'null' ;
STRING : '"' (ESC | SAFECODEPOINT)* '"' ;
fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
fragment UNICODE : 'u' HEX HEX HEX HEX ;
fragment HEX : [0-9a-fA-F] ;
fragment SAFECODEPOINT : ~["\\\u0000-\u001F] ;
NUMBER : '-'? INT ('.' [0-9]+)? EXP? ;
fragment INT : '0' | [1-9] [0-9]* ;
fragment EXP : [Ee] [+\-]? INT ;
WS : [ \t\n\r]+ -> skip ;
+8
View File
@@ -0,0 +1,8 @@
{
"name": "antlrlab",
"tags": ["parser", "antlr", "diagram"],
"version": 1.0,
"stable": true,
"owner": null,
"nested": { "depth": 2, "items": [1, 2, 3] }
}
+18
View File
@@ -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 ;
+15
View File
@@ -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
;
+3
View File
@@ -0,0 +1,3 @@
// two statements
width = 4;
area = width * (width + 2.5) - 1;