-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAlgorithmEngineHelper.js
More file actions
24 lines (22 loc) · 945 Bytes
/
AlgorithmEngineHelper.js
File metadata and controls
24 lines (22 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { AntlrCharStream } from './AntlrCharStream.js';
import mathjsLexer from './math/mathjsLexer.js';
import CommonTokenStream from './antlr4/CommonTokenStream.js';
import mathjsParser from './math/mathjsParser.js';
import mathjsVisitor from './math/mathjsVisitor.js';
export class AlgorithmEngineHelper {
static ParseFormula(exp,errorListener) {
if (!exp || exp.trim() === '') { return null; }
if (!errorListener ) { return null; }
let stream =new AntlrCharStream(exp);
let lexer = new mathjsLexer(stream );
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
let tokens = new CommonTokenStream(lexer);
let parser = new mathjsParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
let context= parser.prog();
let visitor = new mathjsVisitor();
return visitor.visit(context);
}
}