Comments (1)
the 'compilationUnit' isnt related to antlr itself, its vary based on your grammar
import { CharStreams, CommonTokenStream, ParserRuleContext } from 'antlr4ts';
import { ParseTreeWalker } from 'antlr4ts/tree/ParseTreeWalker';
import { ExprContext, calcParser } from './generated/calcParser';
import { calcListener } from './generated/calcListener';
import { calcLexer } from './generated/calcLexer';
import * as fs from "fs";
// Create the lexer and parser
const code = fs.readFileSync('EXAMPLE.txt', 'utf8');
const inputStream = CharStreams.fromString(code);
const lexer = new calcLexer(inputStream);
const tokenStream = new CommonTokenStream(lexer);
const parser = new calcParser(tokenStream);
const tree = parser.program();
in my case my entrypoint parser is "program" method, the grammar used is the AntlrLab Sample
grammar calc;
program
: stat EOF
| def EOF
;
stat: ID '=' expr ';'
| expr ';'
;
def : ID '(' ID (',' ID)* ')' '{' stat* '}' ;
expr: ID
| INT
| func
| 'not' expr
| expr 'and' expr
| expr 'or' expr
;
func : ID '(' expr (',' expr)* ')' ;
AND : 'and' ;
OR : 'or' ;
NOT : 'not' ;
EQ : '=' ;
COMMA : ',' ;
SEMI : ';' ;
LPAREN : '(' ;
RPAREN : ')' ;
LCURLY : '{' ;
RCURLY : '}' ;
INT : [0-9]+ ;
ID: [a-zA-Z_][a-zA-Z_0-9]* ;
WS: [ \t\n\r\f]+ -> skip ;
from antlr4ts.
Related Issues (20)
- Example in the README uses a deprecated feature
- Generated Parser refers to C++ Classes (std::set<std::string>), unable to compile TS HOT 1
- Cannot find module ‘node_modules\antlr4ts\atn\ATN‘ HOT 1
- Please add support for Typescript 4.4.x HOT 11
- Update serialization version support
- Grammar r file `exception` rule is conflict with ParserRuleContext.exception
- antlr4ts cli's -o option is wrong affected by the grammar file option
- Incorporate the >4.10 release
- child process exited with code 3221226505
- return type declaration does not support function types
- Project continues to be updated? HOT 4
- Argument of type 'SqlParser' is not assignable to parameter of type 'Parser'.
- Uncaught TypeError: Cannot read properties of undefined (reading 'custom') at node_modules/antlr4ts/misc/BitSet.js (BitSet.ts:834:32) HOT 7
- Could not generate files with esm type
- "cannot find tokens file" (documentation missing) HOT 1
- Webpack 5 - AntlrTS in Browser HOT 3
- Suggestion for transformation of parse tree
- use `override` instead of `// @Override` HOT 1
- Obsolete Package, use antlr4 directly to generate typescript targets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from antlr4ts.