You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code doesn't compile, tsc --version "Version 5.6.2". MyVisitor.ts:4:47 - error TS1005: '=>' expected. tree is undefined. *Context are all undefined. .text is used instead of .getText(). Also, visitStart() has to be define otherwise none of the other overrides are called, and "null" is returned.
The code should look something like this.
import { StartContext, ExpressionContext, MultiplyContext, DivideContext, AddContext, SubtractContext, NumberContext } from "./ExpressionParser.js";
import { ExpressionVisitor } from "./ExpressionVisitor.js";
export class MyVisitor extends ExpressionVisitor<number> {
public visitStart = (ctx: StartContext) => {
return this.visit(ctx.getChild(0));
}
public visitAdd = (ctx: AddContext) => {
return this.visit(ctx.expression(0)) + this.visit(ctx.expression(1));
}
public visitMultiply = (ctx: MultiplyContext) => {
return this.visit(ctx.expression(0)) * this.visit(ctx.expression(1));
}
public visitNumber = (ctx: NumberContext) => {
return Number.parseInt(ctx.NUMBER().getText());
}
}
The text was updated successfully, but these errors were encountered:
From the readme.md:
antlr4ng/ReadMe.md
Lines 80 to 99 in e1984c4
This code doesn't compile, tsc --version "Version 5.6.2".
MyVisitor.ts:4:47 - error TS1005: '=>' expected
.tree
is undefined.*Context
are all undefined..text
is used instead of.getText()
. Also,visitStart()
has to be define otherwise none of the other overrides are called, and "null" is returned.The code should look something like this.
The text was updated successfully, but these errors were encountered: