diff --git a/.github/workflows/github-actions.yaml b/.github/workflows/github-actions.yaml index b62ed04..671bf42 100644 --- a/.github/workflows/github-actions.yaml +++ b/.github/workflows/github-actions.yaml @@ -4,9 +4,11 @@ jobs: test: runs-on: ubuntu-latest steps: - - run: echo "Testing Abacus" + - run: echo "Running tests" - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.18.0' - name: Run tests run: go test -v -covermode=atomic -race ./... build-and-release: @@ -16,12 +18,14 @@ jobs: steps: - run: echo "Building Abacus" - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.18.0' - name: Build step run: | - GOOS=windows GOARCH=amd64 go build -o abacus-windows-amd64.exe - GOOS=linux GOARCH=amd64 go build -o abacus-linux-amd64 - GOOS=darwin GOARCH=amd64 go build -o abacus-macos-amd64 + GOOS=windows GOARCH=amd64 go build -o abacus-windows-amd64.exe ./cmd/abacus-cli + GOOS=linux GOARCH=amd64 go build -o abacus-linux-amd64 ./cmd/abacus-cli + GOOS=darwin GOARCH=amd64 go build -o abacus-macos-amd64 ./cmd/abacus-cli - name: Set version tag run: echo "VERSION_TAG=$(./abacus-linux-amd64 --version)" >> $GITHUB_ENV - uses: ncipollo/release-action@v1 diff --git a/.gitignore b/.gitignore index 8c036ea..bb58763 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,6 @@ # Dependency directories (remove the comment below to include it) # vendor/ .idea/ -abacus +./abacus definitions.a .DS_Store diff --git a/Abacus.g4 b/Abacus.g4 index 8a46119..e3cb69a 100644 --- a/Abacus.g4 +++ b/Abacus.g4 @@ -108,31 +108,36 @@ sign | '-' # MinusSign; +//function +// : 'sqrt' LPAREN expression RPAREN # SqrtFunction +// | 'cbrt' LPAREN expression RPAREN # CbrtFunction +// | 'ln' LPAREN expression RPAREN # LnFunction +// | 'log' LPAREN expression RPAREN # LogDefFunction +// | 'log2' LPAREN expression RPAREN # Log2Function +// | 'log10' LPAREN expression RPAREN # Log10Function +// | 'floor' LPAREN expression RPAREN # FloorFunction +// | 'ceil' LPAREN expression RPAREN # CeilFunction +// | 'exp' LPAREN expression RPAREN # ExpFunction +// | 'sin' LPAREN expression RPAREN # SinFunction +// | 'cos' LPAREN expression RPAREN # CosFunction +// | 'tan' LPAREN expression RPAREN # TanFunction +// | 'round' LPAREN expression RPAREN # RoundDefFunction +// | 'sign' LPAREN expression RPAREN # SignFunction +// | 'abs' LPAREN expression RPAREN # AbsFunction +// | 'round' LPAREN expression ',' expression RPAREN # Round2Function +// | 'log' LPAREN expression ',' expression RPAREN # LogFunction +// | 'min' LPAREN tuple RPAREN # MinFunction +// | 'max' LPAREN tuple RPAREN # MaxFunction +// | 'avg' LPAREN tuple RPAREN # AvgFunction +// | 'until' LPAREN tuple ',' expression RPAREN # UntilFunction +// | 'from' LPAREN tuple RPAREN # FromFunction +// | 'reverse' LPAREN tuple RPAREN # ReverseFunction +// | 'nth' LPAREN tuple ',' expression RPAREN # NthFunction +// ; + + function - : 'sqrt' LPAREN expression RPAREN # SqrtFunction - | 'cbrt' LPAREN expression RPAREN # CbrtFunction - | 'ln' LPAREN expression RPAREN # LnFunction - | 'log' LPAREN expression RPAREN # LogDefFunction - | 'log2' LPAREN expression RPAREN # Log2Function - | 'log10' LPAREN expression RPAREN # Log10Function - | 'floor' LPAREN expression RPAREN # FloorFunction - | 'ceil' LPAREN expression RPAREN # CeilFunction - | 'exp' LPAREN expression RPAREN # ExpFunction - | 'sin' LPAREN expression RPAREN # SinFunction - | 'cos' LPAREN expression RPAREN # CosFunction - | 'tan' LPAREN expression RPAREN # TanFunction - | 'round' LPAREN expression RPAREN # RoundDefFunction - | 'sign' LPAREN expression RPAREN # SignFunction - | 'abs' LPAREN expression RPAREN # AbsFunction - | 'round' LPAREN expression ',' expression RPAREN # Round2Function - | 'log' LPAREN expression ',' expression RPAREN # LogFunction - | 'min' LPAREN tuple RPAREN # MinFunction - | 'max' LPAREN tuple RPAREN # MaxFunction - | 'avg' LPAREN tuple RPAREN # AvgFunction - | 'until' LPAREN tuple ',' expression RPAREN # UntilFunction - | 'from' LPAREN tuple RPAREN # FromFunction - | 'reverse' LPAREN tuple RPAREN # ReverseFunction - | 'nth' LPAREN tuple ',' expression RPAREN # NthFunction + : VARIABLE LPAREN tuple RPAREN # FunctionInvocation ; @@ -151,10 +156,12 @@ fragment NUMBER : DIGITS+ (POINT DIGITS +)? ; + VARIABLE : VALID_ID_START VALID_ID_CHAR* ; + LAMBDA_VARIABLE : UPPERCASE VALID_ID_CHAR* ; diff --git a/Makefile b/Makefile index 4f25772..8b89db5 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,15 @@ -BIN = abacus +BIN=abacus all: compile run +test: + go test -v -covermode=atomic -race ./... + compile: - go build -o $(BIN) + go build -o $(BIN) ./cmd/abacus-cli/main.go + +recompile-grammar: + antlr4 -Dlanguage=Go -o parser/ Abacus.g4 -visitor run: ./$(BIN) diff --git a/abacus/abacus_visitor.go b/abacus/abacus_visitor.go new file mode 100644 index 0000000..c150d40 --- /dev/null +++ b/abacus/abacus_visitor.go @@ -0,0 +1,1159 @@ +package abacus + +import ( + "github.com/antlr/antlr4/runtime/Go/antlr/v4" + "github.com/cockroachdb/apd" + "github.com/viktordanov/abacus/parser" + _ "math" + "strconv" +) + +func initConstants(store *ConstantsStore, precision uint32) { + decimalCtx := apd.BaseContext.WithPrecision(precision) + + pi, _, _ := decimalCtx.NewFromString("3." + + "14159265358979323846264338327950288419716939937510" + + "58209749445923078164062862089986280348253421170679" + + "82148086513282306647093844609550582231725359408128" + + "48111745028410270193852110555964462294895493038196" + + "44288109756659334461284756482337867831652712019091" + + "45648566923460348610454326648213393607260249141273" + + "72458700660631558817488152092096282925409171536444") + + e, _, _ := decimalCtx.NewFromString("2." + + "71828182845904523536028747135266249775724709369995" + + "95749669676277240766303535475945713821785251664274" + + "27466391932003059921817413596629043572900334295260" + + "59563073813232862794349076323382988075319525101901" + + "157383418793070215408914993488416750924147614606680" + + "82264800168477411853742345442437107539077744992069" + + "55170276183860626133138458300075204493382656029760") + + phi, _, _ := decimalCtx.NewFromString("1." + + "61803398874989484820458683436563811772030917980576" + + "28621354486227052604628189024497072072041893911374" + + "84754088075386891752126633862223536931793180060766" + + "72635443338908659593958290563832266131992829026788" + + "06752087668925017116962070322210432162695486262963" + + "13614438149758701220340805887954454749246185695364" + + "86444924104432077134494704956584678850987433944221") + + store.SetConstant(PI, Number{pi}) + store.SetConstant(PHI, Number{phi}) + store.SetConstant(E, Number{e}) + + calculateLog(store, decimalCtx, Number{apd.New(2, 0)}) + calculateLog(store, decimalCtx, Number{apd.New(10, 0)}) +} + +func NewNumber(f float64) Number { + res := apd.New(0, 0) + res.SetFloat64(f) + return Number{res} +} + +func calculateLog(store *ConstantsStore, ctx *apd.Context, n Number) Number { + out := NewNumber(0) + + var r Number + var ok bool + if r, ok = store.Cached(n.String()); !ok { + ctx.Ln(out.Decimal, n.Decimal) + newValue := NewNumber(0) + newValue.Decimal.Set(out.Decimal) + store.Cache(n.String(), newValue) + } else { + out.Set(r.Decimal) + } + return out +} + +type Visitor struct { + antlr.ParseTreeVisitor + variables map[string]Number + lambdaDeclarations map[string]*LambdaDeclaration + lambdaCallStack *LambdaCallStack + decimalCtx *apd.Context + strict bool + ConstantsStore *ConstantsStore +} + +func (v *Visitor) VariableNames() []string { + var names []string + for k := range v.variables { + names = append(names, k) + } + return names +} + +func (v *Visitor) LambdaNames() []string { + var names []string + for k := range v.lambdaDeclarations { + names = append(names, k) + } + return names +} + +func (v *Visitor) SetVariable(name string, value Number) { + v.variables[name] = value +} + +func NewAbacusVisitor(precision uint32, strict bool) (*Visitor, error) { + constantsStore, err := NewConstantsStore() + if err != nil { + return nil, err + } + + initConstants(constantsStore, precision) + return &Visitor{ + ParseTreeVisitor: &parser.BaseAbacusVisitor{}, + variables: make(map[string]Number), + lambdaDeclarations: make(map[string]*LambdaDeclaration), + lambdaCallStack: &LambdaCallStack{root: nil, invokes: map[string]uint{}, trace: []*CalledLambda{}, recursion: map[string]*RecursionParameters{}, memoized: map[string]*Result{}}, + decimalCtx: apd.BaseContext.WithPrecision(precision), + strict: strict, + + ConstantsStore: constantsStore, + }, err +} + +func (v *Visitor) Visit(tree antlr.ParseTree) interface{} { + switch val := tree.(type) { + case *parser.RootContext: + v.lambdaCallStack.root = nil + v.lambdaCallStack.trace = []*CalledLambda{} + v.lambdaCallStack.invokes = map[string]uint{} + v.lambdaCallStack.recursion = map[string]*RecursionParameters{} + v.lambdaCallStack.memoized = map[string]*Result{} + return val.Accept(v) + } + return nil +} + +func (v *Visitor) VisitRoot(c *parser.RootContext) interface{} { + if c.Tuple() != nil { + return c.Tuple().Accept(v) + } + if c.Declaration() != nil { + return c.Declaration().Accept(v) + } + if c.BoolExpression() != nil { + return c.BoolExpression().Accept(v) + } + if c.LAMBDA_VARIABLE() != nil { + if declaration, ok := v.lambdaDeclarations[c.LAMBDA_VARIABLE().GetText()]; ok { + return NewResult(LambdaAssignment(declaration.ctx.GetText())) + + } + return NewResult(nil).WithError("undefined lambda " + c.LAMBDA_VARIABLE().GetText()) + + } + return NewResult(nil).WithError("syntax error") +} + +func (v *Visitor) visitTupleTail(c parser.ITupleContext, resultTuple *Tuple) { + ctx, ok := c.(*parser.TupleContext) + if !ok || ctx == nil { + return + } + val := ctx.Expression().Accept(v).(*Result) + + switch v := val.Value.(type) { + case Number: + *resultTuple = append(*resultTuple, v) + case Tuple: + *resultTuple = append(*resultTuple, v...) + } + + v.visitTupleTail(ctx.Tuple(), resultTuple) +} + +func (v *Visitor) VisitTuple(c *parser.TupleContext) interface{} { + if c.Tuple() == nil { + return c.Expression().Accept(v) + } + + evaledTuple := Tuple{} + val := c.Expression().Accept(v).(*Result) + + switch v := val.Value.(type) { + case Number: + evaledTuple = append(evaledTuple, v) + case Tuple: + evaledTuple = append(evaledTuple, v...) + } + v.visitTupleTail(c.Tuple(), &evaledTuple) + + return NewResult(evaledTuple) +} + +func (v *Visitor) visitMixedTupleTail(c parser.IMixedTupleContext, resultMixedTuple *MixedTuple) { + ctx, ok := c.(*parser.MixedTupleContext) + if !ok || ctx == nil { + return + } + val := NewResult(nil) + if ctx.Expression() != nil { + val = ctx.Expression().Accept(v).(*Result) + } else if ctx.LAMBDA_VARIABLE() != nil { + val.Value = String(ctx.LAMBDA_VARIABLE().GetText()) + } + + switch v := val.Value.(type) { + case Number: + *resultMixedTuple = append(*resultMixedTuple, v) + case String: + *resultMixedTuple = append(*resultMixedTuple, v) + case MixedTuple: + *resultMixedTuple = append(*resultMixedTuple, v...) + } + + v.visitMixedTupleTail(ctx.MixedTuple(), resultMixedTuple) +} + +func (v *Visitor) VisitMixedTuple(c *parser.MixedTupleContext) interface{} { + if c.MixedTuple() == nil { + val := NewResult(nil) + if c.Expression() != nil { + val = c.Expression().Accept(v).(*Result) + } else if c.LAMBDA_VARIABLE() != nil { + val.Value = String(c.LAMBDA_VARIABLE().GetText()) + } + return val + } + + evaledMixedTuple := MixedTuple{} + val := NewResult(nil) + if c.Expression() != nil { + val = c.Expression().Accept(v).(*Result) + } else if c.LAMBDA_VARIABLE() != nil { + val.Value = String(c.LAMBDA_VARIABLE().GetText()) + } + + switch v := val.Value.(type) { + case Number: + evaledMixedTuple = append(evaledMixedTuple, v) + case String: + evaledMixedTuple = append(evaledMixedTuple, v) + case MixedTuple: + evaledMixedTuple = append(evaledMixedTuple, v...) + } + v.visitMixedTupleTail(c.MixedTuple(), &evaledMixedTuple) + + return NewResult(evaledMixedTuple) +} + +func (v *Visitor) visitVariableTupleTail(c parser.IVariablesTupleContext, resultTuple *VariablesTuple) { + ctx, ok := c.(*parser.VariablesTupleContext) + if !ok || ctx == nil { + return + } + val := ctx.VARIABLE().GetText() + *resultTuple = append(*resultTuple, String(val)) + v.visitVariableTupleTail(ctx.VariablesTuple(), resultTuple) +} + +func (v *Visitor) VisitVariablesTuple(c *parser.VariablesTupleContext) interface{} { + if c.VariablesTuple() == nil { + return NewResult(String(c.VARIABLE().GetText())) + } + + evaledTuple := VariablesTuple{} + + val := c.VARIABLE().GetText() + evaledTuple = append(evaledTuple, String(val)) + v.visitVariableTupleTail(c.VariablesTuple(), &evaledTuple) + + foundVars := make(map[string]bool) + for _, variable := range evaledTuple { + if _, ok := foundVars[variable.String()]; !ok { + foundVars[variable.String()] = true + } else { + return NewResult(evaledTuple).WithError("duplicate variable name \"" + variable.String() + "\"") + } + } + + return NewResult(evaledTuple) +} + +func (v *Visitor) convertVariablesTupleResult(result *Result) { + switch val := result.Value.(type) { + case String: + result.Value = VariablesTuple{val} + } +} + +func (v *Visitor) convertLambdaArgumentsResult(result *Result) { + switch val := result.Value.(type) { + case String: + result.Value = LambdaArguments{val} + } +} + +func (v *Visitor) convertTupleResult(result *Result) { + switch val := result.Value.(type) { + case Number: + result.Value = Tuple{val} + } +} + +func (v *Visitor) convertMixedTupleResult(result *Result) { + switch val := result.Value.(type) { + case Number: + result.Value = MixedTuple{val} + case String: + result.Value = MixedTuple{val} + } +} + +func (v *Visitor) VisitLambdaArguments(c *parser.LambdaArgumentsContext) interface{} { + if c.LambdaArguments() == nil { + val := "" + if c.VARIABLE() != nil { + val = c.VARIABLE().GetText() + } else if c.LAMBDA_VARIABLE() != nil { + val = c.LAMBDA_VARIABLE().GetText() + } + return NewResult(String(val)) + } + + evaledArgs := LambdaArguments{} + + val := "" + if c.VARIABLE() != nil { + val = c.VARIABLE().GetText() + } else if c.LAMBDA_VARIABLE() != nil { + val = c.LAMBDA_VARIABLE().GetText() + } + evaledArgs = append(evaledArgs, String(val)) + v.visitLambdaArgsTail(c.LambdaArguments(), &evaledArgs) + + foundVars := make(map[string]bool) + for _, variable := range evaledArgs { + if _, ok := foundVars[variable.String()]; !ok { + foundVars[variable.String()] = true + } else { + firstChar := variable[0] + if firstChar >= 'A' && firstChar <= 'Z' { + return NewResult(evaledArgs).WithError("duplicate lambda name \"" + variable.String() + "\"") + } else { + return NewResult(evaledArgs).WithError("duplicate variable name \"" + variable.String() + "\"") + } + } + } + + return NewResult(evaledArgs) +} + +func (v *Visitor) visitLambdaArgsTail(c parser.ILambdaArgumentsContext, resultArgs *LambdaArguments) { + ctx, ok := c.(*parser.LambdaArgumentsContext) + if !ok || ctx == nil { + return + } + val := "" + if ctx.VARIABLE() != nil { + val = ctx.VARIABLE().GetText() + } else if ctx.LAMBDA_VARIABLE() != nil { + val = ctx.LAMBDA_VARIABLE().GetText() + } + *resultArgs = append(*resultArgs, String(val)) + v.visitLambdaArgsTail(ctx.LambdaArguments(), resultArgs) +} + +func (v *Visitor) VisitVariableDeclaration(c *parser.VariableDeclarationContext) interface{} { + variablesRes := c.VariablesTuple().Accept(v).(*Result) + if hasErrors(variablesRes) { + return variablesRes + } + v.convertVariablesTupleResult(variablesRes) + + valuesRes := c.Tuple().Accept(v).(*Result) + if hasErrors(variablesRes) { + return variablesRes + } + v.convertTupleResult(valuesRes) + + if variablesRes.Length() != valuesRes.Length() { + return variablesRes.WithError("wrong number of valuesRes " + strconv.FormatInt(int64(valuesRes.Length()), 10) + "; expected " + strconv.FormatInt(int64(variablesRes.Length()), 10)) + } + + variables, ok := variablesRes.Value.(VariablesTuple) + if !ok { + panic("unable to convert variables result to its raw type") + } + values, ok := valuesRes.Value.(Tuple) + if !ok { + panic("unable to convert values result to its raw type") + } + + for i, variable := range variables { + v.variables[variable.String()] = values[i] + } + return NewResult(Assignment(values)) +} + +func (v *Visitor) VisitLambdaDeclaration(c *parser.LambdaDeclarationContext) interface{} { + lambdaName := c.LAMBDA_VARIABLE().GetText() + lambda := c.Lambda() + + // Check if 1) multiple variables && duped variables + multipleVarLambda, ok := lambda.(*parser.VariablesLambdaContext) + arguments := LambdaArguments{} + argMap := map[string]bool{} + if ok { + argsRes := multipleVarLambda.LambdaArguments().Accept(v).(*Result) + if hasErrors(argsRes) { + return argsRes + } + v.convertLambdaArgumentsResult(argsRes) + + arguments, ok = argsRes.Value.(LambdaArguments) + if !ok { + panic("unable to cast argsRes to LambdaArguments") + } + for _, arg := range arguments { + argMap[string(arg)] = true + } + + } + + v.lambdaDeclarations[lambdaName] = &LambdaDeclaration{ + ctx: c, + argSet: argMap, + arguments: arguments, + } + + formattedLambda := lambdaName + " = " + lambda.GetText() + return NewResult(LambdaAssignment(formattedLambda)) +} + +func (v *Visitor) VisitEqualComparison(c *parser.EqualComparisonContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) == 0)) +} + +func (v *Visitor) VisitLessComparison(c *parser.LessComparisonContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) == -1)) +} + +func (v *Visitor) VisitGreaterComparison(c *parser.GreaterComparisonContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) == 1)) +} + +func (v *Visitor) VisitLessOrEqualComparison(c *parser.LessOrEqualComparisonContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) <= 0)) +} + +func (v *Visitor) VisitGreaterOrEqualComparison(c *parser.GreaterOrEqualComparisonContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) >= 0)) +} + +func (v *Visitor) VisitAndOrXor(c *parser.AndOrXorContext) interface{} { + left := c.BoolExpression(0).Accept(v).(*Result) + right := c.BoolExpression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Bool) + if !ok { + panic("unable to cast right to Bool") + } + rightVal, ok := right.Value.(Bool) + if !ok { + panic("unable to cast left to Bool") + } + + op := c.GetOp().GetTokenType() + result := Bool(false) + + switch op { + case parser.AbacusParserAND: + result = leftVal && rightVal + case parser.AbacusParserOR: + result = leftVal || rightVal + case parser.AbacusParserXOR: + result = leftVal != rightVal + + } + return NewResult(result) +} + +func (v *Visitor) VisitNot(c *parser.NotContext) interface{} { + valRes := c.BoolExpression().Accept(v).(*Result) + if hasErrors(valRes) { + return valRes + } + val, ok := valRes.Value.(Bool) + if !ok { + panic("unable to cast right to Bool") + } + return NewResult(!val) +} + +func (v *Visitor) VisitParenthesesBoolean(c *parser.ParenthesesBooleanContext) interface{} { + return c.BoolExpression().Accept(v) +} + +func (v *Visitor) VisitBoolAtom(c *parser.BoolAtomContext) interface{} { + val := c.GetText() + if val == "true" { + return NewResult(Bool(true)) + } + return NewResult(Bool(false)) +} + +func (v *Visitor) VisitBooleanAtom(c *parser.BooleanAtomContext) interface{} { + return c.BoolAtom().Accept(v) +} + +func (v *Visitor) VisitMulDiv(c *parser.MulDivContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + res := NewNumber(0) + switch c.GetOp().GetTokenType() { + case parser.AbacusParserMUL: + v.decimalCtx.Mul(res.Decimal, leftVal.Decimal, rightVal.Decimal) + case parser.AbacusLexerDIV: + v.decimalCtx.Quo(res.Decimal, leftVal.Decimal, rightVal.Decimal) + } + return NewResult(res) +} + +func (v *Visitor) VisitAddSub(c *parser.AddSubContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + + res := NewNumber(0) + switch c.GetOp().GetTokenType() { + case parser.AbacusParserADD: + v.decimalCtx.Add(res.Decimal, leftVal.Decimal, rightVal.Decimal) + case parser.AbacusLexerSUB: + v.decimalCtx.Sub(res.Decimal, leftVal.Decimal, rightVal.Decimal) + } + return NewResult(res) +} + +func (v *Visitor) VisitPow(c *parser.PowContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + res := NewNumber(0) + v.decimalCtx.Pow(res.Decimal, leftVal.Decimal, rightVal.Decimal) + return NewResult(res) +} + +func (v *Visitor) VisitMod(c *parser.ModContext) interface{} { + left := c.Expression(0).Accept(v).(*Result) + right := c.Expression(1).Accept(v).(*Result) + + if hasErrors(left) || hasErrors(right) { + return left.WithErrors(right) + } + + leftVal, ok := left.Value.(Number) + if !ok { + panic("unable to cast right to Number") + } + rightVal, ok := right.Value.(Number) + if !ok { + panic("unable to cast left to Number") + } + res := NewNumber(0) + v.decimalCtx.Rem(res.Decimal, leftVal.Decimal, rightVal.Decimal) + return NewResult(res) +} + +func (v *Visitor) VisitSignedExpr(c *parser.SignedExprContext) interface{} { + valRes := c.Expression().Accept(v).(*Result) + if hasErrors(valRes) { + return valRes + } + + val, ok := valRes.Value.(Number) + if !ok { + panic("unable to cast val to Number") + } + + res := NewNumber(0) + + res.Set(val.Decimal) + sign := c.Sign().Accept(v).(rune) + if sign == '-' { + res.Negative = !res.Negative + } + + return NewResult(res) +} + +func (v *Visitor) VisitParentheses(c *parser.ParenthesesContext) interface{} { + return c.Expression().Accept(v) +} + +func (v *Visitor) VisitAtomExpr(c *parser.AtomExprContext) interface{} { + return c.Atom().Accept(v) +} + +func (v *Visitor) VisitFuncExpr(c *parser.FuncExprContext) interface{} { + return c.Function().Accept(v) +} + +func (v *Visitor) VisitFunctionInvocation(c *parser.FunctionInvocationContext) interface{} { + return v.HandleFunctionInvocation(c) +} + +func (v *Visitor) VisitConstant(c *parser.ConstantContext) interface{} { + switch c.CONSTANT().GetText() { + case "pi": + if pi, ok := v.ConstantsStore.Constant(PI); !ok { + return NewResult(nil).WithError("pi is not defined") + } else { + return NewResult(pi) + } + case "phi": + if phi, ok := v.ConstantsStore.Constant(PHI); !ok { + return NewResult(nil).WithError("phi is not defined") + } else { + return NewResult(phi) + } + case "e": + if e, ok := v.ConstantsStore.Constant(E); !ok { + return NewResult(nil).WithError("e is not defined") + } else { + return NewResult(e) + } + } + return NewResult(NewNumber(0)) +} + +func (v *Visitor) VisitPercent(c *parser.PercentContext) interface{} { + valRes := c.Expression().Accept(v).(*Result) + if hasErrors(valRes) { + return valRes + } + val, ok := valRes.Value.(Number) + if !ok { + panic("unable to cast valRes to Number") + } + + v.decimalCtx.Quo(val.Decimal, val.Decimal, NewNumber(100).Decimal) + return NewResult(val) +} + +func (v *Visitor) VisitNumber(c *parser.NumberContext) interface{} { + numberString := c.SCIENTIFIC_NUMBER().GetText() + + out, _, err := apd.NewFromString(numberString) + if err != nil { + panic(err) + } + return NewResult(Number{out}) +} + +func (v *Visitor) VisitPlusSign(c *parser.PlusSignContext) interface{} { + return '+' +} + +func (v *Visitor) VisitMinusSign(c *parser.MinusSignContext) interface{} { + return '-' +} + +func (v *Visitor) VisitVariablesLambda(c *parser.VariablesLambdaContext) interface{} { + tupleRes := c.Tuple().Accept(v).(*Result) + if hasErrors(tupleRes) { + return tupleRes + } + v.convertTupleResult(tupleRes) + tuple, ok := tupleRes.Value.(Tuple) + if !ok { + panic("unable to cast tupleRes to Tuple") + } + + return NewResult(tuple) +} + +func (v *Visitor) VisitNullArityLambda(c *parser.NullArityLambdaContext) interface{} { + tupleRes := c.Tuple().Accept(v).(*Result) + if hasErrors(tupleRes) { + return tupleRes + } + v.convertTupleResult(tupleRes) + tuple, ok := tupleRes.Value.(Tuple) + if !ok { + panic("unable to cast tupleRes to Tuple") + } + + return NewResult(tuple) +} + +func (v *Visitor) VisitParameter(c *parser.ParameterContext) interface{} { + paramName := c.VARIABLE().GetText() + + if paramName == "last" { + return Parameter{ + Name: paramName, + Value: c.Expression(), + } + } + + if c.Expression() != nil { + expRes := c.Expression().Accept(v).(*Result) + if hasErrors(expRes) { + return expRes + } + number := expRes.Value.(Number) + return Parameter{ + Name: paramName, + Value: number, + } + } else if c.BoolExpression() != nil { + return Parameter{ + Name: paramName, + Value: c.BoolExpression(), + } + } + + // shouldn't be reached + return nil +} + +// TODO: Errors aren't handled +func (v *Visitor) VisitRecursionParameters(c *parser.RecursionParametersContext) interface{} { + recursionParameters := NewRecursionParameters() + + for i := 0; i < len(c.AllParameter()); i++ { + valRes := c.Parameter(i).Accept(v) + switch val := valRes.(type) { + case *Result: + return val + case Parameter: + switch parameterValue := val.Value.(type) { + case Number: + if val.Name == "rec" { + intValue, _ := parameterValue.Abs(parameterValue.Decimal).Int64() + recursionParameters.MaxRecurrences = uint(intValue) + } + case parser.IExpressionContext: + if val.Name == "last" { + recursionParameters.LastValue = parameterValue + } + case parser.IBoolExpressionContext: + if val.Name == "stop" { + recursionParameters.StopWhen = parameterValue + } else if val.Name == "mem" { + res := parameterValue.Accept(v).(*Result) + if !hasErrors(res) { + recursionParameters.Memoize = bool(res.Value.(Bool)) + } + } + } + } + } + + return recursionParameters +} + +func (v *Visitor) VisitLambdaExpr(c *parser.LambdaExprContext) interface{} { + stack := v.lambdaCallStack + lambda := &CalledLambda{ + arguments: nil, + name: c.LAMBDA_VARIABLE().GetText(), + children: []*CalledLambda{}, + nested: false, + } + +getDeclaration: + declaration, found := v.lambdaDeclarations[lambda.name] + + if found { + lambda.ctx = declaration.ctx + } + + // Handle local "composed" lambdas, e.g. E = x,Fn -> Fn(x) // Fn is local + parent := stack.Peek() + isLocal := false + + if parent != nil { + _, isLocal = parent.arguments[lambda.name] + } + if isLocal { + var parent *CalledLambda + for { + if parent == nil { + parent = stack.Peek() + } else { + parent = parent.parent + } + if parent != nil { + if value, ok := parent.arguments[lambda.name]; ok { + lambda.name = value.(String).String() + + isLocalToGrandparent := false + if parent.parent != nil { + _, isLocalToGrandparent = parent.parent.arguments[lambda.name] + } + if _, ok := v.lambdaDeclarations[lambda.name]; ok && !isLocalToGrandparent { + goto getDeclaration + } + } + } else { + break + } + } + } + if !found { + if v.strict { + return NewResult(nil).WithError("undefined lambda " + lambda.name) + } + return NewResult(NewNumber(0)) + } + + // Init arguments + if c.MixedTuple() != nil { + valuesRes := c.MixedTuple().Accept(v).(*Result) + if hasErrors(valuesRes) { + return valuesRes + } + v.convertMixedTupleResult(valuesRes) + tuple, ok := valuesRes.Value.(MixedTuple) + if !ok { + panic("unable to cast valuesRes to MixedTuple") + } + + // Check arity + if len(tuple) != len(declaration.arguments) { + count := len(declaration.arguments) + s := "" + if count > 1 { + s = "s" + } + if len(tuple) < count { + return NewResult(nil).WithError("expected " + strconv.FormatInt(int64(count), 10) + " parameter" + s) + } + } + + // Create argName -> value map + lambda.arguments = map[string]interface{}{} + for i, argument := range declaration.arguments { + // Check type of received parameter and check against expected argument + if isLambdaName(argument.String()) { + if _, ok := tuple[i].(String); !ok { + return NewResult(nil).WithError("[" + lambda.name + "] expected lambda for parameter " + strconv.Itoa(i+1) + ", got number") + } + } else { + if _, ok := tuple[i].(Number); !ok { + return NewResult(nil).WithError("[" + lambda.name + "] expected number for parameter " + strconv.Itoa(i+1) + ", got lambda") + } + } + lambda.arguments[argument.String()] = tuple[i] + } + } + + // Init recursion parameters + if _, ok := stack.recursion[lambda.name]; !ok { + if c.RecursionParameters() != nil { + stack.recursion[lambda.name] = c.RecursionParameters().Accept(v).(*RecursionParameters) + } else { + stack.recursion[lambda.name] = NewRecursionParameters() + } + } + + // Init leaf + if stack.root == nil { + stack.root = lambda + } + parent = stack.Peek() + if parent != nil { + lambda.parent = parent + parent.children = append(parent.children, lambda) + } + + recurring := stack.IsRecurring(lambda.name) + stack.Push(lambda) + + // Count times lambda has been invoked + if _, ok := stack.invokes[lambda.name]; !ok { + stack.invokes[lambda.name] = 1 + } else { + stack.invokes[lambda.name]++ + } + + // Check if memoization is enabled and if a value exists to prevent branching + if stack.recursion[lambda.name].Memoize { + cachedResult, ok := stack.memoized[lambda.Signature()] + if ok { + stack.Pop() + return cachedResult + } + } + + // Calculate and the stop condition if present + shouldStop := false + if stack.recursion[lambda.name].StopWhen != nil { + conditionRes := stack.recursion[lambda.name].StopWhen.Accept(v).(*Result) + if hasErrors(conditionRes) { + return conditionRes + } + condition, ok := conditionRes.Value.(Bool) + if !ok { + panic("unable to cast conditionRes to Bool") + } + shouldStop = bool(condition) + } + + if shouldStop { + val := NewNumber(0) + if stack.recursion[lambda.name].LastValue == nil { + stack.Pop() + return NewResult(val) + } + // Eval last value + lastValRes := stack.recursion[lambda.name].LastValue.Accept(v).(*Result) + if hasErrors(lastValRes) { + return lastValRes + } + lastVal, ok := lastValRes.Value.(Number) + if !ok { + panic("unable to cast lastValRes to Number") + } + + val.Set(lastVal.Decimal) + stack.Pop() + return NewResult(val) + } + + // Handle recursion + if recurring { + recParameters := stack.recursion[lambda.name] + invokes := stack.invokes[lambda.name] + + if recParameters.MaxRecurrences == 0 { + return NewResult(nil).WithError("recursion is disabled") + } + + if shouldStop { + val := NewNumber(0) + if stack.recursion[lambda.name].LastValue == nil { + stack.Pop() + return NewResult(val) + } + // Eval last value + lastValRes := stack.recursion[lambda.name].LastValue.Accept(v).(*Result) + if hasErrors(lastValRes) { + return lastValRes + } + lastVal, ok := lastValRes.Value.(Number) + if !ok { + panic("unable to cast lastValRes to Number") + } + + val.Set(lastVal.Decimal) + stack.Pop() + return NewResult(val) + } + if invokes > recParameters.MaxRecurrences { + val := NewNumber(0) + if stack.recursion[lambda.name].LastValue == nil { + stack.Pop() + return NewResult(val) + } + // Eval last value + lastValRes := stack.recursion[lambda.name].LastValue.Accept(v).(*Result) + if hasErrors(lastValRes) { + return lastValRes + } + lastVal, ok := lastValRes.Value.(Number) + if !ok { + panic("unable to cast lastValRes to Number") + } + + val.Set(lastVal.Decimal) + stack.Pop() + return NewResult(val) + } + } + + // Evaluate lambda + declaredLambda := lambda.ctx.Lambda() + result := declaredLambda.Accept(v).(*Result) + stack.Pop() + + switch value := result.Value.(type) { + case Tuple: + if len(value) == 1 { + v := NewNumber(0) + v.Set(value[0].Decimal) + result = NewResult(v) + if stack.recursion[lambda.name].Memoize { + stack.memoized[lambda.Signature()] = result + } + return result + } + } + + if stack.recursion[lambda.name].Memoize { + stack.memoized[lambda.Signature()] = result + } + return result +} + +func (v *Visitor) VisitVariable(c *parser.VariableContext) interface{} { + name := c.VARIABLE().GetText() + + lambda := v.lambdaCallStack.Peek() + if lambda != nil { + if value, ok := lambda.arguments[name]; ok { + return NewResult(value.(Number)) + } + } + + if value, ok := v.variables[name]; ok { + return NewResult(value) + } + + if v.strict { + return NewResult(nil).WithError("undefined global variable " + name) + } + return NewResult(NewNumber(0)) +} + +func (v *Visitor) checkParentCtxForLambda(c antlr.Tree) (bool, string) { + ctx, ok := interface{}(c).(*parser.LambdaDeclarationContext) + + lambdaName := "" + if ok { + lambdaName = ctx.LAMBDA_VARIABLE().GetText() + } + + if !ok && c.GetParent() != nil { + return v.checkParentCtxForLambda(c.GetParent()) + } + return ok, lambdaName +} + +func hasErrors(r *Result) bool { + return len(r.Errors) != 0 +} + +func isLambdaName(name string) bool { + return name[0] >= 'A' && name[0] <= 'Z' +} diff --git a/abacus/constants_store.go b/abacus/constants_store.go new file mode 100644 index 0000000..0ad8ee7 --- /dev/null +++ b/abacus/constants_store.go @@ -0,0 +1,45 @@ +package abacus + +import "github.com/viktordanov/golang-lru" + +type Constant string + +const ( + PI Constant = "pi" + PHI Constant = "phi" + E Constant = "e" +) + +type ConstantsStore struct { + Constants map[Constant]Number + LogCache *lru.Cache[string, Number] // TODO: migrate back to hashicorp/golang-lru when it supports generics +} + +func (cs *ConstantsStore) Constant(constant Constant) (Number, bool) { + value, ok := cs.Constants[constant] + return value, ok +} + +func NewConstantsStore() (*ConstantsStore, error) { + cache, err := lru.New[string, Number](1000) + if err != nil { + return nil, err + } + return &ConstantsStore{ + Constants: map[Constant]Number{}, + LogCache: cache, + }, nil +} + +func (cs *ConstantsStore) SetConstant(constant Constant, value Number) { + cs.Constants[constant] = value +} + +func (cs *ConstantsStore) Cache(key string, value Number) { + cs.LogCache.Add(key, value) +} + +func (cs *ConstantsStore) Cached(key string) (Number, bool) { + value, ok := cs.LogCache.Get(key) + return value, ok +} diff --git a/formatter.go b/abacus/formatter.go similarity index 94% rename from formatter.go rename to abacus/formatter.go index 0006d16..c3dbbe4 100644 --- a/formatter.go +++ b/abacus/formatter.go @@ -1,4 +1,4 @@ -package main +package abacus import "fmt" diff --git a/abacus/functions.go b/abacus/functions.go new file mode 100644 index 0000000..e7ece2a --- /dev/null +++ b/abacus/functions.go @@ -0,0 +1,484 @@ +package abacus + +import ( + "fmt" + "github.com/cockroachdb/apd" + "github.com/viktordanov/abacus/parser" + "math" +) + +type FunctionName string + +const ( + sqrt = FunctionName("sqrt") + cbrt = FunctionName("cbrt") + ln = FunctionName("ln") + log = FunctionName("log") + log2 = FunctionName("log2") + log10 = FunctionName("log10") + floor = FunctionName("floor") + ceil = FunctionName("ceil") + exp = FunctionName("exp") + sin = FunctionName("sin") + cos = FunctionName("cos") + tan = FunctionName("tan") + sign = FunctionName("sign") + abs = FunctionName("abs") + round = FunctionName("round") + min = FunctionName("min") + max = FunctionName("max") + avg = FunctionName("avg") + from = FunctionName("from") + until = FunctionName("until") + reverse = FunctionName("reverse") + nth = FunctionName("nth") +) + +var FunctionNames = map[FunctionName]struct{}{ + sqrt: {}, + cbrt: {}, + ln: {}, + log: {}, + log2: {}, + log10: {}, + floor: {}, + ceil: {}, + exp: {}, + sin: {}, + cos: {}, + tan: {}, + sign: {}, + abs: {}, + round: {}, + min: {}, + max: {}, + avg: {}, + from: {}, + until: {}, + reverse: {}, + nth: {}, +} + +func (v *Visitor) HandleFunctionInvocation(ctx *parser.FunctionInvocationContext) interface{} { + functionName := ctx.VARIABLE().GetText() + if _, ok := FunctionNames[FunctionName(functionName)]; !ok { + return NewResult(nil).WithError(fmt.Sprintf("undefined function %s", functionName)) + } + + tupleRes := ctx.Tuple().Accept(v).(*Result) + if hasErrors(tupleRes) { + return tupleRes + } + v.convertTupleResult(tupleRes) + + tuple, ok := tupleRes.Value.(Tuple) + if !ok { + panic("unable to cast tupleRes to Tuple") + } + + switch FunctionName(functionName) { + case sqrt: + return v.handleSqrt(tuple) + case cbrt: + return v.handleCbrt(tuple) + case ln: + return v.handleLn(tuple) + case log: + return v.handleLog(tuple) + case log2: + return v.handleLog2(tuple) + case log10: + return v.handleLog10(tuple) + case floor: + return v.handleFloor(tuple) + case ceil: + return v.handleCeil(tuple) + case exp: + return v.handleExp(tuple) + case sin: + return v.handleSin(tuple) + case cos: + return v.handleCos(tuple) + case tan: + return v.handleTan(tuple) + case sign: + return v.handleSign(tuple) + case abs: + return v.handleAbs(tuple) + case round: + return v.handleRound(tuple) + case min: + return v.handleMin(tuple) + case max: + return v.handleMax(tuple) + case avg: + return v.handleAvg(tuple) + case from: + return v.handleFrom(tuple) + case until: + return v.handleUntil(tuple) + case reverse: + return v.handleReverse(tuple) + case nth: + return v.handleNth(tuple) + default: + panic("unhandled function") + } +} + +func (v *Visitor) handleSqrt(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Sqrt(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleCbrt(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Cbrt(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleLn(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Ln(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleLog(tuple Tuple) *Result { + return v.handleLn(tuple) +} + +func (v *Visitor) handleLog2(tuple Tuple) *Result { + result := v.handleLn(tuple) + if hasErrors(result) { + return result + } + out := NewNumber(0) + + base := calculateLog(v.ConstantsStore, v.decimalCtx, NewNumber(2)) + _, err := v.decimalCtx.Quo(out.Decimal, result.Value.(Number).Decimal, base.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleLog10(tuple Tuple) *Result { + result := v.handleLn(tuple) + if hasErrors(result) { + return result + } + out := NewNumber(0) + + base := calculateLog(v.ConstantsStore, v.decimalCtx, NewNumber(10)) + _, err := v.decimalCtx.Quo(out.Decimal, result.Value.(Number).Decimal, base.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleFloor(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Floor(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleCeil(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Ceil(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleExp(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Exp(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleSin(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + toFloat, err := value.Float64() + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + out.Decimal, err = out.Decimal.SetFloat64(math.Sin(toFloat)) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleCos(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + toFloat, err := value.Float64() + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + out.Decimal, err = out.Decimal.SetFloat64(math.Cos(toFloat)) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleTan(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + toFloat, err := value.Float64() + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + out.Decimal, err = out.Decimal.SetFloat64(math.Tan(toFloat)) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleSign(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + + out := NewNumber(0) + out = NewNumber(float64(value.Decimal.Cmp(out.Decimal))) + return NewResult(out) +} + +func (v *Visitor) handleAbs(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Abs(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleRound(tuple Tuple) *Result { + var value Number + var err error + if value, err = first(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + out := NewNumber(0) + _, err = v.decimalCtx.Round(out.Decimal, value.Decimal) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(out) +} + +func (v *Visitor) handleMin(tuple Tuple) *Result { + smallest := NewNumber(0) + smallest.Set(tuple[0].Decimal) + + for i := 1; i < len(tuple); i++ { + curr := tuple[i] + if curr.Cmp(smallest.Decimal) == -1 { + smallest = curr + } + } + return NewResult(smallest) +} + +func (v *Visitor) handleMax(tuple Tuple) *Result { + biggest := NewNumber(0) + biggest.Set(tuple[0].Decimal) + + for i := 1; i < len(tuple); i++ { + curr := tuple[i] + if curr.Cmp(biggest.Decimal) == 1 { + biggest = curr + } + } + return NewResult(biggest) +} + +func (v *Visitor) handleAvg(tuple Tuple) *Result { + sum := NewNumber(0) + sum.Set(tuple[0].Decimal) + + for i := 1; i < len(tuple); i++ { + curr := tuple[i] + // TODO: handle error + v.decimalCtx.Add(sum.Decimal, sum.Decimal, curr.Decimal) + } + _, err := v.decimalCtx.Quo(sum.Decimal, sum.Decimal, apd.New(int64(len(tuple)), 0)) + if err != nil { + return NewResult(nil).WithError(err.Error()) + } + return NewResult(sum) +} + +func (v *Visitor) handleFrom(tuple Tuple) *Result { + var arg Number + var err error + + if arg, err = last(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + + if len(tuple) == 1 { + return NewResult(nil).WithError("from requires at least 2 arguments") + } + + intValue, _ := arg.Int64() + if intValue < 0 { + return NewResult(nil).WithError("from requires a non-negative integer") + } + + newTuple := make(Tuple, 0, len(tuple)-1) + length := len(tuple) + if intValue > int64(length)-1 { + intValue = int64(length) - 1 + } + + for i := intValue; i < int64(length)-1; i++ { + newTuple = append(newTuple, tuple[i]) + } + + return NewResult(newTuple) +} + +func (v *Visitor) handleUntil(tuple Tuple) *Result { + var arg Number + var err error + + if arg, err = last(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + + if len(tuple) == 1 { + return NewResult(nil).WithError("until requires at least 2 arguments") + } + + intValue, _ := arg.Int64() + if intValue < 0 { + return NewResult(nil).WithError("until requires a non-negative integer") + } + + newTuple := make(Tuple, 0, len(tuple)-1) + length := len(tuple) + if intValue > int64(length)-1 { + intValue = int64(length) - 1 + } + for i := 0; i < int(intValue); i++ { + newTuple = append(newTuple, tuple[i]) + } + + return NewResult(newTuple) +} + +func (v *Visitor) handleReverse(tuple Tuple) *Result { + newTuple := make(Tuple, 0, len(tuple)) + + for i := len(tuple) - 1; i >= 0; i-- { + newTuple = append(newTuple, tuple[i]) + } + + return NewResult(newTuple) +} + +func (v *Visitor) handleNth(tuple Tuple) *Result { + var arg Number + var err error + + if arg, err = last(tuple); err != nil { + return NewResult(nil).WithError(err.Error()) + } + + if len(tuple) == 1 { + return NewResult(nil).WithError("nth requires at least 2 arguments") + } + + intValue, _ := arg.Int64() + if intValue < 0 || intValue > int64(len(tuple)-2) { + return NewResult(nil).WithError("nth requires a non-negative integer less than the length of the tuple") + } + + return NewResult(tuple[intValue]) +} + +func first(tuple Tuple) (Number, error) { + if len(tuple) == 0 { + return Number{}, fmt.Errorf("tuple is empty") + } + return tuple[0], nil +} + +func last(tuple Tuple) (Number, error) { + if len(tuple) == 0 { + return Number{}, fmt.Errorf("tuple is empty") + } + return tuple[len(tuple)-1], nil +} diff --git a/abacus/lambda.go b/abacus/lambda.go new file mode 100644 index 0000000..dc663d8 --- /dev/null +++ b/abacus/lambda.go @@ -0,0 +1,91 @@ +package abacus + +import ( + "github.com/viktordanov/abacus/parser" + "strings" +) + +type LambdaDeclaration struct { + ctx *parser.LambdaDeclarationContext + arguments LambdaArguments + argSet map[string]bool +} + +type Parameter struct { + Name string + Value interface{} +} + +type RecursionParameters struct { + MaxRecurrences uint + LastValue parser.IExpressionContext + StopWhen parser.IBoolExpressionContext + Memoize bool +} + +func NewRecursionParameters() *RecursionParameters { + return &RecursionParameters{MaxRecurrences: 0, LastValue: nil, StopWhen: nil, Memoize: false} +} + +type CalledLambda struct { + ctx *parser.LambdaDeclarationContext + parent *CalledLambda + children []*CalledLambda + arguments map[string]interface{} + nested bool + name string +} + +func (l *CalledLambda) Signature() string { + var b strings.Builder + b.WriteString(l.name) + b.WriteRune('_') + for _, i := range l.arguments { + switch val := i.(type) { + case Number: + b.WriteString(val.String()) + case String: + b.WriteString(val.String()) + } + b.WriteRune('_') + } + return b.String() +} + +type LambdaCallStack struct { + root *CalledLambda + trace []*CalledLambda + invokes map[string]uint + recursion map[string]*RecursionParameters + memoized map[string]*Result +} + +func (s *LambdaCallStack) Peek() *CalledLambda { + if len(s.trace) == 0 { + return nil + } + return s.trace[len(s.trace)-1] +} + +func (s *LambdaCallStack) Pop() *CalledLambda { + if len(s.trace) == 0 { + return nil + } + el := s.Peek() + s.trace = s.trace[:len(s.trace)-1] + return el +} + +func (s *LambdaCallStack) Push(l *CalledLambda) { + s.trace = append(s.trace, l) +} + +func (s *LambdaCallStack) IsRecurring(lambdaName string) bool { + for i := len(s.trace) - 1; i >= 0; i-- { + if s.trace[i].name == lambdaName { + return true + } + } + + return false +} diff --git a/results.go b/abacus/result.go similarity index 95% rename from results.go rename to abacus/result.go index c19fa55..dc229bf 100644 --- a/results.go +++ b/abacus/result.go @@ -1,4 +1,4 @@ -package main +package abacus import ( "errors" @@ -17,6 +17,14 @@ type Result struct { func NewResult(value Formatter) *Result { return &Result{Value: value, Errors: make([]error, 0)} } + +func (r *Result) WithError(ee ...string) *Result { + for _, e := range ee { + r.Errors = append(r.Errors, errors.New(e)) + } + return r +} + func (r *Result) WithErrors(previous *Result, ee ...string) *Result { if previous != nil { for _, e := range previous.Errors { @@ -163,7 +171,7 @@ func (r LambdaArguments) Color() string { } type Number struct { - *apd.Decimal + *apd.Decimal } func (r Number) String() string { diff --git a/abacus_visitor.go b/abacus_visitor.go deleted file mode 100644 index fc312c4..0000000 --- a/abacus_visitor.go +++ /dev/null @@ -1,1695 +0,0 @@ -package main - -import ( - "math" - "strconv" - "strings" - - "github.com/antlr/antlr4/runtime/Go/antlr" - "github.com/cockroachdb/apd" - "github.com/viktordanov/abacus/parser" -) - -var ( - logCache map[string]Number - decimalCtx *apd.Context - PI Number - PHI Number - E Number -) - -func initConsts(precision uint32) { - logCache = make(map[string]Number) - decimalCtx = apd.BaseContext.WithPrecision(precision) - cachedLog(Number{apd.New(2, 0)}) - cachedLog(Number{apd.New(10, 0)}) - - pi, _, _ := decimalCtx.NewFromString("3." + - "14159265358979323846264338327950288419716939937510" + - "58209749445923078164062862089986280348253421170679" + - "82148086513282306647093844609550582231725359408128" + - "48111745028410270193852110555964462294895493038196" + - "44288109756659334461284756482337867831652712019091" + - "45648566923460348610454326648213393607260249141273" + - "72458700660631558817488152092096282925409171536444") - - e, _, _ := decimalCtx.NewFromString("2." + - "71828182845904523536028747135266249775724709369995" + - "95749669676277240766303535475945713821785251664274" + - "27466391932003059921817413596629043572900334295260" + - "59563073813232862794349076323382988075319525101901" + - "157383418793070215408914993488416750924147614606680" + - "82264800168477411853742345442437107539077744992069" + - "55170276183860626133138458300075204493382656029760") - - phi, _, _ := decimalCtx.NewFromString("1." + - "61803398874989484820458683436563811772030917980576" + - "28621354486227052604628189024497072072041893911374" + - "84754088075386891752126633862223536931793180060766" + - "72635443338908659593958290563832266131992829026788" + - "06752087668925017116962070322210432162695486262963" + - "13614438149758701220340805887954454749246185695364" + - "86444924104432077134494704956584678850987433944221") - - PI = Number{pi} - PHI = Number{phi} - E = Number{e} -} - -func newNumber(f float64) Number { - res := apd.New(0, 0) - res.SetFloat64(f) - return Number{res} -} - -func cachedLog(n Number) Number { - out := newNumber(0) - - var r Number - var ok bool - if r, ok = logCache[n.String()]; !ok { - decimalCtx.Ln(out.Decimal, n.Decimal) - logCache[n.String()] = newNumber(0) - logCache[n.String()].Set(out.Decimal) - } else { - out.Set(r.Decimal) - } - return out -} - -type LambdaDeclaration struct { - ctx *parser.LambdaDeclarationContext - arguments LambdaArguments - argSet map[string]bool -} - -type Parameter struct { - Name string - Value interface{} -} - -type RecursionParameters struct { - MaxRecurrences uint - LastValue parser.IExpressionContext - StopWhen parser.IBoolExpressionContext - Memoize bool -} - -func NewRecursionParameters() *RecursionParameters { - return &RecursionParameters{MaxRecurrences: 0, LastValue: nil, StopWhen: nil, Memoize: false} -} - -type CalledLambda struct { - ctx *parser.LambdaDeclarationContext - parent *CalledLambda - children []*CalledLambda - arguments map[string]interface{} - nested bool - name string -} - -func (l *CalledLambda) Signature() string { - var b strings.Builder - b.WriteString(l.name) - b.WriteRune('_') - for _, i := range l.arguments { - switch val := i.(type) { - case Number: - b.WriteString(val.String()) - case String: - b.WriteString(val.String()) - } - b.WriteRune('_') - } - return b.String() -} - -type LambdaCallStack struct { - root *CalledLambda - trace []*CalledLambda - invokes map[string]uint - recursion map[string]*RecursionParameters - memoized map[string]*Result -} - -func (s *LambdaCallStack) Peek() *CalledLambda { - if len(s.trace) == 0 { - return nil - } - return s.trace[len(s.trace)-1] -} - -func (s *LambdaCallStack) Pop() *CalledLambda { - if len(s.trace) == 0 { - return nil - } - el := s.Peek() - s.trace = s.trace[:len(s.trace)-1] - return el -} - -func (s *LambdaCallStack) Push(l *CalledLambda) { - s.trace = append(s.trace, l) -} - -func (s *LambdaCallStack) IsRecurring(lambdaName string) bool { - for i := len(s.trace) - 1; i >= 0; i-- { - if s.trace[i].name == lambdaName { - return true - } - } - - return false -} - -type AbacusVisitor struct { - antlr.ParseTreeVisitor - variables map[string]Number - lambdaDeclarations map[string]*LambdaDeclaration - lambdaCallStack *LambdaCallStack - decimalCtx *apd.Context -} - -func NewAbacusVisitor(precision uint32) *AbacusVisitor { - initConsts(precision) - return &AbacusVisitor{ - ParseTreeVisitor: &parser.BaseAbacusVisitor{}, - variables: make(map[string]Number), - lambdaDeclarations: make(map[string]*LambdaDeclaration), - lambdaCallStack: &LambdaCallStack{root: nil, invokes: map[string]uint{}, trace: []*CalledLambda{}, recursion: map[string]*RecursionParameters{}, memoized: map[string]*Result{}}, - decimalCtx: apd.BaseContext.WithPrecision(precision), - } -} - -func (a *AbacusVisitor) Visit(tree antlr.ParseTree) interface{} { - switch val := tree.(type) { - case *parser.RootContext: - a.lambdaCallStack.root = nil - a.lambdaCallStack.trace = []*CalledLambda{} - a.lambdaCallStack.invokes = map[string]uint{} - a.lambdaCallStack.recursion = map[string]*RecursionParameters{} - a.lambdaCallStack.memoized = map[string]*Result{} - return val.Accept(a) - } - return nil -} - -func (a *AbacusVisitor) VisitRoot(c *parser.RootContext) interface{} { - if c.Tuple() != nil { - return c.Tuple().Accept(a) - } - if c.Declaration() != nil { - return c.Declaration().Accept(a) - } - if c.BoolExpression() != nil { - return c.BoolExpression().Accept(a) - } - if c.LAMBDA_VARIABLE() != nil { - if declaration, ok := a.lambdaDeclarations[c.LAMBDA_VARIABLE().GetText()]; ok { - return NewResult(LambdaAssignment(declaration.ctx.GetText())) - - } - return NewResult(nil).WithErrors(nil, "undefined lambda "+c.LAMBDA_VARIABLE().GetText()) - - } - return NewResult(nil).WithErrors(nil, "syntax error") -} - -func (a *AbacusVisitor) visitTupleTail(c parser.ITupleContext, resultTuple *Tuple) { - ctx, ok := c.(*parser.TupleContext) - if !ok || ctx == nil { - return - } - val := ctx.Expression().Accept(a).(*Result) - - switch v := val.Value.(type) { - case Number: - *resultTuple = append(*resultTuple, v) - case Tuple: - *resultTuple = append(*resultTuple, v...) - } - - a.visitTupleTail(ctx.Tuple(), resultTuple) -} - -func (a *AbacusVisitor) VisitTuple(c *parser.TupleContext) interface{} { - if c.Tuple() == nil { - return c.Expression().Accept(a) - } - - evaledTuple := Tuple{} - val := c.Expression().Accept(a).(*Result) - - switch v := val.Value.(type) { - case Number: - evaledTuple = append(evaledTuple, v) - case Tuple: - evaledTuple = append(evaledTuple, v...) - } - a.visitTupleTail(c.Tuple(), &evaledTuple) - - return NewResult(evaledTuple) -} - -func (a *AbacusVisitor) visitMixedTupleTail(c parser.IMixedTupleContext, resultMixedTuple *MixedTuple) { - ctx, ok := c.(*parser.MixedTupleContext) - if !ok || ctx == nil { - return - } - val := NewResult(nil) - if ctx.Expression() != nil { - val = ctx.Expression().Accept(a).(*Result) - } else if ctx.LAMBDA_VARIABLE() != nil { - val.Value = String(ctx.LAMBDA_VARIABLE().GetText()) - } - - switch v := val.Value.(type) { - case Number: - *resultMixedTuple = append(*resultMixedTuple, v) - case String: - *resultMixedTuple = append(*resultMixedTuple, v) - case MixedTuple: - *resultMixedTuple = append(*resultMixedTuple, v...) - } - - a.visitMixedTupleTail(ctx.MixedTuple(), resultMixedTuple) -} - -func (a *AbacusVisitor) VisitMixedTuple(c *parser.MixedTupleContext) interface{} { - if c.MixedTuple() == nil { - val := NewResult(nil) - if c.Expression() != nil { - val = c.Expression().Accept(a).(*Result) - } else if c.LAMBDA_VARIABLE() != nil { - val.Value = String(c.LAMBDA_VARIABLE().GetText()) - } - return val - } - - evaledMixedTuple := MixedTuple{} - val := NewResult(nil) - if c.Expression() != nil { - val = c.Expression().Accept(a).(*Result) - } else if c.LAMBDA_VARIABLE() != nil { - val.Value = String(c.LAMBDA_VARIABLE().GetText()) - } - - switch v := val.Value.(type) { - case Number: - evaledMixedTuple = append(evaledMixedTuple, v) - case String: - evaledMixedTuple = append(evaledMixedTuple, v) - case MixedTuple: - evaledMixedTuple = append(evaledMixedTuple, v...) - } - a.visitMixedTupleTail(c.MixedTuple(), &evaledMixedTuple) - - return NewResult(evaledMixedTuple) -} - -func (a *AbacusVisitor) visitVariableTupleTail(c parser.IVariablesTupleContext, resultTuple *VariablesTuple) { - ctx, ok := c.(*parser.VariablesTupleContext) - if !ok || ctx == nil { - return - } - val := ctx.VARIABLE().GetText() - *resultTuple = append(*resultTuple, String(val)) - a.visitVariableTupleTail(ctx.VariablesTuple(), resultTuple) -} - -func (a *AbacusVisitor) VisitVariablesTuple(c *parser.VariablesTupleContext) interface{} { - if c.VariablesTuple() == nil { - return NewResult(String(c.VARIABLE().GetText())) - } - - evaledTuple := VariablesTuple{} - - val := c.VARIABLE().GetText() - evaledTuple = append(evaledTuple, String(val)) - a.visitVariableTupleTail(c.VariablesTuple(), &evaledTuple) - - foundVars := make(map[string]bool) - for _, variable := range evaledTuple { - if _, ok := foundVars[variable.String()]; !ok { - foundVars[variable.String()] = true - } else { - return NewResult(evaledTuple).WithErrors(nil, "duplicate variable name \""+variable.String()+"\"") - } - } - - return NewResult(evaledTuple) -} - -func (a *AbacusVisitor) convertVariablesTupleResult(result *Result) { - switch val := result.Value.(type) { - case String: - result.Value = VariablesTuple{val} - } -} - -func (a *AbacusVisitor) convertLambdaArgumentsResult(result *Result) { - switch val := result.Value.(type) { - case String: - result.Value = LambdaArguments{val} - } -} - -func (a *AbacusVisitor) convertTupleResult(result *Result) { - switch val := result.Value.(type) { - case Number: - result.Value = Tuple{val} - } -} - -func (a *AbacusVisitor) convertMixedTupleResult(result *Result) { - switch val := result.Value.(type) { - case Number: - result.Value = MixedTuple{val} - case String: - result.Value = MixedTuple{val} - } -} - -func (a *AbacusVisitor) VisitLambdaArguments(c *parser.LambdaArgumentsContext) interface{} { - if c.LambdaArguments() == nil { - val := "" - if c.VARIABLE() != nil { - val = c.VARIABLE().GetText() - } else if c.LAMBDA_VARIABLE() != nil { - val = c.LAMBDA_VARIABLE().GetText() - } - return NewResult(String(val)) - } - - evaledArgs := LambdaArguments{} - - val := "" - if c.VARIABLE() != nil { - val = c.VARIABLE().GetText() - } else if c.LAMBDA_VARIABLE() != nil { - val = c.LAMBDA_VARIABLE().GetText() - } - evaledArgs = append(evaledArgs, String(val)) - a.visitLambdaArgsTail(c.LambdaArguments(), &evaledArgs) - - foundVars := make(map[string]bool) - for _, variable := range evaledArgs { - if _, ok := foundVars[variable.String()]; !ok { - foundVars[variable.String()] = true - } else { - firstChar := variable[0] - if firstChar >= 'A' && firstChar <= 'Z' { - return NewResult(evaledArgs).WithErrors(nil, "duplicate lambda name \""+variable.String()+"\"") - } else { - return NewResult(evaledArgs).WithErrors(nil, "duplicate variable name \""+variable.String()+"\"") - } - } - } - - return NewResult(evaledArgs) -} - -func (a *AbacusVisitor) visitLambdaArgsTail(c parser.ILambdaArgumentsContext, resultArgs *LambdaArguments) { - ctx, ok := c.(*parser.LambdaArgumentsContext) - if !ok || ctx == nil { - return - } - val := "" - if ctx.VARIABLE() != nil { - val = ctx.VARIABLE().GetText() - } else if ctx.LAMBDA_VARIABLE() != nil { - val = ctx.LAMBDA_VARIABLE().GetText() - } - *resultArgs = append(*resultArgs, String(val)) - a.visitLambdaArgsTail(ctx.LambdaArguments(), resultArgs) -} - -func (a *AbacusVisitor) VisitVariableDeclaration(c *parser.VariableDeclarationContext) interface{} { - variablesRes := c.VariablesTuple().Accept(a).(*Result) - if hasErrors(variablesRes) { - return variablesRes - } - a.convertVariablesTupleResult(variablesRes) - - valuesRes := c.Tuple().Accept(a).(*Result) - if hasErrors(variablesRes) { - return variablesRes - } - a.convertTupleResult(valuesRes) - - if variablesRes.Length() != valuesRes.Length() { - return variablesRes.WithErrors(nil, "wrong number of valuesRes "+strconv.FormatInt(int64(valuesRes.Length()), 10)+"; expected "+strconv.FormatInt(int64(variablesRes.Length()), 10)) - } - - variables, ok := variablesRes.Value.(VariablesTuple) - if !ok { - panic("unable to convert variables result to its raw type") - } - values, ok := valuesRes.Value.(Tuple) - if !ok { - panic("unable to convert values result to its raw type") - } - - for i, variable := range variables { - a.variables[variable.String()] = values[i] - } - return NewResult(Assignment(values)) -} - -func (a *AbacusVisitor) VisitLambdaDeclaration(c *parser.LambdaDeclarationContext) interface{} { - lambdaName := c.LAMBDA_VARIABLE().GetText() - lambda := c.Lambda() - - // Check if 1) multiple variables && duped variables - multipleVarLambda, ok := lambda.(*parser.VariablesLambdaContext) - arguments := LambdaArguments{} - argMap := map[string]bool{} - if ok { - argsRes := multipleVarLambda.LambdaArguments().Accept(a).(*Result) - if hasErrors(argsRes) { - return argsRes - } - a.convertLambdaArgumentsResult(argsRes) - - arguments, ok = argsRes.Value.(LambdaArguments) - if !ok { - panic("unable to cast argsRes to LambdaArguments") - } - for _, arg := range arguments { - argMap[string(arg)] = true - } - - } - - a.lambdaDeclarations[lambdaName] = &LambdaDeclaration{ - ctx: c, - argSet: argMap, - arguments: arguments, - } - - formattedLambda := lambdaName + " = " + lambda.GetText() - return NewResult(LambdaAssignment(formattedLambda)) -} - -func (a *AbacusVisitor) VisitEqualComparison(c *parser.EqualComparisonContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) == 0)) -} - -func (a *AbacusVisitor) VisitLessComparison(c *parser.LessComparisonContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) == -1)) -} - -func (a *AbacusVisitor) VisitGreaterComparison(c *parser.GreaterComparisonContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) == 1)) -} - -func (a *AbacusVisitor) VisitLessOrEqualComparison(c *parser.LessOrEqualComparisonContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) <= 0)) -} - -func (a *AbacusVisitor) VisitGreaterOrEqualComparison(c *parser.GreaterOrEqualComparisonContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - return NewResult(Bool(leftVal.Cmp(rightVal.Decimal) >= 0)) -} - -func (a *AbacusVisitor) VisitAndOrXor(c *parser.AndOrXorContext) interface{} { - left := c.BoolExpression(0).Accept(a).(*Result) - right := c.BoolExpression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Bool) - if !ok { - panic("unable to cast right to Bool") - } - rightVal, ok := right.Value.(Bool) - if !ok { - panic("unable to cast left to Bool") - } - - op := c.GetOp().GetTokenType() - result := Bool(false) - - switch op { - case parser.AbacusParserAND: - result = leftVal && rightVal - case parser.AbacusParserOR: - result = leftVal || rightVal - case parser.AbacusParserXOR: - result = leftVal != rightVal - - } - return NewResult(result) -} - -func (a *AbacusVisitor) VisitNot(c *parser.NotContext) interface{} { - valRes := c.BoolExpression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - val, ok := valRes.Value.(Bool) - if !ok { - panic("unable to cast right to Bool") - } - return NewResult(!val) -} - -func (a *AbacusVisitor) VisitParenthesesBoolean(c *parser.ParenthesesBooleanContext) interface{} { - return c.BoolExpression().Accept(a) -} - -func (a *AbacusVisitor) VisitBoolAtom(c *parser.BoolAtomContext) interface{} { - val := c.GetText() - if val == "true" { - return NewResult(Bool(true)) - } - return NewResult(Bool(false)) -} - -func (a *AbacusVisitor) VisitBooleanAtom(c *parser.BooleanAtomContext) interface{} { - return c.BoolAtom().Accept(a) -} - -func (a *AbacusVisitor) VisitMulDiv(c *parser.MulDivContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - res := newNumber(0) - switch c.GetOp().GetTokenType() { - case parser.AbacusParserMUL: - a.decimalCtx.Mul(res.Decimal, leftVal.Decimal, rightVal.Decimal) - case parser.AbacusLexerDIV: - a.decimalCtx.Quo(res.Decimal, leftVal.Decimal, rightVal.Decimal) - } - return NewResult(res) -} - -func (a *AbacusVisitor) VisitAddSub(c *parser.AddSubContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - res := newNumber(0) - switch c.GetOp().GetTokenType() { - case parser.AbacusParserADD: - a.decimalCtx.Add(res.Decimal, leftVal.Decimal, rightVal.Decimal) - case parser.AbacusLexerSUB: - a.decimalCtx.Sub(res.Decimal, leftVal.Decimal, rightVal.Decimal) - } - return NewResult(res) -} - -func (a *AbacusVisitor) VisitPow(c *parser.PowContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - res := newNumber(0) - a.decimalCtx.Pow(res.Decimal, leftVal.Decimal, rightVal.Decimal) - return NewResult(res) -} - -func (a *AbacusVisitor) VisitMod(c *parser.ModContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - res := newNumber(0) - a.decimalCtx.Rem(res.Decimal, leftVal.Decimal, rightVal.Decimal) - return NewResult(res) -} - -func (a *AbacusVisitor) VisitSignedExpr(c *parser.SignedExprContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - res := newNumber(0) - - res.Set(val.Decimal) - sign := c.Sign().Accept(a).(rune) - if sign == '-' { - res.Negative = !res.Negative - } - - return NewResult(res) -} - -func (a *AbacusVisitor) VisitParentheses(c *parser.ParenthesesContext) interface{} { - return c.Expression().Accept(a) -} - -func (a *AbacusVisitor) VisitAtomExpr(c *parser.AtomExprContext) interface{} { - return c.Atom().Accept(a) -} - -func (a *AbacusVisitor) VisitFuncExpr(c *parser.FuncExprContext) interface{} { - return c.Function().Accept(a) -} - -func (a *AbacusVisitor) VisitSqrtFunction(c *parser.SqrtFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Sqrt(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitCbrtFunction(c *parser.CbrtFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Cbrt(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitLnFunction(c *parser.LnFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Ln(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitLogDefFunction(c *parser.LogDefFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Ln(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitLog2Function(c *parser.Log2FunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Ln(v.Decimal, val.Decimal) - a.decimalCtx.Quo(v.Decimal, v.Decimal, cachedLog(newNumber(2)).Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitLog10Function(c *parser.Log10FunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Ln(v.Decimal, val.Decimal) - base := cachedLog(newNumber(10)) - a.decimalCtx.Quo(v.Decimal, v.Decimal, base.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitFloorFunction(c *parser.FloorFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Floor(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitCeilFunction(c *parser.CeilFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Ceil(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitSinFunction(c *parser.SinFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - toFloat, _ := val.Float64() - v := newNumber(0) - v.Decimal, _ = v.Decimal.SetFloat64(math.Sin(toFloat)) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitCosFunction(c *parser.CosFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - toFloat, _ := val.Float64() - v := newNumber(0) - v.Decimal, _ = v.Decimal.SetFloat64(math.Cos(toFloat)) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitTanFunction(c *parser.TanFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - toFloat, _ := val.Float64() - v := newNumber(0) - v.Decimal, _ = v.Decimal.SetFloat64(math.Tan(toFloat)) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitExpFunction(c *parser.ExpFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Exp(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitSignFunction(c *parser.SignFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - v = newNumber(float64(val.Decimal.Cmp(v.Decimal))) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitAbsFunction(c *parser.AbsFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Abs(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitRoundDefFunction(c *parser.RoundDefFunctionContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast val to Number") - } - - v := newNumber(0) - a.decimalCtx.Round(v.Decimal, val.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitRound2Function(c *parser.Round2FunctionContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - intValue, _ := rightVal.Decimal.Int64() - exponent := apd.New(10, int32(intValue)) - - v := newNumber(0) - a.decimalCtx.Mul(v.Decimal, leftVal.Decimal, exponent) - a.decimalCtx.Round(v.Decimal, v.Decimal) - a.decimalCtx.Quo(v.Decimal, v.Decimal, exponent) - - return NewResult(v) -} - -func (a *AbacusVisitor) VisitLogFunction(c *parser.LogFunctionContext) interface{} { - left := c.Expression(0).Accept(a).(*Result) - right := c.Expression(1).Accept(a).(*Result) - - if hasErrors(left) || hasErrors(right) { - return left.WithErrors(right) - } - - leftVal, ok := left.Value.(Number) - if !ok { - panic("unable to cast right to Number") - } - rightVal, ok := right.Value.(Number) - if !ok { - panic("unable to cast left to Number") - } - - v := newNumber(0) - - a.decimalCtx.Ln(v.Decimal, leftVal.Decimal) - base := cachedLog(rightVal) - a.decimalCtx.Quo(v.Decimal, v.Decimal, base.Decimal) - return NewResult(v) -} - -func (a *AbacusVisitor) VisitMinFunction(c *parser.MinFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - smallest := newNumber(0) - smallest.Set(tuple[0].Decimal) - - for i := 1; i < len(tuple); i++ { - curr := tuple[i] - if curr.Cmp(smallest.Decimal) == -1 { - smallest = curr - } - } - - return NewResult(smallest) -} - -func (a *AbacusVisitor) VisitMaxFunction(c *parser.MaxFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - biggest := newNumber(0) - biggest.Set(tuple[0].Decimal) - - for i := 1; i < len(tuple); i++ { - curr := tuple[i] - if curr.Cmp(biggest.Decimal) == 1 { - biggest = curr - } - } - - return NewResult(biggest) -} - -func (a *AbacusVisitor) VisitAvgFunction(c *parser.AvgFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - sum := newNumber(0) - sum.Set(tuple[0].Decimal) - - for i := 1; i < len(tuple); i++ { - curr := tuple[i] - a.decimalCtx.Add(sum.Decimal, sum.Decimal, curr.Decimal) - } - a.decimalCtx.Quo(sum.Decimal, sum.Decimal, apd.New(int64(len(tuple)), 0)) - return NewResult(sum) -} - -func (a *AbacusVisitor) VisitUntilFunction(c *parser.UntilFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - argRes := c.Expression().Accept(a).(*Result) - if hasErrors(argRes) { - return argRes - } - - arg, ok := argRes.Value.(Number) - if !ok { - panic("unable to cast argRes to Number") - } - intValue, _ := arg.Int64() - - newTuple := Tuple{} - length := int64(len(tuple)) - - if intValue > length { - intValue = length - } - for i := 0; i < int(intValue); i++ { - newTuple = append(newTuple, tuple[i]) - } - - if len(newTuple) == 0 { - return NewResult(newNumber(0)) - } - return NewResult(newTuple) -} - -func (a *AbacusVisitor) VisitFromFunction(c *parser.FromFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - arg := tuple[len(tuple)-1] - intValue, _ := arg.Int64() - - newTuple := Tuple{} - length := int64(len(tuple)) - - if intValue < 0 { - intValue = 0 - } - for i := intValue; i < length-1; i++ { - newTuple = append(newTuple, tuple[i]) - } - - if len(newTuple) == 0 { - return NewResult(newNumber(0)) - } - return NewResult(newTuple) -} - -func (a *AbacusVisitor) VisitReverseFunction(c *parser.ReverseFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - newTuple := Tuple{} - for i := len(tuple) - 1; i >= 0; i-- { - newTuple = append(newTuple, tuple[i]) - } - return NewResult(newTuple) -} - -func (a *AbacusVisitor) VisitNthFunction(c *parser.NthFunctionContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - argRes := c.Expression().Accept(a).(*Result) - if hasErrors(argRes) { - return argRes - } - arg, ok := argRes.Value.(Number) - if !ok { - panic("unable to cast argRes to Number") - } - intValue1, _ := arg.Int64() - - if intValue1 >= int64(len(tuple)) || intValue1 < 0 { - return NewResult(newNumber(0)) - } - return NewResult(tuple[intValue1]) -} - -func (a *AbacusVisitor) VisitConstant(c *parser.ConstantContext) interface{} { - switch c.CONSTANT().GetText() { - case "pi": - return NewResult(PI) - case "phi": - return NewResult(PHI) - case "e": - return NewResult(E) - } - return NewResult(newNumber(0)) -} - -func (a *AbacusVisitor) VisitPercent(c *parser.PercentContext) interface{} { - valRes := c.Expression().Accept(a).(*Result) - if hasErrors(valRes) { - return valRes - } - val, ok := valRes.Value.(Number) - if !ok { - panic("unable to cast valRes to Number") - } - - a.decimalCtx.Quo(val.Decimal, val.Decimal, newNumber(100).Decimal) - return NewResult(val) -} - -func (a *AbacusVisitor) VisitNumber(c *parser.NumberContext) interface{} { - numberString := c.SCIENTIFIC_NUMBER().GetText() - - out, _, err := apd.NewFromString(numberString) - if err != nil { - panic(err) - } - return NewResult(Number{out}) -} - -func (a *AbacusVisitor) VisitPlusSign(c *parser.PlusSignContext) interface{} { - return '+' -} - -func (a *AbacusVisitor) VisitMinusSign(c *parser.MinusSignContext) interface{} { - return '-' -} - -func (a *AbacusVisitor) VisitVariablesLambda(c *parser.VariablesLambdaContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - return NewResult(tuple) -} - -func (a *AbacusVisitor) VisitNullArityLambda(c *parser.NullArityLambdaContext) interface{} { - tupleRes := c.Tuple().Accept(a).(*Result) - if hasErrors(tupleRes) { - return tupleRes - } - a.convertTupleResult(tupleRes) - tuple, ok := tupleRes.Value.(Tuple) - if !ok { - panic("unable to cast tupleRes to Tuple") - } - - return NewResult(tuple) -} - -func (a *AbacusVisitor) VisitParameter(c *parser.ParameterContext) interface{} { - paramName := c.VARIABLE().GetText() - - if paramName == "last" { - return Parameter{ - Name: paramName, - Value: c.Expression(), - } - } - - if c.Expression() != nil { - expRes := c.Expression().Accept(a).(*Result) - if hasErrors(expRes) { - return expRes - } - number := expRes.Value.(Number) - return Parameter{ - Name: paramName, - Value: number, - } - } else if c.BoolExpression() != nil { - return Parameter{ - Name: paramName, - Value: c.BoolExpression(), - } - } - - // shouldn't be reached - return nil -} - -// TODO: Errors aren't handled -func (a *AbacusVisitor) VisitRecursionParameters(c *parser.RecursionParametersContext) interface{} { - recursionParameters := NewRecursionParameters() - - for i := 0; i < len(c.AllParameter()); i++ { - valRes := c.Parameter(i).Accept(a) - switch val := valRes.(type) { - case *Result: - return val - case Parameter: - switch parameterValue := val.Value.(type) { - case Number: - if val.Name == "rec" { - intValue, _ := parameterValue.Abs(parameterValue.Decimal).Int64() - recursionParameters.MaxRecurrences = uint(intValue) - } - case parser.IExpressionContext: - if val.Name == "last" { - recursionParameters.LastValue = parameterValue - } - case parser.IBoolExpressionContext: - if val.Name == "stop" { - recursionParameters.StopWhen = parameterValue - } else if val.Name == "mem" { - res := parameterValue.Accept(a).(*Result) - if !hasErrors(res) { - recursionParameters.Memoize = bool(res.Value.(Bool)) - } - } - } - } - } - - return recursionParameters -} - -func (a *AbacusVisitor) VisitLambdaExpr(c *parser.LambdaExprContext) interface{} { - stack := a.lambdaCallStack - lambda := &CalledLambda{ - arguments: nil, - name: c.LAMBDA_VARIABLE().GetText(), - children: []*CalledLambda{}, - nested: false, - } - -getDeclaration: - declaration, found := a.lambdaDeclarations[lambda.name] - - if found { - lambda.ctx = declaration.ctx - } - - // Handle local "composed" lambdas, e.g. E = x,Fn -> Fn(x) // Fn is local - parent := stack.Peek() - isLocal := false - - if parent != nil { - _, isLocal = parent.arguments[lambda.name] - } - if isLocal { - var parent *CalledLambda - for { - if parent == nil { - parent = stack.Peek() - } else { - parent = parent.parent - } - if parent != nil { - if value, ok := parent.arguments[lambda.name]; ok { - lambda.name = value.(String).String() - - isLocalToGrandparent := false - if parent.parent != nil { - _, isLocalToGrandparent = parent.parent.arguments[lambda.name] - } - if _, ok := a.lambdaDeclarations[lambda.name]; ok && !isLocalToGrandparent { - goto getDeclaration - } - } - } else { - break - } - } - } - if !found { - if arguments.Strict { - return NewResult(nil).WithErrors(nil, "undefined lambda "+lambda.name) - } - return NewResult(newNumber(0)) - } - - // Init arguments - if c.MixedTuple() != nil { - valuesRes := c.MixedTuple().Accept(a).(*Result) - if hasErrors(valuesRes) { - return valuesRes - } - a.convertMixedTupleResult(valuesRes) - tuple, ok := valuesRes.Value.(MixedTuple) - if !ok { - panic("unable to cast valuesRes to MixedTuple") - } - - // Check arity - if len(tuple) != len(declaration.arguments) { - count := len(declaration.arguments) - s := "" - if count > 1 { - s = "s" - } - if len(tuple) < count { - return NewResult(nil).WithErrors(nil, "expected "+strconv.FormatInt(int64(count), 10)+" parameter"+s) - } - } - - // Create argName -> value map - lambda.arguments = map[string]interface{}{} - for i, argument := range declaration.arguments { - // Check type of received parameter and check against expected argument - if isLambdaName(argument.String()) { - if _, ok := tuple[i].(String); !ok { - return NewResult(nil).WithErrors(nil, "["+lambda.name+"] expected lambda for parameter "+strconv.Itoa(i+1)+", got number") - } - } else { - if _, ok := tuple[i].(Number); !ok { - return NewResult(nil).WithErrors(nil, "["+lambda.name+"] expected number for parameter "+strconv.Itoa(i+1)+", got lambda") - } - } - lambda.arguments[argument.String()] = tuple[i] - } - } - - // Init recursion parameters - if _, ok := stack.recursion[lambda.name]; !ok { - if c.RecursionParameters() != nil { - stack.recursion[lambda.name] = c.RecursionParameters().Accept(a).(*RecursionParameters) - } else { - stack.recursion[lambda.name] = NewRecursionParameters() - } - } - - // Init leaf - if stack.root == nil { - stack.root = lambda - } - parent = stack.Peek() - if parent != nil { - lambda.parent = parent - parent.children = append(parent.children, lambda) - } - - recurring := stack.IsRecurring(lambda.name) - stack.Push(lambda) - - // Count times lambda has been invoked - if _, ok := stack.invokes[lambda.name]; !ok { - stack.invokes[lambda.name] = 1 - } else { - stack.invokes[lambda.name]++ - } - - // Check if memoization is enabled and if a value exists to prevent branching - if stack.recursion[lambda.name].Memoize { - cachedResult, ok := stack.memoized[lambda.Signature()] - if ok { - stack.Pop() - return cachedResult - } - } - - // Calculate and the stop condition if present - shouldStop := false - if stack.recursion[lambda.name].StopWhen != nil { - conditionRes := stack.recursion[lambda.name].StopWhen.Accept(a).(*Result) - if hasErrors(conditionRes) { - return conditionRes - } - condition, ok := conditionRes.Value.(Bool) - if !ok { - panic("unable to cast conditionRes to Bool") - } - shouldStop = bool(condition) - } - - if shouldStop { - v := newNumber(0) - if stack.recursion[lambda.name].LastValue == nil { - stack.Pop() - return NewResult(v) - } - // Eval last value - lastValRes := stack.recursion[lambda.name].LastValue.Accept(a).(*Result) - if hasErrors(lastValRes) { - return lastValRes - } - lastVal, ok := lastValRes.Value.(Number) - if !ok { - panic("unable to cast lastValRes to Number") - } - - v.Set(lastVal.Decimal) - stack.Pop() - return NewResult(v) - } - - // Handle recursion - if recurring { - recParameters := stack.recursion[lambda.name] - invokes := stack.invokes[lambda.name] - - if recParameters.MaxRecurrences == 0 { - return NewResult(nil).WithErrors(nil, "recursion is disabled") - } - - if shouldStop { - v := newNumber(0) - if stack.recursion[lambda.name].LastValue == nil { - stack.Pop() - return NewResult(v) - } - // Eval last value - lastValRes := stack.recursion[lambda.name].LastValue.Accept(a).(*Result) - if hasErrors(lastValRes) { - return lastValRes - } - lastVal, ok := lastValRes.Value.(Number) - if !ok { - panic("unable to cast lastValRes to Number") - } - - v.Set(lastVal.Decimal) - stack.Pop() - return NewResult(v) - } - if invokes > recParameters.MaxRecurrences { - v := newNumber(0) - if stack.recursion[lambda.name].LastValue == nil { - stack.Pop() - return NewResult(v) - } - // Eval last value - lastValRes := stack.recursion[lambda.name].LastValue.Accept(a).(*Result) - if hasErrors(lastValRes) { - return lastValRes - } - lastVal, ok := lastValRes.Value.(Number) - if !ok { - panic("unable to cast lastValRes to Number") - } - - v.Set(lastVal.Decimal) - stack.Pop() - return NewResult(v) - } - } - - // Evaluate lambda - declaredLambda := lambda.ctx.Lambda() - result := declaredLambda.Accept(a).(*Result) - stack.Pop() - - switch value := result.Value.(type) { - case Tuple: - if len(value) == 1 { - v := newNumber(0) - v.Set(value[0].Decimal) - result = NewResult(v) - if stack.recursion[lambda.name].Memoize { - stack.memoized[lambda.Signature()] = result - } - return result - } - } - - if stack.recursion[lambda.name].Memoize { - stack.memoized[lambda.Signature()] = result - } - return result -} - -func (a *AbacusVisitor) VisitVariable(c *parser.VariableContext) interface{} { - name := c.VARIABLE().GetText() - - lambda := a.lambdaCallStack.Peek() - if lambda != nil { - if value, ok := lambda.arguments[name]; ok { - return NewResult(value.(Number)) - } - } - - if value, ok := a.variables[name]; ok { - return NewResult(value) - } - - if arguments.Strict { - return NewResult(nil).WithErrors(nil, "undefined global variable "+name) - } - return NewResult(newNumber(0)) -} - -func (a *AbacusVisitor) checkParentCtxForLambda(c antlr.Tree) (bool, string) { - ctx, ok := interface{}(c).(*parser.LambdaDeclarationContext) - - lambdaName := "" - if ok { - lambdaName = ctx.LAMBDA_VARIABLE().GetText() - } - - if !ok && c.GetParent() != nil { - return a.checkParentCtxForLambda(c.GetParent()) - } - return ok, lambdaName -} - -func hasErrors(r *Result) bool { - return len(r.Errors) != 0 -} - -func isLambdaName(name string) bool { - return name[0] >= 'A' && name[0] <= 'Z' -} diff --git a/main.go b/cmd/abacus-cli/main.go similarity index 79% rename from main.go rename to cmd/abacus-cli/main.go index 0ed86d7..79ed612 100644 --- a/main.go +++ b/cmd/abacus-cli/main.go @@ -4,8 +4,8 @@ import ( "context" "errors" "fmt" + "github.com/viktordanov/abacus/abacus" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -13,7 +13,7 @@ import ( "strings" "github.com/alexflint/go-arg" - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/antlr/antlr4/runtime/Go/antlr/v4" "github.com/peterh/liner" "github.com/thecodeteam/goodbye" "github.com/viktordanov/abacus/parser" @@ -23,9 +23,6 @@ var ( arguments args homeDir, _ = os.UserHomeDir() historyFile = filepath.Join(homeDir, ".abacus_history") - funcs = []string{ - "sqrt(", "cbrt(", "ln(", "log(", "log2(", "log10(", "floor(", "ceil(", "exp(", "sin(", "cos(", "tan(", "sign(", "abs(", "round(", "min(", "max(", "avg(", "from(", "until(", "reverse(", "nth(", "pi", "e", "phi", - } ) type StringSliceArg []string @@ -35,9 +32,9 @@ func (s *StringSliceArg) UnmarshalText(text []byte) error { raw = strings.ReplaceAll(raw, " ", "") *s = strings.Split(raw, ",") - variableNameMatching := regexp.MustCompile(`^[a-z]\w*$`).MatchString + variableNameMatcher := regexp.MustCompile(`^[a-z]\w*$`).MatchString for _, variableName := range *s { - if !variableNameMatching(variableName) { + if !variableNameMatcher(variableName) { return errors.New("variable names must begin with a latin lowercase letter and consist of a-zA-Z0-9") } } @@ -56,7 +53,7 @@ type args struct { } func (args) Version() string { - return "v1.3.0\n" + return "v1.4.0\n" } func (args) Description() string { return "abacus - a simple interactive calculator CLI with support for variables, lambdas, comparison checks, and math functions\n" @@ -74,7 +71,10 @@ func main() { func run() error { arg.MustParse(&arguments) - abacusVisitor := NewAbacusVisitor(arguments.Precision) + abacusVisitor, err := abacus.NewAbacusVisitor(arguments.Precision, arguments.Strict) + if err != nil { + return err + } line := liner.NewLiner() defer line.Close() @@ -98,26 +98,23 @@ func run() error { return err } - handleAndPrintAnswer := func(res *Result) { + handleAndPrintAnswer := func(res *abacus.Result) { if len(res.Errors) != 0 { for _, e := range res.Errors { - fmt.Print(Red) + fmt.Print(abacus.Red) fmt.Print(e.Error()) - fmt.Println(Reset) + fmt.Println(abacus.Reset) } return } switch rawValue := res.Value.(type) { - case Assignment: - updateCompletions(line, abacusVisitor) - case LambdaAssignment: - updateCompletions(line, abacusVisitor) - case Number: + case abacus.Assignment: + case abacus.LambdaAssignment: + case abacus.Number: for _, variableName := range arguments.LastAnswerVariables { - abacusVisitor.variables[variableName] = rawValue + abacusVisitor.SetVariable(variableName, rawValue) } - updateCompletions(line, abacusVisitor) } if arguments.IgnoreColor { @@ -125,10 +122,11 @@ func run() error { } else { fmt.Println(res.Value.Color()) } + updateCompletions(line, abacusVisitor) } if len(arguments.ImportDefinitions) != 0 { - dat, err := ioutil.ReadFile(arguments.ImportDefinitions) + dat, err := os.ReadFile(arguments.ImportDefinitions) if err != nil { return err } @@ -175,8 +173,8 @@ func run() error { } } -func evaluateExpression(expr string, visitor *AbacusVisitor) *Result { - result := NewResult(nil).WithErrors(nil, "expression did not yield a result") +func evaluateExpression(expr string, visitor *abacus.Visitor) *abacus.Result { + result := abacus.NewResult(nil).WithError("expression did not yield a result") ok := false expressions := strings.Split(expr, ";") @@ -202,9 +200,9 @@ func evaluateExpression(expr string, visitor *AbacusVisitor) *Result { p.BuildParseTrees = true tree := p.Root() t := visitor.Visit(tree) - result, ok = t.(*Result) + result, ok = t.(*abacus.Result) if !ok { - return NewResult(nil).WithErrors(nil, "expression did not yield a result") + return abacus.NewResult(nil).WithError("expression did not yield a result") } } return result @@ -220,15 +218,21 @@ func writeHistoryFile(line *liner.State) error { return err } -func updateCompletions(line *liner.State, a *AbacusVisitor) { +func updateCompletions(line *liner.State, a *abacus.Visitor) { completions := make([]string, 0) - completions = append(completions, funcs...) - for k := range a.variables { - completions = append(completions, k) + + functionNames := []string{} + for name := range abacus.FunctionNames { + functionNames = append(functionNames, string(name)+"(") + } + + completions = append(completions, functionNames...) + for _, variableName := range a.VariableNames() { + completions = append(completions, variableName) } - for k := range a.lambdaDeclarations { - completions = append(completions, k+"(") + for _, lambdaName := range a.LambdaNames() { + completions = append(completions, lambdaName+"(") } line.SetCompleter(func(line string) (c []string) { diff --git a/main_test.go b/cmd/abacus-cli/main_test.go similarity index 57% rename from main_test.go rename to cmd/abacus-cli/main_test.go index feeabd9..8e94427 100644 --- a/main_test.go +++ b/cmd/abacus-cli/main_test.go @@ -1,6 +1,7 @@ package main import ( + "github.com/viktordanov/abacus/abacus" "testing" "github.com/cockroachdb/apd" @@ -9,42 +10,46 @@ import ( type testArgs = []struct { expr string want interface{} - visitor *AbacusVisitor + visitor *abacus.Visitor } func Test_evaluateExpression(t *testing.T) { - visitor := NewAbacusVisitor(64) - decimalCtx = apd.BaseContext.WithPrecision(64) + visitor, err := abacus.NewAbacusVisitor(64, false) + if err != nil { + t.Errorf("Error creating visitor: %v", err) + return + } + decimalCtx := apd.BaseContext.WithPrecision(64) additionTests := testArgs{ - {expr: "2+2", want: newNumber(4), visitor: visitor}, - {expr: "2 +2+ 2+2+2+ 2", want: newNumber(12), visitor: visitor}, - {expr: "0+ 8+( d+4)", want: newNumber(12), visitor: visitor}, - {expr: "(2+2)", want: newNumber(4), visitor: visitor}, - {expr: "2-2", want: newNumber(0), visitor: visitor}, - {expr: "2", want: newNumber(2), visitor: visitor}, - {expr: "2.139487526 + 9.4777777", want: newNumber(11.617265226), visitor: visitor}, + {expr: "2+2", want: abacus.NewNumber(4), visitor: visitor}, + {expr: "2 +2+ 2+2+2+ 2", want: abacus.NewNumber(12), visitor: visitor}, + {expr: "0+ 8+( d+4)", want: abacus.NewNumber(12), visitor: visitor}, + {expr: "(2+2)", want: abacus.NewNumber(4), visitor: visitor}, + {expr: "2-2", want: abacus.NewNumber(0), visitor: visitor}, + {expr: "2", want: abacus.NewNumber(2), visitor: visitor}, + {expr: "2.139487526 + 9.4777777", want: abacus.NewNumber(11.617265226), visitor: visitor}, } multiplicationTests := testArgs{ - {expr: "2*2", want: newNumber(4), visitor: visitor}, - {expr: "2*2*2", want: newNumber(8), visitor: visitor}, + {expr: "2*2", want: abacus.NewNumber(4), visitor: visitor}, + {expr: "2*2*2", want: abacus.NewNumber(8), visitor: visitor}, {expr: "0.188492164*2.444445187", want: newNumFromString(decimalCtx, "0.460758763077014668"), visitor: visitor}, {expr: "9.00005849491657/0.18849622221346", want: newNumFromString(decimalCtx, "47.74662531286476055056365115305431970338920063933451796995514209"), visitor: visitor}, - {expr: "2*(2+9)", want: newNumber(22), visitor: visitor}, - {expr: "(2*2)+9", want: newNumber(13), visitor: visitor}, + {expr: "2*(2+9)", want: abacus.NewNumber(22), visitor: visitor}, + {expr: "(2*2)+9", want: abacus.NewNumber(13), visitor: visitor}, } exponentiationTests := testArgs{ - {expr: "2^2", want: newNumber(4), visitor: visitor}, - {expr: "2^2^2**2", want: newNumber(256), visitor: visitor}, - {expr: "2^(2**2^2)", want: newNumber(65536), visitor: visitor}, - {expr: "2**0", want: newNumber(1), visitor: visitor}, + {expr: "2^2", want: abacus.NewNumber(4), visitor: visitor}, + {expr: "2^2^2**2", want: abacus.NewNumber(256), visitor: visitor}, + {expr: "2^(2**2^2)", want: abacus.NewNumber(65536), visitor: visitor}, + {expr: "2**0", want: abacus.NewNumber(1), visitor: visitor}, } variableTests := testArgs{ - {expr: "d", want: newNumber(0), visitor: visitor}, - {expr: "d=1", want: Assignment{newNumber(1)}, visitor: visitor}, - {expr: "d", want: newNumber(1), visitor: visitor}, - {expr: "dd=d", want: Assignment{newNumber(1)}, visitor: visitor}, - {expr: "dd", want: newNumber(1), visitor: visitor}, + {expr: "d", want: abacus.NewNumber(0), visitor: visitor}, + {expr: "d=1", want: abacus.Assignment{abacus.NewNumber(1)}, visitor: visitor}, + {expr: "d", want: abacus.NewNumber(1), visitor: visitor}, + {expr: "dd=d", want: abacus.Assignment{abacus.NewNumber(1)}, visitor: visitor}, + {expr: "dd", want: abacus.NewNumber(1), visitor: visitor}, } comparisonTests := testArgs{ {expr: "0 == 0", want: true, visitor: visitor}, @@ -72,8 +77,16 @@ func Test_evaluateExpression(t *testing.T) { } func BenchmarkEvaluateExpression(b *testing.B) { - visitor := NewAbacusVisitor(64) + b.StopTimer() + visitor, err := abacus.NewAbacusVisitor(64, true) + if err != nil { + b.Errorf("Error creating visitor: %v", err) + return + } + complicatedExpression := "2+2+sin(4**5**((7/(4**(pi/1.45*e*log(97,1.1))))**8))" + + b.StartTimer() for i := 0; i < b.N; i++ { evaluateExpression(complicatedExpression, visitor) } @@ -85,8 +98,8 @@ func runTestSuite(t *testing.T, name string, tests testArgs) { t.Run(tt.expr, func(t *testing.T) { ans := evaluateExpression(tt.expr, tt.visitor) switch val := ans.Value.(type) { - case Assignment: - expected, ok := tt.want.(Assignment) + case abacus.Assignment: + expected, ok := tt.want.(abacus.Assignment) if !ok { t.Errorf("Assignment %v, unexpected type", ans) } @@ -95,15 +108,15 @@ func runTestSuite(t *testing.T, name string, tests testArgs) { t.Errorf("Assignment %v, want %v", val[i], expected[i]) } } - case Number: - expected, ok := tt.want.(Number) + case abacus.Number: + expected, ok := tt.want.(abacus.Number) if !ok { t.Errorf("Number %v, unexpected type", ans) } if !compareNum(val, expected) { t.Errorf("Number %v, want %v", val, expected) } - case Bool: + case abacus.Bool: expected, ok := tt.want.(bool) if !ok { t.Errorf("Bool %v, unexpected type", ans) @@ -117,11 +130,11 @@ func runTestSuite(t *testing.T, name string, tests testArgs) { }) } -func newNumFromString(ctx *apd.Context, s string) Number { +func newNumFromString(ctx *apd.Context, s string) abacus.Number { n, _, _ := ctx.NewFromString(s) - return Number{n} + return abacus.Number{Decimal: n} } -func compareNum(left, right Number) bool { +func compareNum(left, right abacus.Number) bool { return left.Cmp(right.Decimal) == 0 } diff --git a/go.mod b/go.mod index 49a70b9..6a9f0e4 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,22 @@ module github.com/viktordanov/abacus -go 1.18 +go 1.19 require ( github.com/alexflint/go-arg v1.3.0 - github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220722194653-14703f21b580 + github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20220911224424-aa1f1f12a846 github.com/cockroachdb/apd v1.1.0 github.com/peterh/liner v1.2.1 github.com/thecodeteam/goodbye v0.0.0-20170927022442-a83968bda2d3 + github.com/viktordanov/golang-lru v0.5.6 ) require ( github.com/alexflint/go-scalar v1.0.0 // indirect + github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/lib/pq v1.9.0 // indirect github.com/mattn/go-runewidth v0.0.10 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect + golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect ) diff --git a/go.sum b/go.sum index 1cf7fe1..c0d7828 100644 --- a/go.sum +++ b/go.sum @@ -2,12 +2,16 @@ github.com/alexflint/go-arg v1.3.0 h1:UfldqSdFWeLtoOuVRosqofU4nmhI1pYEbT4ZFS34Bd github.com/alexflint/go-arg v1.3.0/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM= github.com/alexflint/go-scalar v1.0.0 h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70= github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw= -github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220722194653-14703f21b580 h1:rfAZfq1LjIhVCFsBp2MoXxVvgtCyZUOtzsV8azhR1Jk= -github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220722194653-14703f21b580/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY= +github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20220911224424-aa1f1f12a846 h1:et5J11AOyUn9qwkIAF9kcxTxjTO8Z9oSmlOqH7MVSPo= +github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20220911224424-aa1f1f12a846/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8= github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -26,3 +30,9 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/thecodeteam/goodbye v0.0.0-20170927022442-a83968bda2d3 h1:COy7ekr2jBEd34npP2LvMTqk9UtiLkuvkjiJFHihlTo= github.com/thecodeteam/goodbye v0.0.0-20170927022442-a83968bda2d3/go.mod h1:ehwM4AFY4byYSorQbigh79cKUOUNL3pAOz5eCAQNlGI= +github.com/viktordanov/golang-lru v0.5.5 h1:JHcmO1MW/LfjZA52cdmGO0TnO8K86idjD2Vgnx6v9Ck= +github.com/viktordanov/golang-lru v0.5.5/go.mod h1:R91CBCcMhp6TYUy8NHP/PJ09sk5BTDwb8KMO21CELes= +github.com/viktordanov/golang-lru v0.5.6 h1:wEyMgglEo5IZ7Maxeh8E2jCPskpQnt6FJAYl1/TJ6ac= +github.com/viktordanov/golang-lru v0.5.6/go.mod h1:R91CBCcMhp6TYUy8NHP/PJ09sk5BTDwb8KMO21CELes= +golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= +golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= diff --git a/parser/Abacus.interp b/parser/Abacus.interp index fe18039..ceb5a3b 100644 --- a/parser/Abacus.interp +++ b/parser/Abacus.interp @@ -4,28 +4,6 @@ null 'false' ':' ',' -'sqrt' -'cbrt' -'ln' -'log' -'log2' -'log10' -'floor' -'ceil' -'exp' -'sin' -'cos' -'tan' -'round' -'sign' -'abs' -'min' -'max' -'avg' -'until' -'from' -'reverse' -'nth' '&&' '||' 'xor' @@ -60,28 +38,6 @@ null null null null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null AND OR XOR @@ -129,4 +85,4 @@ function atn: -[4, 1, 53, 354, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 42, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 51, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 72, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 81, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 92, 8, 2, 1, 2, 1, 2, 1, 2, 5, 2, 97, 8, 2, 10, 2, 12, 2, 100, 9, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 112, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 125, 8, 5, 1, 5, 1, 5, 3, 5, 129, 8, 5, 1, 5, 3, 5, 132, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 149, 8, 5, 10, 5, 12, 5, 152, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 158, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 164, 8, 7, 10, 7, 12, 7, 167, 9, 7, 3, 7, 169, 8, 7, 1, 7, 1, 7, 1, 8, 1, 8, 3, 8, 175, 8, 8, 1, 8, 1, 8, 3, 8, 179, 8, 8, 1, 9, 1, 9, 1, 9, 3, 9, 184, 8, 9, 1, 10, 1, 10, 1, 10, 3, 10, 189, 8, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 195, 8, 10, 1, 10, 3, 10, 198, 8, 10, 1, 11, 1, 11, 1, 11, 3, 11, 203, 8, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 209, 8, 11, 1, 11, 3, 11, 212, 8, 11, 1, 12, 1, 12, 1, 12, 1, 12, 3, 12, 218, 8, 12, 1, 13, 1, 13, 3, 13, 222, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 3, 14, 352, 8, 14, 1, 14, 0, 2, 4, 10, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 0, 6, 1, 0, 27, 29, 1, 0, 1, 2, 1, 0, 36, 37, 1, 0, 38, 39, 2, 0, 3, 3, 31, 31, 1, 0, 48, 49, 402, 0, 41, 1, 0, 0, 0, 2, 50, 1, 0, 0, 0, 4, 91, 1, 0, 0, 0, 6, 101, 1, 0, 0, 0, 8, 111, 1, 0, 0, 0, 10, 131, 1, 0, 0, 0, 12, 153, 1, 0, 0, 0, 14, 159, 1, 0, 0, 0, 16, 174, 1, 0, 0, 0, 18, 180, 1, 0, 0, 0, 20, 197, 1, 0, 0, 0, 22, 211, 1, 0, 0, 0, 24, 217, 1, 0, 0, 0, 26, 221, 1, 0, 0, 0, 28, 351, 1, 0, 0, 0, 30, 31, 3, 2, 1, 0, 31, 32, 5, 0, 0, 1, 32, 42, 1, 0, 0, 0, 33, 34, 3, 4, 2, 0, 34, 35, 5, 0, 0, 1, 35, 42, 1, 0, 0, 0, 36, 37, 3, 18, 9, 0, 37, 38, 5, 0, 0, 1, 38, 42, 1, 0, 0, 0, 39, 40, 5, 49, 0, 0, 40, 42, 5, 0, 0, 1, 41, 30, 1, 0, 0, 0, 41, 33, 1, 0, 0, 0, 41, 36, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 42, 1, 1, 0, 0, 0, 43, 44, 3, 22, 11, 0, 44, 45, 5, 31, 0, 0, 45, 46, 3, 18, 9, 0, 46, 51, 1, 0, 0, 0, 47, 48, 5, 49, 0, 0, 48, 49, 5, 31, 0, 0, 49, 51, 3, 8, 4, 0, 50, 43, 1, 0, 0, 0, 50, 47, 1, 0, 0, 0, 51, 3, 1, 0, 0, 0, 52, 53, 6, 2, -1, 0, 53, 54, 3, 10, 5, 0, 54, 55, 5, 31, 0, 0, 55, 56, 5, 31, 0, 0, 56, 57, 3, 10, 5, 0, 57, 92, 1, 0, 0, 0, 58, 59, 3, 10, 5, 0, 59, 60, 5, 32, 0, 0, 60, 61, 3, 10, 5, 0, 61, 92, 1, 0, 0, 0, 62, 63, 3, 10, 5, 0, 63, 64, 5, 33, 0, 0, 64, 65, 3, 10, 5, 0, 65, 92, 1, 0, 0, 0, 66, 71, 3, 10, 5, 0, 67, 68, 5, 32, 0, 0, 68, 72, 5, 31, 0, 0, 69, 70, 5, 31, 0, 0, 70, 72, 5, 32, 0, 0, 71, 67, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 74, 3, 10, 5, 0, 74, 92, 1, 0, 0, 0, 75, 80, 3, 10, 5, 0, 76, 77, 5, 33, 0, 0, 77, 81, 5, 31, 0, 0, 78, 79, 5, 31, 0, 0, 79, 81, 5, 33, 0, 0, 80, 76, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 83, 3, 10, 5, 0, 83, 92, 1, 0, 0, 0, 84, 85, 5, 30, 0, 0, 85, 92, 3, 4, 2, 3, 86, 87, 5, 42, 0, 0, 87, 88, 3, 4, 2, 0, 88, 89, 5, 43, 0, 0, 89, 92, 1, 0, 0, 0, 90, 92, 3, 6, 3, 0, 91, 52, 1, 0, 0, 0, 91, 58, 1, 0, 0, 0, 91, 62, 1, 0, 0, 0, 91, 66, 1, 0, 0, 0, 91, 75, 1, 0, 0, 0, 91, 84, 1, 0, 0, 0, 91, 86, 1, 0, 0, 0, 91, 90, 1, 0, 0, 0, 92, 98, 1, 0, 0, 0, 93, 94, 10, 4, 0, 0, 94, 95, 7, 0, 0, 0, 95, 97, 3, 4, 2, 5, 96, 93, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 5, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 102, 7, 1, 0, 0, 102, 7, 1, 0, 0, 0, 103, 104, 3, 20, 10, 0, 104, 105, 5, 34, 0, 0, 105, 106, 3, 18, 9, 0, 106, 112, 1, 0, 0, 0, 107, 108, 5, 42, 0, 0, 108, 109, 5, 43, 0, 0, 109, 110, 5, 34, 0, 0, 110, 112, 3, 18, 9, 0, 111, 103, 1, 0, 0, 0, 111, 107, 1, 0, 0, 0, 112, 9, 1, 0, 0, 0, 113, 114, 6, 5, -1, 0, 114, 115, 3, 26, 13, 0, 115, 116, 3, 10, 5, 9, 116, 132, 1, 0, 0, 0, 117, 118, 5, 42, 0, 0, 118, 119, 3, 10, 5, 0, 119, 120, 5, 43, 0, 0, 120, 132, 1, 0, 0, 0, 121, 122, 5, 49, 0, 0, 122, 124, 5, 42, 0, 0, 123, 125, 3, 16, 8, 0, 124, 123, 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 126, 1, 0, 0, 0, 126, 128, 5, 43, 0, 0, 127, 129, 3, 14, 7, 0, 128, 127, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 132, 1, 0, 0, 0, 130, 132, 3, 24, 12, 0, 131, 113, 1, 0, 0, 0, 131, 117, 1, 0, 0, 0, 131, 121, 1, 0, 0, 0, 131, 130, 1, 0, 0, 0, 132, 150, 1, 0, 0, 0, 133, 134, 10, 7, 0, 0, 134, 135, 5, 35, 0, 0, 135, 149, 3, 10, 5, 8, 136, 137, 10, 6, 0, 0, 137, 138, 5, 40, 0, 0, 138, 139, 5, 40, 0, 0, 139, 149, 3, 10, 5, 7, 140, 141, 10, 5, 0, 0, 141, 142, 7, 2, 0, 0, 142, 149, 3, 10, 5, 6, 143, 144, 10, 4, 0, 0, 144, 145, 7, 3, 0, 0, 145, 149, 3, 10, 5, 5, 146, 147, 10, 8, 0, 0, 147, 149, 5, 40, 0, 0, 148, 133, 1, 0, 0, 0, 148, 136, 1, 0, 0, 0, 148, 140, 1, 0, 0, 0, 148, 143, 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, 149, 152, 1, 0, 0, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 11, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 153, 154, 5, 48, 0, 0, 154, 157, 7, 4, 0, 0, 155, 158, 3, 4, 2, 0, 156, 158, 3, 10, 5, 0, 157, 155, 1, 0, 0, 0, 157, 156, 1, 0, 0, 0, 158, 13, 1, 0, 0, 0, 159, 168, 5, 44, 0, 0, 160, 165, 3, 12, 6, 0, 161, 162, 5, 4, 0, 0, 162, 164, 3, 12, 6, 0, 163, 161, 1, 0, 0, 0, 164, 167, 1, 0, 0, 0, 165, 163, 1, 0, 0, 0, 165, 166, 1, 0, 0, 0, 166, 169, 1, 0, 0, 0, 167, 165, 1, 0, 0, 0, 168, 160, 1, 0, 0, 0, 168, 169, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 171, 5, 45, 0, 0, 171, 15, 1, 0, 0, 0, 172, 175, 3, 10, 5, 0, 173, 175, 5, 49, 0, 0, 174, 172, 1, 0, 0, 0, 174, 173, 1, 0, 0, 0, 175, 178, 1, 0, 0, 0, 176, 177, 5, 4, 0, 0, 177, 179, 3, 16, 8, 0, 178, 176, 1, 0, 0, 0, 178, 179, 1, 0, 0, 0, 179, 17, 1, 0, 0, 0, 180, 183, 3, 10, 5, 0, 181, 182, 5, 4, 0, 0, 182, 184, 3, 18, 9, 0, 183, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 19, 1, 0, 0, 0, 185, 188, 7, 5, 0, 0, 186, 187, 5, 4, 0, 0, 187, 189, 3, 20, 10, 0, 188, 186, 1, 0, 0, 0, 188, 189, 1, 0, 0, 0, 189, 198, 1, 0, 0, 0, 190, 191, 5, 42, 0, 0, 191, 194, 7, 5, 0, 0, 192, 193, 5, 4, 0, 0, 193, 195, 3, 20, 10, 0, 194, 192, 1, 0, 0, 0, 194, 195, 1, 0, 0, 0, 195, 196, 1, 0, 0, 0, 196, 198, 5, 43, 0, 0, 197, 185, 1, 0, 0, 0, 197, 190, 1, 0, 0, 0, 198, 21, 1, 0, 0, 0, 199, 202, 5, 48, 0, 0, 200, 201, 5, 4, 0, 0, 201, 203, 3, 22, 11, 0, 202, 200, 1, 0, 0, 0, 202, 203, 1, 0, 0, 0, 203, 212, 1, 0, 0, 0, 204, 205, 5, 42, 0, 0, 205, 208, 5, 48, 0, 0, 206, 207, 5, 4, 0, 0, 207, 209, 3, 22, 11, 0, 208, 206, 1, 0, 0, 0, 208, 209, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, 212, 5, 43, 0, 0, 211, 199, 1, 0, 0, 0, 211, 204, 1, 0, 0, 0, 212, 23, 1, 0, 0, 0, 213, 218, 3, 28, 14, 0, 214, 218, 5, 46, 0, 0, 215, 218, 5, 47, 0, 0, 216, 218, 5, 48, 0, 0, 217, 213, 1, 0, 0, 0, 217, 214, 1, 0, 0, 0, 217, 215, 1, 0, 0, 0, 217, 216, 1, 0, 0, 0, 218, 25, 1, 0, 0, 0, 219, 222, 5, 38, 0, 0, 220, 222, 5, 39, 0, 0, 221, 219, 1, 0, 0, 0, 221, 220, 1, 0, 0, 0, 222, 27, 1, 0, 0, 0, 223, 224, 5, 5, 0, 0, 224, 225, 5, 42, 0, 0, 225, 226, 3, 10, 5, 0, 226, 227, 5, 43, 0, 0, 227, 352, 1, 0, 0, 0, 228, 229, 5, 6, 0, 0, 229, 230, 5, 42, 0, 0, 230, 231, 3, 10, 5, 0, 231, 232, 5, 43, 0, 0, 232, 352, 1, 0, 0, 0, 233, 234, 5, 7, 0, 0, 234, 235, 5, 42, 0, 0, 235, 236, 3, 10, 5, 0, 236, 237, 5, 43, 0, 0, 237, 352, 1, 0, 0, 0, 238, 239, 5, 8, 0, 0, 239, 240, 5, 42, 0, 0, 240, 241, 3, 10, 5, 0, 241, 242, 5, 43, 0, 0, 242, 352, 1, 0, 0, 0, 243, 244, 5, 9, 0, 0, 244, 245, 5, 42, 0, 0, 245, 246, 3, 10, 5, 0, 246, 247, 5, 43, 0, 0, 247, 352, 1, 0, 0, 0, 248, 249, 5, 10, 0, 0, 249, 250, 5, 42, 0, 0, 250, 251, 3, 10, 5, 0, 251, 252, 5, 43, 0, 0, 252, 352, 1, 0, 0, 0, 253, 254, 5, 11, 0, 0, 254, 255, 5, 42, 0, 0, 255, 256, 3, 10, 5, 0, 256, 257, 5, 43, 0, 0, 257, 352, 1, 0, 0, 0, 258, 259, 5, 12, 0, 0, 259, 260, 5, 42, 0, 0, 260, 261, 3, 10, 5, 0, 261, 262, 5, 43, 0, 0, 262, 352, 1, 0, 0, 0, 263, 264, 5, 13, 0, 0, 264, 265, 5, 42, 0, 0, 265, 266, 3, 10, 5, 0, 266, 267, 5, 43, 0, 0, 267, 352, 1, 0, 0, 0, 268, 269, 5, 14, 0, 0, 269, 270, 5, 42, 0, 0, 270, 271, 3, 10, 5, 0, 271, 272, 5, 43, 0, 0, 272, 352, 1, 0, 0, 0, 273, 274, 5, 15, 0, 0, 274, 275, 5, 42, 0, 0, 275, 276, 3, 10, 5, 0, 276, 277, 5, 43, 0, 0, 277, 352, 1, 0, 0, 0, 278, 279, 5, 16, 0, 0, 279, 280, 5, 42, 0, 0, 280, 281, 3, 10, 5, 0, 281, 282, 5, 43, 0, 0, 282, 352, 1, 0, 0, 0, 283, 284, 5, 17, 0, 0, 284, 285, 5, 42, 0, 0, 285, 286, 3, 10, 5, 0, 286, 287, 5, 43, 0, 0, 287, 352, 1, 0, 0, 0, 288, 289, 5, 18, 0, 0, 289, 290, 5, 42, 0, 0, 290, 291, 3, 10, 5, 0, 291, 292, 5, 43, 0, 0, 292, 352, 1, 0, 0, 0, 293, 294, 5, 19, 0, 0, 294, 295, 5, 42, 0, 0, 295, 296, 3, 10, 5, 0, 296, 297, 5, 43, 0, 0, 297, 352, 1, 0, 0, 0, 298, 299, 5, 17, 0, 0, 299, 300, 5, 42, 0, 0, 300, 301, 3, 10, 5, 0, 301, 302, 5, 4, 0, 0, 302, 303, 3, 10, 5, 0, 303, 304, 5, 43, 0, 0, 304, 352, 1, 0, 0, 0, 305, 306, 5, 8, 0, 0, 306, 307, 5, 42, 0, 0, 307, 308, 3, 10, 5, 0, 308, 309, 5, 4, 0, 0, 309, 310, 3, 10, 5, 0, 310, 311, 5, 43, 0, 0, 311, 352, 1, 0, 0, 0, 312, 313, 5, 20, 0, 0, 313, 314, 5, 42, 0, 0, 314, 315, 3, 18, 9, 0, 315, 316, 5, 43, 0, 0, 316, 352, 1, 0, 0, 0, 317, 318, 5, 21, 0, 0, 318, 319, 5, 42, 0, 0, 319, 320, 3, 18, 9, 0, 320, 321, 5, 43, 0, 0, 321, 352, 1, 0, 0, 0, 322, 323, 5, 22, 0, 0, 323, 324, 5, 42, 0, 0, 324, 325, 3, 18, 9, 0, 325, 326, 5, 43, 0, 0, 326, 352, 1, 0, 0, 0, 327, 328, 5, 23, 0, 0, 328, 329, 5, 42, 0, 0, 329, 330, 3, 18, 9, 0, 330, 331, 5, 4, 0, 0, 331, 332, 3, 10, 5, 0, 332, 333, 5, 43, 0, 0, 333, 352, 1, 0, 0, 0, 334, 335, 5, 24, 0, 0, 335, 336, 5, 42, 0, 0, 336, 337, 3, 18, 9, 0, 337, 338, 5, 43, 0, 0, 338, 352, 1, 0, 0, 0, 339, 340, 5, 25, 0, 0, 340, 341, 5, 42, 0, 0, 341, 342, 3, 18, 9, 0, 342, 343, 5, 43, 0, 0, 343, 352, 1, 0, 0, 0, 344, 345, 5, 26, 0, 0, 345, 346, 5, 42, 0, 0, 346, 347, 3, 18, 9, 0, 347, 348, 5, 4, 0, 0, 348, 349, 3, 10, 5, 0, 349, 350, 5, 43, 0, 0, 350, 352, 1, 0, 0, 0, 351, 223, 1, 0, 0, 0, 351, 228, 1, 0, 0, 0, 351, 233, 1, 0, 0, 0, 351, 238, 1, 0, 0, 0, 351, 243, 1, 0, 0, 0, 351, 248, 1, 0, 0, 0, 351, 253, 1, 0, 0, 0, 351, 258, 1, 0, 0, 0, 351, 263, 1, 0, 0, 0, 351, 268, 1, 0, 0, 0, 351, 273, 1, 0, 0, 0, 351, 278, 1, 0, 0, 0, 351, 283, 1, 0, 0, 0, 351, 288, 1, 0, 0, 0, 351, 293, 1, 0, 0, 0, 351, 298, 1, 0, 0, 0, 351, 305, 1, 0, 0, 0, 351, 312, 1, 0, 0, 0, 351, 317, 1, 0, 0, 0, 351, 322, 1, 0, 0, 0, 351, 327, 1, 0, 0, 0, 351, 334, 1, 0, 0, 0, 351, 339, 1, 0, 0, 0, 351, 344, 1, 0, 0, 0, 352, 29, 1, 0, 0, 0, 27, 41, 50, 71, 80, 91, 98, 111, 124, 128, 131, 148, 150, 157, 165, 168, 174, 178, 183, 188, 194, 197, 202, 208, 211, 217, 221, 351] \ No newline at end of file +[4, 1, 31, 229, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 42, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 51, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 72, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 81, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 92, 8, 2, 1, 2, 1, 2, 1, 2, 5, 2, 97, 8, 2, 10, 2, 12, 2, 100, 9, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 112, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 125, 8, 5, 1, 5, 1, 5, 3, 5, 129, 8, 5, 1, 5, 3, 5, 132, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 149, 8, 5, 10, 5, 12, 5, 152, 9, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 158, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 164, 8, 7, 10, 7, 12, 7, 167, 9, 7, 3, 7, 169, 8, 7, 1, 7, 1, 7, 1, 8, 1, 8, 3, 8, 175, 8, 8, 1, 8, 1, 8, 3, 8, 179, 8, 8, 1, 9, 1, 9, 1, 9, 3, 9, 184, 8, 9, 1, 10, 1, 10, 1, 10, 3, 10, 189, 8, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 195, 8, 10, 1, 10, 3, 10, 198, 8, 10, 1, 11, 1, 11, 1, 11, 3, 11, 203, 8, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 209, 8, 11, 1, 11, 3, 11, 212, 8, 11, 1, 12, 1, 12, 1, 12, 1, 12, 3, 12, 218, 8, 12, 1, 13, 1, 13, 3, 13, 222, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 0, 2, 4, 10, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 0, 6, 1, 0, 5, 7, 1, 0, 1, 2, 1, 0, 14, 15, 1, 0, 16, 17, 2, 0, 3, 3, 9, 9, 1, 0, 26, 27, 254, 0, 41, 1, 0, 0, 0, 2, 50, 1, 0, 0, 0, 4, 91, 1, 0, 0, 0, 6, 101, 1, 0, 0, 0, 8, 111, 1, 0, 0, 0, 10, 131, 1, 0, 0, 0, 12, 153, 1, 0, 0, 0, 14, 159, 1, 0, 0, 0, 16, 174, 1, 0, 0, 0, 18, 180, 1, 0, 0, 0, 20, 197, 1, 0, 0, 0, 22, 211, 1, 0, 0, 0, 24, 217, 1, 0, 0, 0, 26, 221, 1, 0, 0, 0, 28, 223, 1, 0, 0, 0, 30, 31, 3, 2, 1, 0, 31, 32, 5, 0, 0, 1, 32, 42, 1, 0, 0, 0, 33, 34, 3, 4, 2, 0, 34, 35, 5, 0, 0, 1, 35, 42, 1, 0, 0, 0, 36, 37, 3, 18, 9, 0, 37, 38, 5, 0, 0, 1, 38, 42, 1, 0, 0, 0, 39, 40, 5, 27, 0, 0, 40, 42, 5, 0, 0, 1, 41, 30, 1, 0, 0, 0, 41, 33, 1, 0, 0, 0, 41, 36, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 42, 1, 1, 0, 0, 0, 43, 44, 3, 22, 11, 0, 44, 45, 5, 9, 0, 0, 45, 46, 3, 18, 9, 0, 46, 51, 1, 0, 0, 0, 47, 48, 5, 27, 0, 0, 48, 49, 5, 9, 0, 0, 49, 51, 3, 8, 4, 0, 50, 43, 1, 0, 0, 0, 50, 47, 1, 0, 0, 0, 51, 3, 1, 0, 0, 0, 52, 53, 6, 2, -1, 0, 53, 54, 3, 10, 5, 0, 54, 55, 5, 9, 0, 0, 55, 56, 5, 9, 0, 0, 56, 57, 3, 10, 5, 0, 57, 92, 1, 0, 0, 0, 58, 59, 3, 10, 5, 0, 59, 60, 5, 10, 0, 0, 60, 61, 3, 10, 5, 0, 61, 92, 1, 0, 0, 0, 62, 63, 3, 10, 5, 0, 63, 64, 5, 11, 0, 0, 64, 65, 3, 10, 5, 0, 65, 92, 1, 0, 0, 0, 66, 71, 3, 10, 5, 0, 67, 68, 5, 10, 0, 0, 68, 72, 5, 9, 0, 0, 69, 70, 5, 9, 0, 0, 70, 72, 5, 10, 0, 0, 71, 67, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 74, 3, 10, 5, 0, 74, 92, 1, 0, 0, 0, 75, 80, 3, 10, 5, 0, 76, 77, 5, 11, 0, 0, 77, 81, 5, 9, 0, 0, 78, 79, 5, 9, 0, 0, 79, 81, 5, 11, 0, 0, 80, 76, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 83, 3, 10, 5, 0, 83, 92, 1, 0, 0, 0, 84, 85, 5, 8, 0, 0, 85, 92, 3, 4, 2, 3, 86, 87, 5, 20, 0, 0, 87, 88, 3, 4, 2, 0, 88, 89, 5, 21, 0, 0, 89, 92, 1, 0, 0, 0, 90, 92, 3, 6, 3, 0, 91, 52, 1, 0, 0, 0, 91, 58, 1, 0, 0, 0, 91, 62, 1, 0, 0, 0, 91, 66, 1, 0, 0, 0, 91, 75, 1, 0, 0, 0, 91, 84, 1, 0, 0, 0, 91, 86, 1, 0, 0, 0, 91, 90, 1, 0, 0, 0, 92, 98, 1, 0, 0, 0, 93, 94, 10, 4, 0, 0, 94, 95, 7, 0, 0, 0, 95, 97, 3, 4, 2, 5, 96, 93, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 5, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 102, 7, 1, 0, 0, 102, 7, 1, 0, 0, 0, 103, 104, 3, 20, 10, 0, 104, 105, 5, 12, 0, 0, 105, 106, 3, 18, 9, 0, 106, 112, 1, 0, 0, 0, 107, 108, 5, 20, 0, 0, 108, 109, 5, 21, 0, 0, 109, 110, 5, 12, 0, 0, 110, 112, 3, 18, 9, 0, 111, 103, 1, 0, 0, 0, 111, 107, 1, 0, 0, 0, 112, 9, 1, 0, 0, 0, 113, 114, 6, 5, -1, 0, 114, 115, 3, 26, 13, 0, 115, 116, 3, 10, 5, 9, 116, 132, 1, 0, 0, 0, 117, 118, 5, 20, 0, 0, 118, 119, 3, 10, 5, 0, 119, 120, 5, 21, 0, 0, 120, 132, 1, 0, 0, 0, 121, 122, 5, 27, 0, 0, 122, 124, 5, 20, 0, 0, 123, 125, 3, 16, 8, 0, 124, 123, 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 126, 1, 0, 0, 0, 126, 128, 5, 21, 0, 0, 127, 129, 3, 14, 7, 0, 128, 127, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 132, 1, 0, 0, 0, 130, 132, 3, 24, 12, 0, 131, 113, 1, 0, 0, 0, 131, 117, 1, 0, 0, 0, 131, 121, 1, 0, 0, 0, 131, 130, 1, 0, 0, 0, 132, 150, 1, 0, 0, 0, 133, 134, 10, 7, 0, 0, 134, 135, 5, 13, 0, 0, 135, 149, 3, 10, 5, 8, 136, 137, 10, 6, 0, 0, 137, 138, 5, 18, 0, 0, 138, 139, 5, 18, 0, 0, 139, 149, 3, 10, 5, 7, 140, 141, 10, 5, 0, 0, 141, 142, 7, 2, 0, 0, 142, 149, 3, 10, 5, 6, 143, 144, 10, 4, 0, 0, 144, 145, 7, 3, 0, 0, 145, 149, 3, 10, 5, 5, 146, 147, 10, 8, 0, 0, 147, 149, 5, 18, 0, 0, 148, 133, 1, 0, 0, 0, 148, 136, 1, 0, 0, 0, 148, 140, 1, 0, 0, 0, 148, 143, 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, 149, 152, 1, 0, 0, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 11, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 153, 154, 5, 26, 0, 0, 154, 157, 7, 4, 0, 0, 155, 158, 3, 4, 2, 0, 156, 158, 3, 10, 5, 0, 157, 155, 1, 0, 0, 0, 157, 156, 1, 0, 0, 0, 158, 13, 1, 0, 0, 0, 159, 168, 5, 22, 0, 0, 160, 165, 3, 12, 6, 0, 161, 162, 5, 4, 0, 0, 162, 164, 3, 12, 6, 0, 163, 161, 1, 0, 0, 0, 164, 167, 1, 0, 0, 0, 165, 163, 1, 0, 0, 0, 165, 166, 1, 0, 0, 0, 166, 169, 1, 0, 0, 0, 167, 165, 1, 0, 0, 0, 168, 160, 1, 0, 0, 0, 168, 169, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 171, 5, 23, 0, 0, 171, 15, 1, 0, 0, 0, 172, 175, 3, 10, 5, 0, 173, 175, 5, 27, 0, 0, 174, 172, 1, 0, 0, 0, 174, 173, 1, 0, 0, 0, 175, 178, 1, 0, 0, 0, 176, 177, 5, 4, 0, 0, 177, 179, 3, 16, 8, 0, 178, 176, 1, 0, 0, 0, 178, 179, 1, 0, 0, 0, 179, 17, 1, 0, 0, 0, 180, 183, 3, 10, 5, 0, 181, 182, 5, 4, 0, 0, 182, 184, 3, 18, 9, 0, 183, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 19, 1, 0, 0, 0, 185, 188, 7, 5, 0, 0, 186, 187, 5, 4, 0, 0, 187, 189, 3, 20, 10, 0, 188, 186, 1, 0, 0, 0, 188, 189, 1, 0, 0, 0, 189, 198, 1, 0, 0, 0, 190, 191, 5, 20, 0, 0, 191, 194, 7, 5, 0, 0, 192, 193, 5, 4, 0, 0, 193, 195, 3, 20, 10, 0, 194, 192, 1, 0, 0, 0, 194, 195, 1, 0, 0, 0, 195, 196, 1, 0, 0, 0, 196, 198, 5, 21, 0, 0, 197, 185, 1, 0, 0, 0, 197, 190, 1, 0, 0, 0, 198, 21, 1, 0, 0, 0, 199, 202, 5, 26, 0, 0, 200, 201, 5, 4, 0, 0, 201, 203, 3, 22, 11, 0, 202, 200, 1, 0, 0, 0, 202, 203, 1, 0, 0, 0, 203, 212, 1, 0, 0, 0, 204, 205, 5, 20, 0, 0, 205, 208, 5, 26, 0, 0, 206, 207, 5, 4, 0, 0, 207, 209, 3, 22, 11, 0, 208, 206, 1, 0, 0, 0, 208, 209, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, 212, 5, 21, 0, 0, 211, 199, 1, 0, 0, 0, 211, 204, 1, 0, 0, 0, 212, 23, 1, 0, 0, 0, 213, 218, 3, 28, 14, 0, 214, 218, 5, 24, 0, 0, 215, 218, 5, 25, 0, 0, 216, 218, 5, 26, 0, 0, 217, 213, 1, 0, 0, 0, 217, 214, 1, 0, 0, 0, 217, 215, 1, 0, 0, 0, 217, 216, 1, 0, 0, 0, 218, 25, 1, 0, 0, 0, 219, 222, 5, 16, 0, 0, 220, 222, 5, 17, 0, 0, 221, 219, 1, 0, 0, 0, 221, 220, 1, 0, 0, 0, 222, 27, 1, 0, 0, 0, 223, 224, 5, 26, 0, 0, 224, 225, 5, 20, 0, 0, 225, 226, 3, 18, 9, 0, 226, 227, 5, 21, 0, 0, 227, 29, 1, 0, 0, 0, 26, 41, 50, 71, 80, 91, 98, 111, 124, 128, 131, 148, 150, 157, 165, 168, 174, 178, 183, 188, 194, 197, 202, 208, 211, 217, 221] \ No newline at end of file diff --git a/parser/Abacus.tokens b/parser/Abacus.tokens index 24ebf3e..359c0a6 100644 --- a/parser/Abacus.tokens +++ b/parser/Abacus.tokens @@ -2,94 +2,50 @@ T__0=1 T__1=2 T__2=3 T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -AND=27 -OR=28 -XOR=29 -NOT=30 -EQ=31 -LS=32 -GR=33 -ARROW=34 -POW=35 -MUL=36 -DIV=37 -ADD=38 -SUB=39 -PER=40 -POINT=41 -LPAREN=42 -RPAREN=43 -LSQPAREN=44 -RSQPAREN=45 -CONSTANT=46 -SCIENTIFIC_NUMBER=47 -VARIABLE=48 -LAMBDA_VARIABLE=49 -DIGITS=50 -UPPERCASE=51 -LOWERCASE=52 -WHITESPACE=53 +AND=5 +OR=6 +XOR=7 +NOT=8 +EQ=9 +LS=10 +GR=11 +ARROW=12 +POW=13 +MUL=14 +DIV=15 +ADD=16 +SUB=17 +PER=18 +POINT=19 +LPAREN=20 +RPAREN=21 +LSQPAREN=22 +RSQPAREN=23 +CONSTANT=24 +SCIENTIFIC_NUMBER=25 +VARIABLE=26 +LAMBDA_VARIABLE=27 +DIGITS=28 +UPPERCASE=29 +LOWERCASE=30 +WHITESPACE=31 'true'=1 'false'=2 ':'=3 ','=4 -'sqrt'=5 -'cbrt'=6 -'ln'=7 -'log'=8 -'log2'=9 -'log10'=10 -'floor'=11 -'ceil'=12 -'exp'=13 -'sin'=14 -'cos'=15 -'tan'=16 -'round'=17 -'sign'=18 -'abs'=19 -'min'=20 -'max'=21 -'avg'=22 -'until'=23 -'from'=24 -'reverse'=25 -'nth'=26 -'&&'=27 -'||'=28 -'xor'=29 -'='=31 -'<'=32 -'>'=33 -'*'=36 -'/'=37 -'+'=38 -'-'=39 -'%'=40 -'.'=41 -'('=42 -')'=43 -'['=44 -']'=45 +'&&'=5 +'||'=6 +'xor'=7 +'='=9 +'<'=10 +'>'=11 +'*'=14 +'/'=15 +'+'=16 +'-'=17 +'%'=18 +'.'=19 +'('=20 +')'=21 +'['=22 +']'=23 diff --git a/parser/AbacusLexer.interp b/parser/AbacusLexer.interp index 4169c41..aa14902 100644 --- a/parser/AbacusLexer.interp +++ b/parser/AbacusLexer.interp @@ -4,28 +4,6 @@ null 'false' ':' ',' -'sqrt' -'cbrt' -'ln' -'log' -'log2' -'log10' -'floor' -'ceil' -'exp' -'sin' -'cos' -'tan' -'round' -'sign' -'abs' -'min' -'max' -'avg' -'until' -'from' -'reverse' -'nth' '&&' '||' 'xor' @@ -60,28 +38,6 @@ null null null null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null AND OR XOR @@ -115,28 +71,6 @@ T__0 T__1 T__2 T__3 -T__4 -T__5 -T__6 -T__7 -T__8 -T__9 -T__10 -T__11 -T__12 -T__13 -T__14 -T__15 -T__16 -T__17 -T__18 -T__19 -T__20 -T__21 -T__22 -T__23 -T__24 -T__25 AND OR XOR @@ -177,4 +111,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 53, 351, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 33, 3, 33, 258, 8, 33, 1, 34, 1, 34, 1, 34, 3, 34, 263, 8, 34, 1, 35, 1, 35, 1, 36, 1, 36, 1, 37, 1, 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 40, 1, 40, 1, 41, 1, 41, 1, 42, 1, 42, 1, 43, 1, 43, 1, 44, 1, 44, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 3, 45, 291, 8, 45, 1, 46, 1, 46, 1, 46, 3, 46, 296, 8, 46, 1, 46, 3, 46, 299, 8, 46, 1, 47, 1, 47, 1, 48, 4, 48, 304, 8, 48, 11, 48, 12, 48, 305, 1, 48, 1, 48, 4, 48, 310, 8, 48, 11, 48, 12, 48, 311, 3, 48, 314, 8, 48, 1, 49, 1, 49, 5, 49, 318, 8, 49, 10, 49, 12, 49, 321, 9, 49, 1, 50, 1, 50, 5, 50, 325, 8, 50, 10, 50, 12, 50, 328, 9, 50, 1, 51, 1, 51, 3, 51, 332, 8, 51, 1, 52, 1, 52, 1, 52, 3, 52, 337, 8, 52, 1, 53, 1, 53, 1, 54, 1, 54, 1, 55, 1, 55, 1, 56, 4, 56, 346, 8, 56, 11, 56, 12, 56, 347, 1, 56, 1, 56, 0, 0, 57, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 35, 71, 36, 73, 37, 75, 38, 77, 39, 79, 40, 81, 41, 83, 42, 85, 43, 87, 44, 89, 45, 91, 46, 93, 47, 95, 0, 97, 0, 99, 48, 101, 49, 103, 0, 105, 0, 107, 50, 109, 51, 111, 52, 113, 53, 1, 0, 4, 3, 0, 33, 33, 126, 126, 172, 172, 2, 0, 69, 69, 101, 101, 2, 0, 43, 43, 45, 45, 3, 0, 9, 10, 13, 13, 32, 32, 361, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, 0, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 99, 1, 0, 0, 0, 0, 101, 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 1, 115, 1, 0, 0, 0, 3, 120, 1, 0, 0, 0, 5, 126, 1, 0, 0, 0, 7, 128, 1, 0, 0, 0, 9, 130, 1, 0, 0, 0, 11, 135, 1, 0, 0, 0, 13, 140, 1, 0, 0, 0, 15, 143, 1, 0, 0, 0, 17, 147, 1, 0, 0, 0, 19, 152, 1, 0, 0, 0, 21, 158, 1, 0, 0, 0, 23, 164, 1, 0, 0, 0, 25, 169, 1, 0, 0, 0, 27, 173, 1, 0, 0, 0, 29, 177, 1, 0, 0, 0, 31, 181, 1, 0, 0, 0, 33, 185, 1, 0, 0, 0, 35, 191, 1, 0, 0, 0, 37, 196, 1, 0, 0, 0, 39, 200, 1, 0, 0, 0, 41, 204, 1, 0, 0, 0, 43, 208, 1, 0, 0, 0, 45, 212, 1, 0, 0, 0, 47, 218, 1, 0, 0, 0, 49, 223, 1, 0, 0, 0, 51, 231, 1, 0, 0, 0, 53, 235, 1, 0, 0, 0, 55, 238, 1, 0, 0, 0, 57, 241, 1, 0, 0, 0, 59, 245, 1, 0, 0, 0, 61, 247, 1, 0, 0, 0, 63, 249, 1, 0, 0, 0, 65, 251, 1, 0, 0, 0, 67, 257, 1, 0, 0, 0, 69, 262, 1, 0, 0, 0, 71, 264, 1, 0, 0, 0, 73, 266, 1, 0, 0, 0, 75, 268, 1, 0, 0, 0, 77, 270, 1, 0, 0, 0, 79, 272, 1, 0, 0, 0, 81, 274, 1, 0, 0, 0, 83, 276, 1, 0, 0, 0, 85, 278, 1, 0, 0, 0, 87, 280, 1, 0, 0, 0, 89, 282, 1, 0, 0, 0, 91, 290, 1, 0, 0, 0, 93, 292, 1, 0, 0, 0, 95, 300, 1, 0, 0, 0, 97, 303, 1, 0, 0, 0, 99, 315, 1, 0, 0, 0, 101, 322, 1, 0, 0, 0, 103, 331, 1, 0, 0, 0, 105, 336, 1, 0, 0, 0, 107, 338, 1, 0, 0, 0, 109, 340, 1, 0, 0, 0, 111, 342, 1, 0, 0, 0, 113, 345, 1, 0, 0, 0, 115, 116, 5, 116, 0, 0, 116, 117, 5, 114, 0, 0, 117, 118, 5, 117, 0, 0, 118, 119, 5, 101, 0, 0, 119, 2, 1, 0, 0, 0, 120, 121, 5, 102, 0, 0, 121, 122, 5, 97, 0, 0, 122, 123, 5, 108, 0, 0, 123, 124, 5, 115, 0, 0, 124, 125, 5, 101, 0, 0, 125, 4, 1, 0, 0, 0, 126, 127, 5, 58, 0, 0, 127, 6, 1, 0, 0, 0, 128, 129, 5, 44, 0, 0, 129, 8, 1, 0, 0, 0, 130, 131, 5, 115, 0, 0, 131, 132, 5, 113, 0, 0, 132, 133, 5, 114, 0, 0, 133, 134, 5, 116, 0, 0, 134, 10, 1, 0, 0, 0, 135, 136, 5, 99, 0, 0, 136, 137, 5, 98, 0, 0, 137, 138, 5, 114, 0, 0, 138, 139, 5, 116, 0, 0, 139, 12, 1, 0, 0, 0, 140, 141, 5, 108, 0, 0, 141, 142, 5, 110, 0, 0, 142, 14, 1, 0, 0, 0, 143, 144, 5, 108, 0, 0, 144, 145, 5, 111, 0, 0, 145, 146, 5, 103, 0, 0, 146, 16, 1, 0, 0, 0, 147, 148, 5, 108, 0, 0, 148, 149, 5, 111, 0, 0, 149, 150, 5, 103, 0, 0, 150, 151, 5, 50, 0, 0, 151, 18, 1, 0, 0, 0, 152, 153, 5, 108, 0, 0, 153, 154, 5, 111, 0, 0, 154, 155, 5, 103, 0, 0, 155, 156, 5, 49, 0, 0, 156, 157, 5, 48, 0, 0, 157, 20, 1, 0, 0, 0, 158, 159, 5, 102, 0, 0, 159, 160, 5, 108, 0, 0, 160, 161, 5, 111, 0, 0, 161, 162, 5, 111, 0, 0, 162, 163, 5, 114, 0, 0, 163, 22, 1, 0, 0, 0, 164, 165, 5, 99, 0, 0, 165, 166, 5, 101, 0, 0, 166, 167, 5, 105, 0, 0, 167, 168, 5, 108, 0, 0, 168, 24, 1, 0, 0, 0, 169, 170, 5, 101, 0, 0, 170, 171, 5, 120, 0, 0, 171, 172, 5, 112, 0, 0, 172, 26, 1, 0, 0, 0, 173, 174, 5, 115, 0, 0, 174, 175, 5, 105, 0, 0, 175, 176, 5, 110, 0, 0, 176, 28, 1, 0, 0, 0, 177, 178, 5, 99, 0, 0, 178, 179, 5, 111, 0, 0, 179, 180, 5, 115, 0, 0, 180, 30, 1, 0, 0, 0, 181, 182, 5, 116, 0, 0, 182, 183, 5, 97, 0, 0, 183, 184, 5, 110, 0, 0, 184, 32, 1, 0, 0, 0, 185, 186, 5, 114, 0, 0, 186, 187, 5, 111, 0, 0, 187, 188, 5, 117, 0, 0, 188, 189, 5, 110, 0, 0, 189, 190, 5, 100, 0, 0, 190, 34, 1, 0, 0, 0, 191, 192, 5, 115, 0, 0, 192, 193, 5, 105, 0, 0, 193, 194, 5, 103, 0, 0, 194, 195, 5, 110, 0, 0, 195, 36, 1, 0, 0, 0, 196, 197, 5, 97, 0, 0, 197, 198, 5, 98, 0, 0, 198, 199, 5, 115, 0, 0, 199, 38, 1, 0, 0, 0, 200, 201, 5, 109, 0, 0, 201, 202, 5, 105, 0, 0, 202, 203, 5, 110, 0, 0, 203, 40, 1, 0, 0, 0, 204, 205, 5, 109, 0, 0, 205, 206, 5, 97, 0, 0, 206, 207, 5, 120, 0, 0, 207, 42, 1, 0, 0, 0, 208, 209, 5, 97, 0, 0, 209, 210, 5, 118, 0, 0, 210, 211, 5, 103, 0, 0, 211, 44, 1, 0, 0, 0, 212, 213, 5, 117, 0, 0, 213, 214, 5, 110, 0, 0, 214, 215, 5, 116, 0, 0, 215, 216, 5, 105, 0, 0, 216, 217, 5, 108, 0, 0, 217, 46, 1, 0, 0, 0, 218, 219, 5, 102, 0, 0, 219, 220, 5, 114, 0, 0, 220, 221, 5, 111, 0, 0, 221, 222, 5, 109, 0, 0, 222, 48, 1, 0, 0, 0, 223, 224, 5, 114, 0, 0, 224, 225, 5, 101, 0, 0, 225, 226, 5, 118, 0, 0, 226, 227, 5, 101, 0, 0, 227, 228, 5, 114, 0, 0, 228, 229, 5, 115, 0, 0, 229, 230, 5, 101, 0, 0, 230, 50, 1, 0, 0, 0, 231, 232, 5, 110, 0, 0, 232, 233, 5, 116, 0, 0, 233, 234, 5, 104, 0, 0, 234, 52, 1, 0, 0, 0, 235, 236, 5, 38, 0, 0, 236, 237, 5, 38, 0, 0, 237, 54, 1, 0, 0, 0, 238, 239, 5, 124, 0, 0, 239, 240, 5, 124, 0, 0, 240, 56, 1, 0, 0, 0, 241, 242, 5, 120, 0, 0, 242, 243, 5, 111, 0, 0, 243, 244, 5, 114, 0, 0, 244, 58, 1, 0, 0, 0, 245, 246, 7, 0, 0, 0, 246, 60, 1, 0, 0, 0, 247, 248, 5, 61, 0, 0, 248, 62, 1, 0, 0, 0, 249, 250, 5, 60, 0, 0, 250, 64, 1, 0, 0, 0, 251, 252, 5, 62, 0, 0, 252, 66, 1, 0, 0, 0, 253, 254, 5, 45, 0, 0, 254, 258, 5, 62, 0, 0, 255, 256, 5, 61, 0, 0, 256, 258, 5, 62, 0, 0, 257, 253, 1, 0, 0, 0, 257, 255, 1, 0, 0, 0, 258, 68, 1, 0, 0, 0, 259, 263, 5, 94, 0, 0, 260, 261, 5, 42, 0, 0, 261, 263, 5, 42, 0, 0, 262, 259, 1, 0, 0, 0, 262, 260, 1, 0, 0, 0, 263, 70, 1, 0, 0, 0, 264, 265, 5, 42, 0, 0, 265, 72, 1, 0, 0, 0, 266, 267, 5, 47, 0, 0, 267, 74, 1, 0, 0, 0, 268, 269, 5, 43, 0, 0, 269, 76, 1, 0, 0, 0, 270, 271, 5, 45, 0, 0, 271, 78, 1, 0, 0, 0, 272, 273, 5, 37, 0, 0, 273, 80, 1, 0, 0, 0, 274, 275, 5, 46, 0, 0, 275, 82, 1, 0, 0, 0, 276, 277, 5, 40, 0, 0, 277, 84, 1, 0, 0, 0, 278, 279, 5, 41, 0, 0, 279, 86, 1, 0, 0, 0, 280, 281, 5, 91, 0, 0, 281, 88, 1, 0, 0, 0, 282, 283, 5, 93, 0, 0, 283, 90, 1, 0, 0, 0, 284, 285, 5, 112, 0, 0, 285, 291, 5, 105, 0, 0, 286, 291, 5, 101, 0, 0, 287, 288, 5, 112, 0, 0, 288, 289, 5, 104, 0, 0, 289, 291, 5, 105, 0, 0, 290, 284, 1, 0, 0, 0, 290, 286, 1, 0, 0, 0, 290, 287, 1, 0, 0, 0, 291, 92, 1, 0, 0, 0, 292, 298, 3, 97, 48, 0, 293, 295, 7, 1, 0, 0, 294, 296, 3, 95, 47, 0, 295, 294, 1, 0, 0, 0, 295, 296, 1, 0, 0, 0, 296, 297, 1, 0, 0, 0, 297, 299, 3, 97, 48, 0, 298, 293, 1, 0, 0, 0, 298, 299, 1, 0, 0, 0, 299, 94, 1, 0, 0, 0, 300, 301, 7, 2, 0, 0, 301, 96, 1, 0, 0, 0, 302, 304, 3, 107, 53, 0, 303, 302, 1, 0, 0, 0, 304, 305, 1, 0, 0, 0, 305, 303, 1, 0, 0, 0, 305, 306, 1, 0, 0, 0, 306, 313, 1, 0, 0, 0, 307, 309, 3, 81, 40, 0, 308, 310, 3, 107, 53, 0, 309, 308, 1, 0, 0, 0, 310, 311, 1, 0, 0, 0, 311, 309, 1, 0, 0, 0, 311, 312, 1, 0, 0, 0, 312, 314, 1, 0, 0, 0, 313, 307, 1, 0, 0, 0, 313, 314, 1, 0, 0, 0, 314, 98, 1, 0, 0, 0, 315, 319, 3, 103, 51, 0, 316, 318, 3, 105, 52, 0, 317, 316, 1, 0, 0, 0, 318, 321, 1, 0, 0, 0, 319, 317, 1, 0, 0, 0, 319, 320, 1, 0, 0, 0, 320, 100, 1, 0, 0, 0, 321, 319, 1, 0, 0, 0, 322, 326, 3, 109, 54, 0, 323, 325, 3, 105, 52, 0, 324, 323, 1, 0, 0, 0, 325, 328, 1, 0, 0, 0, 326, 324, 1, 0, 0, 0, 326, 327, 1, 0, 0, 0, 327, 102, 1, 0, 0, 0, 328, 326, 1, 0, 0, 0, 329, 332, 3, 111, 55, 0, 330, 332, 5, 95, 0, 0, 331, 329, 1, 0, 0, 0, 331, 330, 1, 0, 0, 0, 332, 104, 1, 0, 0, 0, 333, 337, 3, 103, 51, 0, 334, 337, 3, 109, 54, 0, 335, 337, 3, 107, 53, 0, 336, 333, 1, 0, 0, 0, 336, 334, 1, 0, 0, 0, 336, 335, 1, 0, 0, 0, 337, 106, 1, 0, 0, 0, 338, 339, 2, 48, 57, 0, 339, 108, 1, 0, 0, 0, 340, 341, 2, 65, 90, 0, 341, 110, 1, 0, 0, 0, 342, 343, 2, 97, 122, 0, 343, 112, 1, 0, 0, 0, 344, 346, 7, 3, 0, 0, 345, 344, 1, 0, 0, 0, 346, 347, 1, 0, 0, 0, 347, 345, 1, 0, 0, 0, 347, 348, 1, 0, 0, 0, 348, 349, 1, 0, 0, 0, 349, 350, 6, 56, 0, 0, 350, 114, 1, 0, 0, 0, 14, 0, 257, 262, 290, 295, 298, 305, 311, 313, 319, 326, 331, 336, 347, 1, 6, 0, 0] \ No newline at end of file +[4, 0, 31, 202, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 109, 8, 11, 1, 12, 1, 12, 1, 12, 3, 12, 114, 8, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 3, 23, 142, 8, 23, 1, 24, 1, 24, 1, 24, 3, 24, 147, 8, 24, 1, 24, 3, 24, 150, 8, 24, 1, 25, 1, 25, 1, 26, 4, 26, 155, 8, 26, 11, 26, 12, 26, 156, 1, 26, 1, 26, 4, 26, 161, 8, 26, 11, 26, 12, 26, 162, 3, 26, 165, 8, 26, 1, 27, 1, 27, 5, 27, 169, 8, 27, 10, 27, 12, 27, 172, 9, 27, 1, 28, 1, 28, 5, 28, 176, 8, 28, 10, 28, 12, 28, 179, 9, 28, 1, 29, 1, 29, 3, 29, 183, 8, 29, 1, 30, 1, 30, 1, 30, 3, 30, 188, 8, 30, 1, 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 4, 34, 197, 8, 34, 11, 34, 12, 34, 198, 1, 34, 1, 34, 0, 0, 35, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 0, 53, 0, 55, 26, 57, 27, 59, 0, 61, 0, 63, 28, 65, 29, 67, 30, 69, 31, 1, 0, 4, 3, 0, 33, 33, 126, 126, 172, 172, 2, 0, 69, 69, 101, 101, 2, 0, 43, 43, 45, 45, 3, 0, 9, 10, 13, 13, 32, 32, 212, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 1, 71, 1, 0, 0, 0, 3, 76, 1, 0, 0, 0, 5, 82, 1, 0, 0, 0, 7, 84, 1, 0, 0, 0, 9, 86, 1, 0, 0, 0, 11, 89, 1, 0, 0, 0, 13, 92, 1, 0, 0, 0, 15, 96, 1, 0, 0, 0, 17, 98, 1, 0, 0, 0, 19, 100, 1, 0, 0, 0, 21, 102, 1, 0, 0, 0, 23, 108, 1, 0, 0, 0, 25, 113, 1, 0, 0, 0, 27, 115, 1, 0, 0, 0, 29, 117, 1, 0, 0, 0, 31, 119, 1, 0, 0, 0, 33, 121, 1, 0, 0, 0, 35, 123, 1, 0, 0, 0, 37, 125, 1, 0, 0, 0, 39, 127, 1, 0, 0, 0, 41, 129, 1, 0, 0, 0, 43, 131, 1, 0, 0, 0, 45, 133, 1, 0, 0, 0, 47, 141, 1, 0, 0, 0, 49, 143, 1, 0, 0, 0, 51, 151, 1, 0, 0, 0, 53, 154, 1, 0, 0, 0, 55, 166, 1, 0, 0, 0, 57, 173, 1, 0, 0, 0, 59, 182, 1, 0, 0, 0, 61, 187, 1, 0, 0, 0, 63, 189, 1, 0, 0, 0, 65, 191, 1, 0, 0, 0, 67, 193, 1, 0, 0, 0, 69, 196, 1, 0, 0, 0, 71, 72, 5, 116, 0, 0, 72, 73, 5, 114, 0, 0, 73, 74, 5, 117, 0, 0, 74, 75, 5, 101, 0, 0, 75, 2, 1, 0, 0, 0, 76, 77, 5, 102, 0, 0, 77, 78, 5, 97, 0, 0, 78, 79, 5, 108, 0, 0, 79, 80, 5, 115, 0, 0, 80, 81, 5, 101, 0, 0, 81, 4, 1, 0, 0, 0, 82, 83, 5, 58, 0, 0, 83, 6, 1, 0, 0, 0, 84, 85, 5, 44, 0, 0, 85, 8, 1, 0, 0, 0, 86, 87, 5, 38, 0, 0, 87, 88, 5, 38, 0, 0, 88, 10, 1, 0, 0, 0, 89, 90, 5, 124, 0, 0, 90, 91, 5, 124, 0, 0, 91, 12, 1, 0, 0, 0, 92, 93, 5, 120, 0, 0, 93, 94, 5, 111, 0, 0, 94, 95, 5, 114, 0, 0, 95, 14, 1, 0, 0, 0, 96, 97, 7, 0, 0, 0, 97, 16, 1, 0, 0, 0, 98, 99, 5, 61, 0, 0, 99, 18, 1, 0, 0, 0, 100, 101, 5, 60, 0, 0, 101, 20, 1, 0, 0, 0, 102, 103, 5, 62, 0, 0, 103, 22, 1, 0, 0, 0, 104, 105, 5, 45, 0, 0, 105, 109, 5, 62, 0, 0, 106, 107, 5, 61, 0, 0, 107, 109, 5, 62, 0, 0, 108, 104, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 109, 24, 1, 0, 0, 0, 110, 114, 5, 94, 0, 0, 111, 112, 5, 42, 0, 0, 112, 114, 5, 42, 0, 0, 113, 110, 1, 0, 0, 0, 113, 111, 1, 0, 0, 0, 114, 26, 1, 0, 0, 0, 115, 116, 5, 42, 0, 0, 116, 28, 1, 0, 0, 0, 117, 118, 5, 47, 0, 0, 118, 30, 1, 0, 0, 0, 119, 120, 5, 43, 0, 0, 120, 32, 1, 0, 0, 0, 121, 122, 5, 45, 0, 0, 122, 34, 1, 0, 0, 0, 123, 124, 5, 37, 0, 0, 124, 36, 1, 0, 0, 0, 125, 126, 5, 46, 0, 0, 126, 38, 1, 0, 0, 0, 127, 128, 5, 40, 0, 0, 128, 40, 1, 0, 0, 0, 129, 130, 5, 41, 0, 0, 130, 42, 1, 0, 0, 0, 131, 132, 5, 91, 0, 0, 132, 44, 1, 0, 0, 0, 133, 134, 5, 93, 0, 0, 134, 46, 1, 0, 0, 0, 135, 136, 5, 112, 0, 0, 136, 142, 5, 105, 0, 0, 137, 142, 5, 101, 0, 0, 138, 139, 5, 112, 0, 0, 139, 140, 5, 104, 0, 0, 140, 142, 5, 105, 0, 0, 141, 135, 1, 0, 0, 0, 141, 137, 1, 0, 0, 0, 141, 138, 1, 0, 0, 0, 142, 48, 1, 0, 0, 0, 143, 149, 3, 53, 26, 0, 144, 146, 7, 1, 0, 0, 145, 147, 3, 51, 25, 0, 146, 145, 1, 0, 0, 0, 146, 147, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 150, 3, 53, 26, 0, 149, 144, 1, 0, 0, 0, 149, 150, 1, 0, 0, 0, 150, 50, 1, 0, 0, 0, 151, 152, 7, 2, 0, 0, 152, 52, 1, 0, 0, 0, 153, 155, 3, 63, 31, 0, 154, 153, 1, 0, 0, 0, 155, 156, 1, 0, 0, 0, 156, 154, 1, 0, 0, 0, 156, 157, 1, 0, 0, 0, 157, 164, 1, 0, 0, 0, 158, 160, 3, 37, 18, 0, 159, 161, 3, 63, 31, 0, 160, 159, 1, 0, 0, 0, 161, 162, 1, 0, 0, 0, 162, 160, 1, 0, 0, 0, 162, 163, 1, 0, 0, 0, 163, 165, 1, 0, 0, 0, 164, 158, 1, 0, 0, 0, 164, 165, 1, 0, 0, 0, 165, 54, 1, 0, 0, 0, 166, 170, 3, 59, 29, 0, 167, 169, 3, 61, 30, 0, 168, 167, 1, 0, 0, 0, 169, 172, 1, 0, 0, 0, 170, 168, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, 171, 56, 1, 0, 0, 0, 172, 170, 1, 0, 0, 0, 173, 177, 3, 65, 32, 0, 174, 176, 3, 61, 30, 0, 175, 174, 1, 0, 0, 0, 176, 179, 1, 0, 0, 0, 177, 175, 1, 0, 0, 0, 177, 178, 1, 0, 0, 0, 178, 58, 1, 0, 0, 0, 179, 177, 1, 0, 0, 0, 180, 183, 3, 67, 33, 0, 181, 183, 5, 95, 0, 0, 182, 180, 1, 0, 0, 0, 182, 181, 1, 0, 0, 0, 183, 60, 1, 0, 0, 0, 184, 188, 3, 59, 29, 0, 185, 188, 3, 65, 32, 0, 186, 188, 3, 63, 31, 0, 187, 184, 1, 0, 0, 0, 187, 185, 1, 0, 0, 0, 187, 186, 1, 0, 0, 0, 188, 62, 1, 0, 0, 0, 189, 190, 2, 48, 57, 0, 190, 64, 1, 0, 0, 0, 191, 192, 2, 65, 90, 0, 192, 66, 1, 0, 0, 0, 193, 194, 2, 97, 122, 0, 194, 68, 1, 0, 0, 0, 195, 197, 7, 3, 0, 0, 196, 195, 1, 0, 0, 0, 197, 198, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 198, 199, 1, 0, 0, 0, 199, 200, 1, 0, 0, 0, 200, 201, 6, 34, 0, 0, 201, 70, 1, 0, 0, 0, 14, 0, 108, 113, 141, 146, 149, 156, 162, 164, 170, 177, 182, 187, 198, 1, 6, 0, 0] \ No newline at end of file diff --git a/parser/AbacusLexer.tokens b/parser/AbacusLexer.tokens index 24ebf3e..359c0a6 100644 --- a/parser/AbacusLexer.tokens +++ b/parser/AbacusLexer.tokens @@ -2,94 +2,50 @@ T__0=1 T__1=2 T__2=3 T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -AND=27 -OR=28 -XOR=29 -NOT=30 -EQ=31 -LS=32 -GR=33 -ARROW=34 -POW=35 -MUL=36 -DIV=37 -ADD=38 -SUB=39 -PER=40 -POINT=41 -LPAREN=42 -RPAREN=43 -LSQPAREN=44 -RSQPAREN=45 -CONSTANT=46 -SCIENTIFIC_NUMBER=47 -VARIABLE=48 -LAMBDA_VARIABLE=49 -DIGITS=50 -UPPERCASE=51 -LOWERCASE=52 -WHITESPACE=53 +AND=5 +OR=6 +XOR=7 +NOT=8 +EQ=9 +LS=10 +GR=11 +ARROW=12 +POW=13 +MUL=14 +DIV=15 +ADD=16 +SUB=17 +PER=18 +POINT=19 +LPAREN=20 +RPAREN=21 +LSQPAREN=22 +RSQPAREN=23 +CONSTANT=24 +SCIENTIFIC_NUMBER=25 +VARIABLE=26 +LAMBDA_VARIABLE=27 +DIGITS=28 +UPPERCASE=29 +LOWERCASE=30 +WHITESPACE=31 'true'=1 'false'=2 ':'=3 ','=4 -'sqrt'=5 -'cbrt'=6 -'ln'=7 -'log'=8 -'log2'=9 -'log10'=10 -'floor'=11 -'ceil'=12 -'exp'=13 -'sin'=14 -'cos'=15 -'tan'=16 -'round'=17 -'sign'=18 -'abs'=19 -'min'=20 -'max'=21 -'avg'=22 -'until'=23 -'from'=24 -'reverse'=25 -'nth'=26 -'&&'=27 -'||'=28 -'xor'=29 -'='=31 -'<'=32 -'>'=33 -'*'=36 -'/'=37 -'+'=38 -'-'=39 -'%'=40 -'.'=41 -'('=42 -')'=43 -'['=44 -']'=45 +'&&'=5 +'||'=6 +'xor'=7 +'='=9 +'<'=10 +'>'=11 +'*'=14 +'/'=15 +'+'=16 +'-'=17 +'%'=18 +'.'=19 +'('=20 +')'=21 +'['=22 +']'=23 diff --git a/parser/abacus_base_listener.go b/parser/abacus_base_listener.go index dd05615..bdb314d 100644 --- a/parser/abacus_base_listener.go +++ b/parser/abacus_base_listener.go @@ -1,8 +1,8 @@ -// Code generated from Abacus.g4 by ANTLR 4.10.1. DO NOT EDIT. +// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. package parser // Abacus -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/antlr/antlr4/runtime/Go/antlr/v4" // BaseAbacusListener is a complete listener for a parse tree produced by AbacusParser. type BaseAbacusListener struct{} @@ -237,146 +237,8 @@ func (s *BaseAbacusListener) EnterMinusSign(ctx *MinusSignContext) {} // ExitMinusSign is called when production MinusSign is exited. func (s *BaseAbacusListener) ExitMinusSign(ctx *MinusSignContext) {} -// EnterSqrtFunction is called when production SqrtFunction is entered. -func (s *BaseAbacusListener) EnterSqrtFunction(ctx *SqrtFunctionContext) {} +// EnterFunctionInvocation is called when production FunctionInvocation is entered. +func (s *BaseAbacusListener) EnterFunctionInvocation(ctx *FunctionInvocationContext) {} -// ExitSqrtFunction is called when production SqrtFunction is exited. -func (s *BaseAbacusListener) ExitSqrtFunction(ctx *SqrtFunctionContext) {} - -// EnterCbrtFunction is called when production CbrtFunction is entered. -func (s *BaseAbacusListener) EnterCbrtFunction(ctx *CbrtFunctionContext) {} - -// ExitCbrtFunction is called when production CbrtFunction is exited. -func (s *BaseAbacusListener) ExitCbrtFunction(ctx *CbrtFunctionContext) {} - -// EnterLnFunction is called when production LnFunction is entered. -func (s *BaseAbacusListener) EnterLnFunction(ctx *LnFunctionContext) {} - -// ExitLnFunction is called when production LnFunction is exited. -func (s *BaseAbacusListener) ExitLnFunction(ctx *LnFunctionContext) {} - -// EnterLogDefFunction is called when production LogDefFunction is entered. -func (s *BaseAbacusListener) EnterLogDefFunction(ctx *LogDefFunctionContext) {} - -// ExitLogDefFunction is called when production LogDefFunction is exited. -func (s *BaseAbacusListener) ExitLogDefFunction(ctx *LogDefFunctionContext) {} - -// EnterLog2Function is called when production Log2Function is entered. -func (s *BaseAbacusListener) EnterLog2Function(ctx *Log2FunctionContext) {} - -// ExitLog2Function is called when production Log2Function is exited. -func (s *BaseAbacusListener) ExitLog2Function(ctx *Log2FunctionContext) {} - -// EnterLog10Function is called when production Log10Function is entered. -func (s *BaseAbacusListener) EnterLog10Function(ctx *Log10FunctionContext) {} - -// ExitLog10Function is called when production Log10Function is exited. -func (s *BaseAbacusListener) ExitLog10Function(ctx *Log10FunctionContext) {} - -// EnterFloorFunction is called when production FloorFunction is entered. -func (s *BaseAbacusListener) EnterFloorFunction(ctx *FloorFunctionContext) {} - -// ExitFloorFunction is called when production FloorFunction is exited. -func (s *BaseAbacusListener) ExitFloorFunction(ctx *FloorFunctionContext) {} - -// EnterCeilFunction is called when production CeilFunction is entered. -func (s *BaseAbacusListener) EnterCeilFunction(ctx *CeilFunctionContext) {} - -// ExitCeilFunction is called when production CeilFunction is exited. -func (s *BaseAbacusListener) ExitCeilFunction(ctx *CeilFunctionContext) {} - -// EnterExpFunction is called when production ExpFunction is entered. -func (s *BaseAbacusListener) EnterExpFunction(ctx *ExpFunctionContext) {} - -// ExitExpFunction is called when production ExpFunction is exited. -func (s *BaseAbacusListener) ExitExpFunction(ctx *ExpFunctionContext) {} - -// EnterSinFunction is called when production SinFunction is entered. -func (s *BaseAbacusListener) EnterSinFunction(ctx *SinFunctionContext) {} - -// ExitSinFunction is called when production SinFunction is exited. -func (s *BaseAbacusListener) ExitSinFunction(ctx *SinFunctionContext) {} - -// EnterCosFunction is called when production CosFunction is entered. -func (s *BaseAbacusListener) EnterCosFunction(ctx *CosFunctionContext) {} - -// ExitCosFunction is called when production CosFunction is exited. -func (s *BaseAbacusListener) ExitCosFunction(ctx *CosFunctionContext) {} - -// EnterTanFunction is called when production TanFunction is entered. -func (s *BaseAbacusListener) EnterTanFunction(ctx *TanFunctionContext) {} - -// ExitTanFunction is called when production TanFunction is exited. -func (s *BaseAbacusListener) ExitTanFunction(ctx *TanFunctionContext) {} - -// EnterRoundDefFunction is called when production RoundDefFunction is entered. -func (s *BaseAbacusListener) EnterRoundDefFunction(ctx *RoundDefFunctionContext) {} - -// ExitRoundDefFunction is called when production RoundDefFunction is exited. -func (s *BaseAbacusListener) ExitRoundDefFunction(ctx *RoundDefFunctionContext) {} - -// EnterSignFunction is called when production SignFunction is entered. -func (s *BaseAbacusListener) EnterSignFunction(ctx *SignFunctionContext) {} - -// ExitSignFunction is called when production SignFunction is exited. -func (s *BaseAbacusListener) ExitSignFunction(ctx *SignFunctionContext) {} - -// EnterAbsFunction is called when production AbsFunction is entered. -func (s *BaseAbacusListener) EnterAbsFunction(ctx *AbsFunctionContext) {} - -// ExitAbsFunction is called when production AbsFunction is exited. -func (s *BaseAbacusListener) ExitAbsFunction(ctx *AbsFunctionContext) {} - -// EnterRound2Function is called when production Round2Function is entered. -func (s *BaseAbacusListener) EnterRound2Function(ctx *Round2FunctionContext) {} - -// ExitRound2Function is called when production Round2Function is exited. -func (s *BaseAbacusListener) ExitRound2Function(ctx *Round2FunctionContext) {} - -// EnterLogFunction is called when production LogFunction is entered. -func (s *BaseAbacusListener) EnterLogFunction(ctx *LogFunctionContext) {} - -// ExitLogFunction is called when production LogFunction is exited. -func (s *BaseAbacusListener) ExitLogFunction(ctx *LogFunctionContext) {} - -// EnterMinFunction is called when production MinFunction is entered. -func (s *BaseAbacusListener) EnterMinFunction(ctx *MinFunctionContext) {} - -// ExitMinFunction is called when production MinFunction is exited. -func (s *BaseAbacusListener) ExitMinFunction(ctx *MinFunctionContext) {} - -// EnterMaxFunction is called when production MaxFunction is entered. -func (s *BaseAbacusListener) EnterMaxFunction(ctx *MaxFunctionContext) {} - -// ExitMaxFunction is called when production MaxFunction is exited. -func (s *BaseAbacusListener) ExitMaxFunction(ctx *MaxFunctionContext) {} - -// EnterAvgFunction is called when production AvgFunction is entered. -func (s *BaseAbacusListener) EnterAvgFunction(ctx *AvgFunctionContext) {} - -// ExitAvgFunction is called when production AvgFunction is exited. -func (s *BaseAbacusListener) ExitAvgFunction(ctx *AvgFunctionContext) {} - -// EnterUntilFunction is called when production UntilFunction is entered. -func (s *BaseAbacusListener) EnterUntilFunction(ctx *UntilFunctionContext) {} - -// ExitUntilFunction is called when production UntilFunction is exited. -func (s *BaseAbacusListener) ExitUntilFunction(ctx *UntilFunctionContext) {} - -// EnterFromFunction is called when production FromFunction is entered. -func (s *BaseAbacusListener) EnterFromFunction(ctx *FromFunctionContext) {} - -// ExitFromFunction is called when production FromFunction is exited. -func (s *BaseAbacusListener) ExitFromFunction(ctx *FromFunctionContext) {} - -// EnterReverseFunction is called when production ReverseFunction is entered. -func (s *BaseAbacusListener) EnterReverseFunction(ctx *ReverseFunctionContext) {} - -// ExitReverseFunction is called when production ReverseFunction is exited. -func (s *BaseAbacusListener) ExitReverseFunction(ctx *ReverseFunctionContext) {} - -// EnterNthFunction is called when production NthFunction is entered. -func (s *BaseAbacusListener) EnterNthFunction(ctx *NthFunctionContext) {} - -// ExitNthFunction is called when production NthFunction is exited. -func (s *BaseAbacusListener) ExitNthFunction(ctx *NthFunctionContext) {} +// ExitFunctionInvocation is called when production FunctionInvocation is exited. +func (s *BaseAbacusListener) ExitFunctionInvocation(ctx *FunctionInvocationContext) {} diff --git a/parser/abacus_base_visitor.go b/parser/abacus_base_visitor.go index 9998d31..ca3fe6e 100644 --- a/parser/abacus_base_visitor.go +++ b/parser/abacus_base_visitor.go @@ -1,8 +1,8 @@ -// Code generated from Abacus.g4 by ANTLR 4.10.1. DO NOT EDIT. +// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. package parser // Abacus -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/antlr/antlr4/runtime/Go/antlr/v4" type BaseAbacusVisitor struct { *antlr.BaseParseTreeVisitor @@ -152,98 +152,6 @@ func (v *BaseAbacusVisitor) VisitMinusSign(ctx *MinusSignContext) interface{} { return v.VisitChildren(ctx) } -func (v *BaseAbacusVisitor) VisitSqrtFunction(ctx *SqrtFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitCbrtFunction(ctx *CbrtFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitLnFunction(ctx *LnFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitLogDefFunction(ctx *LogDefFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitLog2Function(ctx *Log2FunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitLog10Function(ctx *Log10FunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitFloorFunction(ctx *FloorFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitCeilFunction(ctx *CeilFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitExpFunction(ctx *ExpFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitSinFunction(ctx *SinFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitCosFunction(ctx *CosFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitTanFunction(ctx *TanFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitRoundDefFunction(ctx *RoundDefFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitSignFunction(ctx *SignFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitAbsFunction(ctx *AbsFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitRound2Function(ctx *Round2FunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitLogFunction(ctx *LogFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitMinFunction(ctx *MinFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitMaxFunction(ctx *MaxFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitAvgFunction(ctx *AvgFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitUntilFunction(ctx *UntilFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitFromFunction(ctx *FromFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitReverseFunction(ctx *ReverseFunctionContext) interface{} { - return v.VisitChildren(ctx) -} - -func (v *BaseAbacusVisitor) VisitNthFunction(ctx *NthFunctionContext) interface{} { +func (v *BaseAbacusVisitor) VisitFunctionInvocation(ctx *FunctionInvocationContext) interface{} { return v.VisitChildren(ctx) } diff --git a/parser/abacus_lexer.go b/parser/abacus_lexer.go index f69b993..dd0f1ca 100644 --- a/parser/abacus_lexer.go +++ b/parser/abacus_lexer.go @@ -1,4 +1,4 @@ -// Code generated from Abacus.g4 by ANTLR 4.10.1. DO NOT EDIT. +// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. package parser @@ -7,7 +7,7 @@ import ( "sync" "unicode" - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/antlr/antlr4/runtime/Go/antlr/v4" ) // Suppress unused import error @@ -44,185 +44,115 @@ func abacuslexerLexerInit() { "DEFAULT_MODE", } staticData.literalNames = []string{ - "", "'true'", "'false'", "':'", "','", "'sqrt'", "'cbrt'", "'ln'", "'log'", - "'log2'", "'log10'", "'floor'", "'ceil'", "'exp'", "'sin'", "'cos'", - "'tan'", "'round'", "'sign'", "'abs'", "'min'", "'max'", "'avg'", "'until'", - "'from'", "'reverse'", "'nth'", "'&&'", "'||'", "'xor'", "", "'='", - "'<'", "'>'", "", "", "'*'", "'/'", "'+'", "'-'", "'%'", "'.'", "'('", - "')'", "'['", "']'", + "", "'true'", "'false'", "':'", "','", "'&&'", "'||'", "'xor'", "", + "'='", "'<'", "'>'", "", "", "'*'", "'/'", "'+'", "'-'", "'%'", "'.'", + "'('", "')'", "'['", "']'", } staticData.symbolicNames = []string{ - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "AND", "OR", "XOR", "NOT", "EQ", - "LS", "GR", "ARROW", "POW", "MUL", "DIV", "ADD", "SUB", "PER", "POINT", - "LPAREN", "RPAREN", "LSQPAREN", "RSQPAREN", "CONSTANT", "SCIENTIFIC_NUMBER", - "VARIABLE", "LAMBDA_VARIABLE", "DIGITS", "UPPERCASE", "LOWERCASE", "WHITESPACE", + "", "", "", "", "", "AND", "OR", "XOR", "NOT", "EQ", "LS", "GR", "ARROW", + "POW", "MUL", "DIV", "ADD", "SUB", "PER", "POINT", "LPAREN", "RPAREN", + "LSQPAREN", "RSQPAREN", "CONSTANT", "SCIENTIFIC_NUMBER", "VARIABLE", + "LAMBDA_VARIABLE", "DIGITS", "UPPERCASE", "LOWERCASE", "WHITESPACE", } staticData.ruleNames = []string{ - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", - "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24", - "T__25", "AND", "OR", "XOR", "NOT", "EQ", "LS", "GR", "ARROW", "POW", - "MUL", "DIV", "ADD", "SUB", "PER", "POINT", "LPAREN", "RPAREN", "LSQPAREN", - "RSQPAREN", "CONSTANT", "SCIENTIFIC_NUMBER", "SIGN", "NUMBER", "VARIABLE", - "LAMBDA_VARIABLE", "VALID_ID_START", "VALID_ID_CHAR", "DIGITS", "UPPERCASE", - "LOWERCASE", "WHITESPACE", + "T__0", "T__1", "T__2", "T__3", "AND", "OR", "XOR", "NOT", "EQ", "LS", + "GR", "ARROW", "POW", "MUL", "DIV", "ADD", "SUB", "PER", "POINT", "LPAREN", + "RPAREN", "LSQPAREN", "RSQPAREN", "CONSTANT", "SCIENTIFIC_NUMBER", "SIGN", + "NUMBER", "VARIABLE", "LAMBDA_VARIABLE", "VALID_ID_START", "VALID_ID_CHAR", + "DIGITS", "UPPERCASE", "LOWERCASE", "WHITESPACE", } staticData.predictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 0, 53, 351, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, + 4, 0, 31, 202, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, - 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, - 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, - 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, - 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, - 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 1, 0, - 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, - 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, - 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, - 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, - 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, - 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, - 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, - 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, - 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, - 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 24, - 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, - 26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, - 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 33, 3, - 33, 258, 8, 33, 1, 34, 1, 34, 1, 34, 3, 34, 263, 8, 34, 1, 35, 1, 35, 1, - 36, 1, 36, 1, 37, 1, 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 40, 1, 40, 1, 41, - 1, 41, 1, 42, 1, 42, 1, 43, 1, 43, 1, 44, 1, 44, 1, 45, 1, 45, 1, 45, 1, - 45, 1, 45, 1, 45, 3, 45, 291, 8, 45, 1, 46, 1, 46, 1, 46, 3, 46, 296, 8, - 46, 1, 46, 3, 46, 299, 8, 46, 1, 47, 1, 47, 1, 48, 4, 48, 304, 8, 48, 11, - 48, 12, 48, 305, 1, 48, 1, 48, 4, 48, 310, 8, 48, 11, 48, 12, 48, 311, - 3, 48, 314, 8, 48, 1, 49, 1, 49, 5, 49, 318, 8, 49, 10, 49, 12, 49, 321, - 9, 49, 1, 50, 1, 50, 5, 50, 325, 8, 50, 10, 50, 12, 50, 328, 9, 50, 1, - 51, 1, 51, 3, 51, 332, 8, 51, 1, 52, 1, 52, 1, 52, 3, 52, 337, 8, 52, 1, - 53, 1, 53, 1, 54, 1, 54, 1, 55, 1, 55, 1, 56, 4, 56, 346, 8, 56, 11, 56, - 12, 56, 347, 1, 56, 1, 56, 0, 0, 57, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, - 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, - 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, - 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, - 67, 34, 69, 35, 71, 36, 73, 37, 75, 38, 77, 39, 79, 40, 81, 41, 83, 42, - 85, 43, 87, 44, 89, 45, 91, 46, 93, 47, 95, 0, 97, 0, 99, 48, 101, 49, - 103, 0, 105, 0, 107, 50, 109, 51, 111, 52, 113, 53, 1, 0, 4, 3, 0, 33, - 33, 126, 126, 172, 172, 2, 0, 69, 69, 101, 101, 2, 0, 43, 43, 45, 45, 3, - 0, 9, 10, 13, 13, 32, 32, 361, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, - 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, - 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, - 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, - 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, - 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, - 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, - 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, - 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, - 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, - 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, - 0, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, - 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 99, 1, 0, 0, 0, 0, 101, - 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, - 0, 113, 1, 0, 0, 0, 1, 115, 1, 0, 0, 0, 3, 120, 1, 0, 0, 0, 5, 126, 1, - 0, 0, 0, 7, 128, 1, 0, 0, 0, 9, 130, 1, 0, 0, 0, 11, 135, 1, 0, 0, 0, 13, - 140, 1, 0, 0, 0, 15, 143, 1, 0, 0, 0, 17, 147, 1, 0, 0, 0, 19, 152, 1, - 0, 0, 0, 21, 158, 1, 0, 0, 0, 23, 164, 1, 0, 0, 0, 25, 169, 1, 0, 0, 0, - 27, 173, 1, 0, 0, 0, 29, 177, 1, 0, 0, 0, 31, 181, 1, 0, 0, 0, 33, 185, - 1, 0, 0, 0, 35, 191, 1, 0, 0, 0, 37, 196, 1, 0, 0, 0, 39, 200, 1, 0, 0, - 0, 41, 204, 1, 0, 0, 0, 43, 208, 1, 0, 0, 0, 45, 212, 1, 0, 0, 0, 47, 218, - 1, 0, 0, 0, 49, 223, 1, 0, 0, 0, 51, 231, 1, 0, 0, 0, 53, 235, 1, 0, 0, - 0, 55, 238, 1, 0, 0, 0, 57, 241, 1, 0, 0, 0, 59, 245, 1, 0, 0, 0, 61, 247, - 1, 0, 0, 0, 63, 249, 1, 0, 0, 0, 65, 251, 1, 0, 0, 0, 67, 257, 1, 0, 0, - 0, 69, 262, 1, 0, 0, 0, 71, 264, 1, 0, 0, 0, 73, 266, 1, 0, 0, 0, 75, 268, - 1, 0, 0, 0, 77, 270, 1, 0, 0, 0, 79, 272, 1, 0, 0, 0, 81, 274, 1, 0, 0, - 0, 83, 276, 1, 0, 0, 0, 85, 278, 1, 0, 0, 0, 87, 280, 1, 0, 0, 0, 89, 282, - 1, 0, 0, 0, 91, 290, 1, 0, 0, 0, 93, 292, 1, 0, 0, 0, 95, 300, 1, 0, 0, - 0, 97, 303, 1, 0, 0, 0, 99, 315, 1, 0, 0, 0, 101, 322, 1, 0, 0, 0, 103, - 331, 1, 0, 0, 0, 105, 336, 1, 0, 0, 0, 107, 338, 1, 0, 0, 0, 109, 340, - 1, 0, 0, 0, 111, 342, 1, 0, 0, 0, 113, 345, 1, 0, 0, 0, 115, 116, 5, 116, - 0, 0, 116, 117, 5, 114, 0, 0, 117, 118, 5, 117, 0, 0, 118, 119, 5, 101, - 0, 0, 119, 2, 1, 0, 0, 0, 120, 121, 5, 102, 0, 0, 121, 122, 5, 97, 0, 0, - 122, 123, 5, 108, 0, 0, 123, 124, 5, 115, 0, 0, 124, 125, 5, 101, 0, 0, - 125, 4, 1, 0, 0, 0, 126, 127, 5, 58, 0, 0, 127, 6, 1, 0, 0, 0, 128, 129, - 5, 44, 0, 0, 129, 8, 1, 0, 0, 0, 130, 131, 5, 115, 0, 0, 131, 132, 5, 113, - 0, 0, 132, 133, 5, 114, 0, 0, 133, 134, 5, 116, 0, 0, 134, 10, 1, 0, 0, - 0, 135, 136, 5, 99, 0, 0, 136, 137, 5, 98, 0, 0, 137, 138, 5, 114, 0, 0, - 138, 139, 5, 116, 0, 0, 139, 12, 1, 0, 0, 0, 140, 141, 5, 108, 0, 0, 141, - 142, 5, 110, 0, 0, 142, 14, 1, 0, 0, 0, 143, 144, 5, 108, 0, 0, 144, 145, - 5, 111, 0, 0, 145, 146, 5, 103, 0, 0, 146, 16, 1, 0, 0, 0, 147, 148, 5, - 108, 0, 0, 148, 149, 5, 111, 0, 0, 149, 150, 5, 103, 0, 0, 150, 151, 5, - 50, 0, 0, 151, 18, 1, 0, 0, 0, 152, 153, 5, 108, 0, 0, 153, 154, 5, 111, - 0, 0, 154, 155, 5, 103, 0, 0, 155, 156, 5, 49, 0, 0, 156, 157, 5, 48, 0, - 0, 157, 20, 1, 0, 0, 0, 158, 159, 5, 102, 0, 0, 159, 160, 5, 108, 0, 0, - 160, 161, 5, 111, 0, 0, 161, 162, 5, 111, 0, 0, 162, 163, 5, 114, 0, 0, - 163, 22, 1, 0, 0, 0, 164, 165, 5, 99, 0, 0, 165, 166, 5, 101, 0, 0, 166, - 167, 5, 105, 0, 0, 167, 168, 5, 108, 0, 0, 168, 24, 1, 0, 0, 0, 169, 170, - 5, 101, 0, 0, 170, 171, 5, 120, 0, 0, 171, 172, 5, 112, 0, 0, 172, 26, - 1, 0, 0, 0, 173, 174, 5, 115, 0, 0, 174, 175, 5, 105, 0, 0, 175, 176, 5, - 110, 0, 0, 176, 28, 1, 0, 0, 0, 177, 178, 5, 99, 0, 0, 178, 179, 5, 111, - 0, 0, 179, 180, 5, 115, 0, 0, 180, 30, 1, 0, 0, 0, 181, 182, 5, 116, 0, - 0, 182, 183, 5, 97, 0, 0, 183, 184, 5, 110, 0, 0, 184, 32, 1, 0, 0, 0, - 185, 186, 5, 114, 0, 0, 186, 187, 5, 111, 0, 0, 187, 188, 5, 117, 0, 0, - 188, 189, 5, 110, 0, 0, 189, 190, 5, 100, 0, 0, 190, 34, 1, 0, 0, 0, 191, - 192, 5, 115, 0, 0, 192, 193, 5, 105, 0, 0, 193, 194, 5, 103, 0, 0, 194, - 195, 5, 110, 0, 0, 195, 36, 1, 0, 0, 0, 196, 197, 5, 97, 0, 0, 197, 198, - 5, 98, 0, 0, 198, 199, 5, 115, 0, 0, 199, 38, 1, 0, 0, 0, 200, 201, 5, - 109, 0, 0, 201, 202, 5, 105, 0, 0, 202, 203, 5, 110, 0, 0, 203, 40, 1, - 0, 0, 0, 204, 205, 5, 109, 0, 0, 205, 206, 5, 97, 0, 0, 206, 207, 5, 120, - 0, 0, 207, 42, 1, 0, 0, 0, 208, 209, 5, 97, 0, 0, 209, 210, 5, 118, 0, - 0, 210, 211, 5, 103, 0, 0, 211, 44, 1, 0, 0, 0, 212, 213, 5, 117, 0, 0, - 213, 214, 5, 110, 0, 0, 214, 215, 5, 116, 0, 0, 215, 216, 5, 105, 0, 0, - 216, 217, 5, 108, 0, 0, 217, 46, 1, 0, 0, 0, 218, 219, 5, 102, 0, 0, 219, - 220, 5, 114, 0, 0, 220, 221, 5, 111, 0, 0, 221, 222, 5, 109, 0, 0, 222, - 48, 1, 0, 0, 0, 223, 224, 5, 114, 0, 0, 224, 225, 5, 101, 0, 0, 225, 226, - 5, 118, 0, 0, 226, 227, 5, 101, 0, 0, 227, 228, 5, 114, 0, 0, 228, 229, - 5, 115, 0, 0, 229, 230, 5, 101, 0, 0, 230, 50, 1, 0, 0, 0, 231, 232, 5, - 110, 0, 0, 232, 233, 5, 116, 0, 0, 233, 234, 5, 104, 0, 0, 234, 52, 1, - 0, 0, 0, 235, 236, 5, 38, 0, 0, 236, 237, 5, 38, 0, 0, 237, 54, 1, 0, 0, - 0, 238, 239, 5, 124, 0, 0, 239, 240, 5, 124, 0, 0, 240, 56, 1, 0, 0, 0, - 241, 242, 5, 120, 0, 0, 242, 243, 5, 111, 0, 0, 243, 244, 5, 114, 0, 0, - 244, 58, 1, 0, 0, 0, 245, 246, 7, 0, 0, 0, 246, 60, 1, 0, 0, 0, 247, 248, - 5, 61, 0, 0, 248, 62, 1, 0, 0, 0, 249, 250, 5, 60, 0, 0, 250, 64, 1, 0, - 0, 0, 251, 252, 5, 62, 0, 0, 252, 66, 1, 0, 0, 0, 253, 254, 5, 45, 0, 0, - 254, 258, 5, 62, 0, 0, 255, 256, 5, 61, 0, 0, 256, 258, 5, 62, 0, 0, 257, - 253, 1, 0, 0, 0, 257, 255, 1, 0, 0, 0, 258, 68, 1, 0, 0, 0, 259, 263, 5, - 94, 0, 0, 260, 261, 5, 42, 0, 0, 261, 263, 5, 42, 0, 0, 262, 259, 1, 0, - 0, 0, 262, 260, 1, 0, 0, 0, 263, 70, 1, 0, 0, 0, 264, 265, 5, 42, 0, 0, - 265, 72, 1, 0, 0, 0, 266, 267, 5, 47, 0, 0, 267, 74, 1, 0, 0, 0, 268, 269, - 5, 43, 0, 0, 269, 76, 1, 0, 0, 0, 270, 271, 5, 45, 0, 0, 271, 78, 1, 0, - 0, 0, 272, 273, 5, 37, 0, 0, 273, 80, 1, 0, 0, 0, 274, 275, 5, 46, 0, 0, - 275, 82, 1, 0, 0, 0, 276, 277, 5, 40, 0, 0, 277, 84, 1, 0, 0, 0, 278, 279, - 5, 41, 0, 0, 279, 86, 1, 0, 0, 0, 280, 281, 5, 91, 0, 0, 281, 88, 1, 0, - 0, 0, 282, 283, 5, 93, 0, 0, 283, 90, 1, 0, 0, 0, 284, 285, 5, 112, 0, - 0, 285, 291, 5, 105, 0, 0, 286, 291, 5, 101, 0, 0, 287, 288, 5, 112, 0, - 0, 288, 289, 5, 104, 0, 0, 289, 291, 5, 105, 0, 0, 290, 284, 1, 0, 0, 0, - 290, 286, 1, 0, 0, 0, 290, 287, 1, 0, 0, 0, 291, 92, 1, 0, 0, 0, 292, 298, - 3, 97, 48, 0, 293, 295, 7, 1, 0, 0, 294, 296, 3, 95, 47, 0, 295, 294, 1, - 0, 0, 0, 295, 296, 1, 0, 0, 0, 296, 297, 1, 0, 0, 0, 297, 299, 3, 97, 48, - 0, 298, 293, 1, 0, 0, 0, 298, 299, 1, 0, 0, 0, 299, 94, 1, 0, 0, 0, 300, - 301, 7, 2, 0, 0, 301, 96, 1, 0, 0, 0, 302, 304, 3, 107, 53, 0, 303, 302, - 1, 0, 0, 0, 304, 305, 1, 0, 0, 0, 305, 303, 1, 0, 0, 0, 305, 306, 1, 0, - 0, 0, 306, 313, 1, 0, 0, 0, 307, 309, 3, 81, 40, 0, 308, 310, 3, 107, 53, - 0, 309, 308, 1, 0, 0, 0, 310, 311, 1, 0, 0, 0, 311, 309, 1, 0, 0, 0, 311, - 312, 1, 0, 0, 0, 312, 314, 1, 0, 0, 0, 313, 307, 1, 0, 0, 0, 313, 314, - 1, 0, 0, 0, 314, 98, 1, 0, 0, 0, 315, 319, 3, 103, 51, 0, 316, 318, 3, - 105, 52, 0, 317, 316, 1, 0, 0, 0, 318, 321, 1, 0, 0, 0, 319, 317, 1, 0, - 0, 0, 319, 320, 1, 0, 0, 0, 320, 100, 1, 0, 0, 0, 321, 319, 1, 0, 0, 0, - 322, 326, 3, 109, 54, 0, 323, 325, 3, 105, 52, 0, 324, 323, 1, 0, 0, 0, - 325, 328, 1, 0, 0, 0, 326, 324, 1, 0, 0, 0, 326, 327, 1, 0, 0, 0, 327, - 102, 1, 0, 0, 0, 328, 326, 1, 0, 0, 0, 329, 332, 3, 111, 55, 0, 330, 332, - 5, 95, 0, 0, 331, 329, 1, 0, 0, 0, 331, 330, 1, 0, 0, 0, 332, 104, 1, 0, - 0, 0, 333, 337, 3, 103, 51, 0, 334, 337, 3, 109, 54, 0, 335, 337, 3, 107, - 53, 0, 336, 333, 1, 0, 0, 0, 336, 334, 1, 0, 0, 0, 336, 335, 1, 0, 0, 0, - 337, 106, 1, 0, 0, 0, 338, 339, 2, 48, 57, 0, 339, 108, 1, 0, 0, 0, 340, - 341, 2, 65, 90, 0, 341, 110, 1, 0, 0, 0, 342, 343, 2, 97, 122, 0, 343, - 112, 1, 0, 0, 0, 344, 346, 7, 3, 0, 0, 345, 344, 1, 0, 0, 0, 346, 347, - 1, 0, 0, 0, 347, 345, 1, 0, 0, 0, 347, 348, 1, 0, 0, 0, 348, 349, 1, 0, - 0, 0, 349, 350, 6, 56, 0, 0, 350, 114, 1, 0, 0, 0, 14, 0, 257, 262, 290, - 295, 298, 305, 311, 313, 319, 326, 331, 336, 347, 1, 6, 0, 0, + 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 1, 0, 1, 0, 1, 0, + 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, + 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, + 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, + 109, 8, 11, 1, 12, 1, 12, 1, 12, 3, 12, 114, 8, 12, 1, 13, 1, 13, 1, 14, + 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, + 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, + 1, 23, 1, 23, 3, 23, 142, 8, 23, 1, 24, 1, 24, 1, 24, 3, 24, 147, 8, 24, + 1, 24, 3, 24, 150, 8, 24, 1, 25, 1, 25, 1, 26, 4, 26, 155, 8, 26, 11, 26, + 12, 26, 156, 1, 26, 1, 26, 4, 26, 161, 8, 26, 11, 26, 12, 26, 162, 3, 26, + 165, 8, 26, 1, 27, 1, 27, 5, 27, 169, 8, 27, 10, 27, 12, 27, 172, 9, 27, + 1, 28, 1, 28, 5, 28, 176, 8, 28, 10, 28, 12, 28, 179, 9, 28, 1, 29, 1, + 29, 3, 29, 183, 8, 29, 1, 30, 1, 30, 1, 30, 3, 30, 188, 8, 30, 1, 31, 1, + 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 4, 34, 197, 8, 34, 11, 34, 12, 34, + 198, 1, 34, 1, 34, 0, 0, 35, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, + 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, + 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, + 0, 53, 0, 55, 26, 57, 27, 59, 0, 61, 0, 63, 28, 65, 29, 67, 30, 69, 31, + 1, 0, 4, 3, 0, 33, 33, 126, 126, 172, 172, 2, 0, 69, 69, 101, 101, 2, 0, + 43, 43, 45, 45, 3, 0, 9, 10, 13, 13, 32, 32, 212, 0, 1, 1, 0, 0, 0, 0, + 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, + 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, + 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, + 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, + 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, + 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, + 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, + 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 1, 71, 1, 0, 0, 0, + 3, 76, 1, 0, 0, 0, 5, 82, 1, 0, 0, 0, 7, 84, 1, 0, 0, 0, 9, 86, 1, 0, 0, + 0, 11, 89, 1, 0, 0, 0, 13, 92, 1, 0, 0, 0, 15, 96, 1, 0, 0, 0, 17, 98, + 1, 0, 0, 0, 19, 100, 1, 0, 0, 0, 21, 102, 1, 0, 0, 0, 23, 108, 1, 0, 0, + 0, 25, 113, 1, 0, 0, 0, 27, 115, 1, 0, 0, 0, 29, 117, 1, 0, 0, 0, 31, 119, + 1, 0, 0, 0, 33, 121, 1, 0, 0, 0, 35, 123, 1, 0, 0, 0, 37, 125, 1, 0, 0, + 0, 39, 127, 1, 0, 0, 0, 41, 129, 1, 0, 0, 0, 43, 131, 1, 0, 0, 0, 45, 133, + 1, 0, 0, 0, 47, 141, 1, 0, 0, 0, 49, 143, 1, 0, 0, 0, 51, 151, 1, 0, 0, + 0, 53, 154, 1, 0, 0, 0, 55, 166, 1, 0, 0, 0, 57, 173, 1, 0, 0, 0, 59, 182, + 1, 0, 0, 0, 61, 187, 1, 0, 0, 0, 63, 189, 1, 0, 0, 0, 65, 191, 1, 0, 0, + 0, 67, 193, 1, 0, 0, 0, 69, 196, 1, 0, 0, 0, 71, 72, 5, 116, 0, 0, 72, + 73, 5, 114, 0, 0, 73, 74, 5, 117, 0, 0, 74, 75, 5, 101, 0, 0, 75, 2, 1, + 0, 0, 0, 76, 77, 5, 102, 0, 0, 77, 78, 5, 97, 0, 0, 78, 79, 5, 108, 0, + 0, 79, 80, 5, 115, 0, 0, 80, 81, 5, 101, 0, 0, 81, 4, 1, 0, 0, 0, 82, 83, + 5, 58, 0, 0, 83, 6, 1, 0, 0, 0, 84, 85, 5, 44, 0, 0, 85, 8, 1, 0, 0, 0, + 86, 87, 5, 38, 0, 0, 87, 88, 5, 38, 0, 0, 88, 10, 1, 0, 0, 0, 89, 90, 5, + 124, 0, 0, 90, 91, 5, 124, 0, 0, 91, 12, 1, 0, 0, 0, 92, 93, 5, 120, 0, + 0, 93, 94, 5, 111, 0, 0, 94, 95, 5, 114, 0, 0, 95, 14, 1, 0, 0, 0, 96, + 97, 7, 0, 0, 0, 97, 16, 1, 0, 0, 0, 98, 99, 5, 61, 0, 0, 99, 18, 1, 0, + 0, 0, 100, 101, 5, 60, 0, 0, 101, 20, 1, 0, 0, 0, 102, 103, 5, 62, 0, 0, + 103, 22, 1, 0, 0, 0, 104, 105, 5, 45, 0, 0, 105, 109, 5, 62, 0, 0, 106, + 107, 5, 61, 0, 0, 107, 109, 5, 62, 0, 0, 108, 104, 1, 0, 0, 0, 108, 106, + 1, 0, 0, 0, 109, 24, 1, 0, 0, 0, 110, 114, 5, 94, 0, 0, 111, 112, 5, 42, + 0, 0, 112, 114, 5, 42, 0, 0, 113, 110, 1, 0, 0, 0, 113, 111, 1, 0, 0, 0, + 114, 26, 1, 0, 0, 0, 115, 116, 5, 42, 0, 0, 116, 28, 1, 0, 0, 0, 117, 118, + 5, 47, 0, 0, 118, 30, 1, 0, 0, 0, 119, 120, 5, 43, 0, 0, 120, 32, 1, 0, + 0, 0, 121, 122, 5, 45, 0, 0, 122, 34, 1, 0, 0, 0, 123, 124, 5, 37, 0, 0, + 124, 36, 1, 0, 0, 0, 125, 126, 5, 46, 0, 0, 126, 38, 1, 0, 0, 0, 127, 128, + 5, 40, 0, 0, 128, 40, 1, 0, 0, 0, 129, 130, 5, 41, 0, 0, 130, 42, 1, 0, + 0, 0, 131, 132, 5, 91, 0, 0, 132, 44, 1, 0, 0, 0, 133, 134, 5, 93, 0, 0, + 134, 46, 1, 0, 0, 0, 135, 136, 5, 112, 0, 0, 136, 142, 5, 105, 0, 0, 137, + 142, 5, 101, 0, 0, 138, 139, 5, 112, 0, 0, 139, 140, 5, 104, 0, 0, 140, + 142, 5, 105, 0, 0, 141, 135, 1, 0, 0, 0, 141, 137, 1, 0, 0, 0, 141, 138, + 1, 0, 0, 0, 142, 48, 1, 0, 0, 0, 143, 149, 3, 53, 26, 0, 144, 146, 7, 1, + 0, 0, 145, 147, 3, 51, 25, 0, 146, 145, 1, 0, 0, 0, 146, 147, 1, 0, 0, + 0, 147, 148, 1, 0, 0, 0, 148, 150, 3, 53, 26, 0, 149, 144, 1, 0, 0, 0, + 149, 150, 1, 0, 0, 0, 150, 50, 1, 0, 0, 0, 151, 152, 7, 2, 0, 0, 152, 52, + 1, 0, 0, 0, 153, 155, 3, 63, 31, 0, 154, 153, 1, 0, 0, 0, 155, 156, 1, + 0, 0, 0, 156, 154, 1, 0, 0, 0, 156, 157, 1, 0, 0, 0, 157, 164, 1, 0, 0, + 0, 158, 160, 3, 37, 18, 0, 159, 161, 3, 63, 31, 0, 160, 159, 1, 0, 0, 0, + 161, 162, 1, 0, 0, 0, 162, 160, 1, 0, 0, 0, 162, 163, 1, 0, 0, 0, 163, + 165, 1, 0, 0, 0, 164, 158, 1, 0, 0, 0, 164, 165, 1, 0, 0, 0, 165, 54, 1, + 0, 0, 0, 166, 170, 3, 59, 29, 0, 167, 169, 3, 61, 30, 0, 168, 167, 1, 0, + 0, 0, 169, 172, 1, 0, 0, 0, 170, 168, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, + 171, 56, 1, 0, 0, 0, 172, 170, 1, 0, 0, 0, 173, 177, 3, 65, 32, 0, 174, + 176, 3, 61, 30, 0, 175, 174, 1, 0, 0, 0, 176, 179, 1, 0, 0, 0, 177, 175, + 1, 0, 0, 0, 177, 178, 1, 0, 0, 0, 178, 58, 1, 0, 0, 0, 179, 177, 1, 0, + 0, 0, 180, 183, 3, 67, 33, 0, 181, 183, 5, 95, 0, 0, 182, 180, 1, 0, 0, + 0, 182, 181, 1, 0, 0, 0, 183, 60, 1, 0, 0, 0, 184, 188, 3, 59, 29, 0, 185, + 188, 3, 65, 32, 0, 186, 188, 3, 63, 31, 0, 187, 184, 1, 0, 0, 0, 187, 185, + 1, 0, 0, 0, 187, 186, 1, 0, 0, 0, 188, 62, 1, 0, 0, 0, 189, 190, 2, 48, + 57, 0, 190, 64, 1, 0, 0, 0, 191, 192, 2, 65, 90, 0, 192, 66, 1, 0, 0, 0, + 193, 194, 2, 97, 122, 0, 194, 68, 1, 0, 0, 0, 195, 197, 7, 3, 0, 0, 196, + 195, 1, 0, 0, 0, 197, 198, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 198, 199, + 1, 0, 0, 0, 199, 200, 1, 0, 0, 0, 200, 201, 6, 34, 0, 0, 201, 70, 1, 0, + 0, 0, 14, 0, 108, 113, 141, 146, 149, 156, 162, 164, 170, 177, 182, 187, + 198, 1, 6, 0, 0, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -267,53 +197,31 @@ const ( AbacusLexerT__1 = 2 AbacusLexerT__2 = 3 AbacusLexerT__3 = 4 - AbacusLexerT__4 = 5 - AbacusLexerT__5 = 6 - AbacusLexerT__6 = 7 - AbacusLexerT__7 = 8 - AbacusLexerT__8 = 9 - AbacusLexerT__9 = 10 - AbacusLexerT__10 = 11 - AbacusLexerT__11 = 12 - AbacusLexerT__12 = 13 - AbacusLexerT__13 = 14 - AbacusLexerT__14 = 15 - AbacusLexerT__15 = 16 - AbacusLexerT__16 = 17 - AbacusLexerT__17 = 18 - AbacusLexerT__18 = 19 - AbacusLexerT__19 = 20 - AbacusLexerT__20 = 21 - AbacusLexerT__21 = 22 - AbacusLexerT__22 = 23 - AbacusLexerT__23 = 24 - AbacusLexerT__24 = 25 - AbacusLexerT__25 = 26 - AbacusLexerAND = 27 - AbacusLexerOR = 28 - AbacusLexerXOR = 29 - AbacusLexerNOT = 30 - AbacusLexerEQ = 31 - AbacusLexerLS = 32 - AbacusLexerGR = 33 - AbacusLexerARROW = 34 - AbacusLexerPOW = 35 - AbacusLexerMUL = 36 - AbacusLexerDIV = 37 - AbacusLexerADD = 38 - AbacusLexerSUB = 39 - AbacusLexerPER = 40 - AbacusLexerPOINT = 41 - AbacusLexerLPAREN = 42 - AbacusLexerRPAREN = 43 - AbacusLexerLSQPAREN = 44 - AbacusLexerRSQPAREN = 45 - AbacusLexerCONSTANT = 46 - AbacusLexerSCIENTIFIC_NUMBER = 47 - AbacusLexerVARIABLE = 48 - AbacusLexerLAMBDA_VARIABLE = 49 - AbacusLexerDIGITS = 50 - AbacusLexerUPPERCASE = 51 - AbacusLexerLOWERCASE = 52 - AbacusLexerWHITESPACE = 53 + AbacusLexerAND = 5 + AbacusLexerOR = 6 + AbacusLexerXOR = 7 + AbacusLexerNOT = 8 + AbacusLexerEQ = 9 + AbacusLexerLS = 10 + AbacusLexerGR = 11 + AbacusLexerARROW = 12 + AbacusLexerPOW = 13 + AbacusLexerMUL = 14 + AbacusLexerDIV = 15 + AbacusLexerADD = 16 + AbacusLexerSUB = 17 + AbacusLexerPER = 18 + AbacusLexerPOINT = 19 + AbacusLexerLPAREN = 20 + AbacusLexerRPAREN = 21 + AbacusLexerLSQPAREN = 22 + AbacusLexerRSQPAREN = 23 + AbacusLexerCONSTANT = 24 + AbacusLexerSCIENTIFIC_NUMBER = 25 + AbacusLexerVARIABLE = 26 + AbacusLexerLAMBDA_VARIABLE = 27 + AbacusLexerDIGITS = 28 + AbacusLexerUPPERCASE = 29 + AbacusLexerLOWERCASE = 30 + AbacusLexerWHITESPACE = 31 ) diff --git a/parser/abacus_listener.go b/parser/abacus_listener.go index 7eb64be..bed22b4 100644 --- a/parser/abacus_listener.go +++ b/parser/abacus_listener.go @@ -1,8 +1,8 @@ -// Code generated from Abacus.g4 by ANTLR 4.10.1. DO NOT EDIT. +// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. package parser // Abacus -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/antlr/antlr4/runtime/Go/antlr/v4" // AbacusListener is a complete listener for a parse tree produced by AbacusParser. type AbacusListener interface { @@ -116,77 +116,8 @@ type AbacusListener interface { // EnterMinusSign is called when entering the MinusSign production. EnterMinusSign(c *MinusSignContext) - // EnterSqrtFunction is called when entering the SqrtFunction production. - EnterSqrtFunction(c *SqrtFunctionContext) - - // EnterCbrtFunction is called when entering the CbrtFunction production. - EnterCbrtFunction(c *CbrtFunctionContext) - - // EnterLnFunction is called when entering the LnFunction production. - EnterLnFunction(c *LnFunctionContext) - - // EnterLogDefFunction is called when entering the LogDefFunction production. - EnterLogDefFunction(c *LogDefFunctionContext) - - // EnterLog2Function is called when entering the Log2Function production. - EnterLog2Function(c *Log2FunctionContext) - - // EnterLog10Function is called when entering the Log10Function production. - EnterLog10Function(c *Log10FunctionContext) - - // EnterFloorFunction is called when entering the FloorFunction production. - EnterFloorFunction(c *FloorFunctionContext) - - // EnterCeilFunction is called when entering the CeilFunction production. - EnterCeilFunction(c *CeilFunctionContext) - - // EnterExpFunction is called when entering the ExpFunction production. - EnterExpFunction(c *ExpFunctionContext) - - // EnterSinFunction is called when entering the SinFunction production. - EnterSinFunction(c *SinFunctionContext) - - // EnterCosFunction is called when entering the CosFunction production. - EnterCosFunction(c *CosFunctionContext) - - // EnterTanFunction is called when entering the TanFunction production. - EnterTanFunction(c *TanFunctionContext) - - // EnterRoundDefFunction is called when entering the RoundDefFunction production. - EnterRoundDefFunction(c *RoundDefFunctionContext) - - // EnterSignFunction is called when entering the SignFunction production. - EnterSignFunction(c *SignFunctionContext) - - // EnterAbsFunction is called when entering the AbsFunction production. - EnterAbsFunction(c *AbsFunctionContext) - - // EnterRound2Function is called when entering the Round2Function production. - EnterRound2Function(c *Round2FunctionContext) - - // EnterLogFunction is called when entering the LogFunction production. - EnterLogFunction(c *LogFunctionContext) - - // EnterMinFunction is called when entering the MinFunction production. - EnterMinFunction(c *MinFunctionContext) - - // EnterMaxFunction is called when entering the MaxFunction production. - EnterMaxFunction(c *MaxFunctionContext) - - // EnterAvgFunction is called when entering the AvgFunction production. - EnterAvgFunction(c *AvgFunctionContext) - - // EnterUntilFunction is called when entering the UntilFunction production. - EnterUntilFunction(c *UntilFunctionContext) - - // EnterFromFunction is called when entering the FromFunction production. - EnterFromFunction(c *FromFunctionContext) - - // EnterReverseFunction is called when entering the ReverseFunction production. - EnterReverseFunction(c *ReverseFunctionContext) - - // EnterNthFunction is called when entering the NthFunction production. - EnterNthFunction(c *NthFunctionContext) + // EnterFunctionInvocation is called when entering the FunctionInvocation production. + EnterFunctionInvocation(c *FunctionInvocationContext) // ExitRoot is called when exiting the root production. ExitRoot(c *RootContext) @@ -296,75 +227,6 @@ type AbacusListener interface { // ExitMinusSign is called when exiting the MinusSign production. ExitMinusSign(c *MinusSignContext) - // ExitSqrtFunction is called when exiting the SqrtFunction production. - ExitSqrtFunction(c *SqrtFunctionContext) - - // ExitCbrtFunction is called when exiting the CbrtFunction production. - ExitCbrtFunction(c *CbrtFunctionContext) - - // ExitLnFunction is called when exiting the LnFunction production. - ExitLnFunction(c *LnFunctionContext) - - // ExitLogDefFunction is called when exiting the LogDefFunction production. - ExitLogDefFunction(c *LogDefFunctionContext) - - // ExitLog2Function is called when exiting the Log2Function production. - ExitLog2Function(c *Log2FunctionContext) - - // ExitLog10Function is called when exiting the Log10Function production. - ExitLog10Function(c *Log10FunctionContext) - - // ExitFloorFunction is called when exiting the FloorFunction production. - ExitFloorFunction(c *FloorFunctionContext) - - // ExitCeilFunction is called when exiting the CeilFunction production. - ExitCeilFunction(c *CeilFunctionContext) - - // ExitExpFunction is called when exiting the ExpFunction production. - ExitExpFunction(c *ExpFunctionContext) - - // ExitSinFunction is called when exiting the SinFunction production. - ExitSinFunction(c *SinFunctionContext) - - // ExitCosFunction is called when exiting the CosFunction production. - ExitCosFunction(c *CosFunctionContext) - - // ExitTanFunction is called when exiting the TanFunction production. - ExitTanFunction(c *TanFunctionContext) - - // ExitRoundDefFunction is called when exiting the RoundDefFunction production. - ExitRoundDefFunction(c *RoundDefFunctionContext) - - // ExitSignFunction is called when exiting the SignFunction production. - ExitSignFunction(c *SignFunctionContext) - - // ExitAbsFunction is called when exiting the AbsFunction production. - ExitAbsFunction(c *AbsFunctionContext) - - // ExitRound2Function is called when exiting the Round2Function production. - ExitRound2Function(c *Round2FunctionContext) - - // ExitLogFunction is called when exiting the LogFunction production. - ExitLogFunction(c *LogFunctionContext) - - // ExitMinFunction is called when exiting the MinFunction production. - ExitMinFunction(c *MinFunctionContext) - - // ExitMaxFunction is called when exiting the MaxFunction production. - ExitMaxFunction(c *MaxFunctionContext) - - // ExitAvgFunction is called when exiting the AvgFunction production. - ExitAvgFunction(c *AvgFunctionContext) - - // ExitUntilFunction is called when exiting the UntilFunction production. - ExitUntilFunction(c *UntilFunctionContext) - - // ExitFromFunction is called when exiting the FromFunction production. - ExitFromFunction(c *FromFunctionContext) - - // ExitReverseFunction is called when exiting the ReverseFunction production. - ExitReverseFunction(c *ReverseFunctionContext) - - // ExitNthFunction is called when exiting the NthFunction production. - ExitNthFunction(c *NthFunctionContext) + // ExitFunctionInvocation is called when exiting the FunctionInvocation production. + ExitFunctionInvocation(c *FunctionInvocationContext) } diff --git a/parser/abacus_parser.go b/parser/abacus_parser.go index e0e3b73..365f8b8 100644 --- a/parser/abacus_parser.go +++ b/parser/abacus_parser.go @@ -1,4 +1,4 @@ -// Code generated from Abacus.g4 by ANTLR 4.10.1. DO NOT EDIT. +// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. package parser // Abacus @@ -7,7 +7,7 @@ import ( "strconv" "sync" - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/antlr/antlr4/runtime/Go/antlr/v4" ) // Suppress unused import errors @@ -33,19 +33,15 @@ var abacusParserStaticData struct { func abacusParserInit() { staticData := &abacusParserStaticData staticData.literalNames = []string{ - "", "'true'", "'false'", "':'", "','", "'sqrt'", "'cbrt'", "'ln'", "'log'", - "'log2'", "'log10'", "'floor'", "'ceil'", "'exp'", "'sin'", "'cos'", - "'tan'", "'round'", "'sign'", "'abs'", "'min'", "'max'", "'avg'", "'until'", - "'from'", "'reverse'", "'nth'", "'&&'", "'||'", "'xor'", "", "'='", - "'<'", "'>'", "", "", "'*'", "'/'", "'+'", "'-'", "'%'", "'.'", "'('", - "')'", "'['", "']'", + "", "'true'", "'false'", "':'", "','", "'&&'", "'||'", "'xor'", "", + "'='", "'<'", "'>'", "", "", "'*'", "'/'", "'+'", "'-'", "'%'", "'.'", + "'('", "')'", "'['", "']'", } staticData.symbolicNames = []string{ - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "AND", "OR", "XOR", "NOT", "EQ", - "LS", "GR", "ARROW", "POW", "MUL", "DIV", "ADD", "SUB", "PER", "POINT", - "LPAREN", "RPAREN", "LSQPAREN", "RSQPAREN", "CONSTANT", "SCIENTIFIC_NUMBER", - "VARIABLE", "LAMBDA_VARIABLE", "DIGITS", "UPPERCASE", "LOWERCASE", "WHITESPACE", + "", "", "", "", "", "AND", "OR", "XOR", "NOT", "EQ", "LS", "GR", "ARROW", + "POW", "MUL", "DIV", "ADD", "SUB", "PER", "POINT", "LPAREN", "RPAREN", + "LSQPAREN", "RSQPAREN", "CONSTANT", "SCIENTIFIC_NUMBER", "VARIABLE", + "LAMBDA_VARIABLE", "DIGITS", "UPPERCASE", "LOWERCASE", "WHITESPACE", } staticData.ruleNames = []string{ "root", "declaration", "boolExpression", "boolAtom", "lambda", "expression", @@ -54,7 +50,7 @@ func abacusParserInit() { } staticData.predictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 1, 53, 354, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, + 4, 1, 31, 229, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 42, 8, 0, 1, @@ -75,146 +71,87 @@ func abacusParserInit() { 3, 10, 195, 8, 10, 1, 10, 3, 10, 198, 8, 10, 1, 11, 1, 11, 1, 11, 3, 11, 203, 8, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 209, 8, 11, 1, 11, 3, 11, 212, 8, 11, 1, 12, 1, 12, 1, 12, 1, 12, 3, 12, 218, 8, 12, 1, 13, 1, 13, - 3, 13, 222, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, - 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, - 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, - 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, - 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, - 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, - 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, - 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, - 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, - 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, - 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, - 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, - 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 3, 14, 352, 8, 14, 1, 14, 0, 2, 4, 10, + 3, 13, 222, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 0, 2, 4, 10, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 0, 6, 1, 0, - 27, 29, 1, 0, 1, 2, 1, 0, 36, 37, 1, 0, 38, 39, 2, 0, 3, 3, 31, 31, 1, - 0, 48, 49, 402, 0, 41, 1, 0, 0, 0, 2, 50, 1, 0, 0, 0, 4, 91, 1, 0, 0, 0, - 6, 101, 1, 0, 0, 0, 8, 111, 1, 0, 0, 0, 10, 131, 1, 0, 0, 0, 12, 153, 1, - 0, 0, 0, 14, 159, 1, 0, 0, 0, 16, 174, 1, 0, 0, 0, 18, 180, 1, 0, 0, 0, - 20, 197, 1, 0, 0, 0, 22, 211, 1, 0, 0, 0, 24, 217, 1, 0, 0, 0, 26, 221, - 1, 0, 0, 0, 28, 351, 1, 0, 0, 0, 30, 31, 3, 2, 1, 0, 31, 32, 5, 0, 0, 1, - 32, 42, 1, 0, 0, 0, 33, 34, 3, 4, 2, 0, 34, 35, 5, 0, 0, 1, 35, 42, 1, - 0, 0, 0, 36, 37, 3, 18, 9, 0, 37, 38, 5, 0, 0, 1, 38, 42, 1, 0, 0, 0, 39, - 40, 5, 49, 0, 0, 40, 42, 5, 0, 0, 1, 41, 30, 1, 0, 0, 0, 41, 33, 1, 0, - 0, 0, 41, 36, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 42, 1, 1, 0, 0, 0, 43, 44, - 3, 22, 11, 0, 44, 45, 5, 31, 0, 0, 45, 46, 3, 18, 9, 0, 46, 51, 1, 0, 0, - 0, 47, 48, 5, 49, 0, 0, 48, 49, 5, 31, 0, 0, 49, 51, 3, 8, 4, 0, 50, 43, - 1, 0, 0, 0, 50, 47, 1, 0, 0, 0, 51, 3, 1, 0, 0, 0, 52, 53, 6, 2, -1, 0, - 53, 54, 3, 10, 5, 0, 54, 55, 5, 31, 0, 0, 55, 56, 5, 31, 0, 0, 56, 57, - 3, 10, 5, 0, 57, 92, 1, 0, 0, 0, 58, 59, 3, 10, 5, 0, 59, 60, 5, 32, 0, - 0, 60, 61, 3, 10, 5, 0, 61, 92, 1, 0, 0, 0, 62, 63, 3, 10, 5, 0, 63, 64, - 5, 33, 0, 0, 64, 65, 3, 10, 5, 0, 65, 92, 1, 0, 0, 0, 66, 71, 3, 10, 5, - 0, 67, 68, 5, 32, 0, 0, 68, 72, 5, 31, 0, 0, 69, 70, 5, 31, 0, 0, 70, 72, - 5, 32, 0, 0, 71, 67, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, - 73, 74, 3, 10, 5, 0, 74, 92, 1, 0, 0, 0, 75, 80, 3, 10, 5, 0, 76, 77, 5, - 33, 0, 0, 77, 81, 5, 31, 0, 0, 78, 79, 5, 31, 0, 0, 79, 81, 5, 33, 0, 0, - 80, 76, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 83, 3, - 10, 5, 0, 83, 92, 1, 0, 0, 0, 84, 85, 5, 30, 0, 0, 85, 92, 3, 4, 2, 3, - 86, 87, 5, 42, 0, 0, 87, 88, 3, 4, 2, 0, 88, 89, 5, 43, 0, 0, 89, 92, 1, - 0, 0, 0, 90, 92, 3, 6, 3, 0, 91, 52, 1, 0, 0, 0, 91, 58, 1, 0, 0, 0, 91, - 62, 1, 0, 0, 0, 91, 66, 1, 0, 0, 0, 91, 75, 1, 0, 0, 0, 91, 84, 1, 0, 0, - 0, 91, 86, 1, 0, 0, 0, 91, 90, 1, 0, 0, 0, 92, 98, 1, 0, 0, 0, 93, 94, - 10, 4, 0, 0, 94, 95, 7, 0, 0, 0, 95, 97, 3, 4, 2, 5, 96, 93, 1, 0, 0, 0, - 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 5, 1, - 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 102, 7, 1, 0, 0, 102, 7, 1, 0, 0, 0, - 103, 104, 3, 20, 10, 0, 104, 105, 5, 34, 0, 0, 105, 106, 3, 18, 9, 0, 106, - 112, 1, 0, 0, 0, 107, 108, 5, 42, 0, 0, 108, 109, 5, 43, 0, 0, 109, 110, - 5, 34, 0, 0, 110, 112, 3, 18, 9, 0, 111, 103, 1, 0, 0, 0, 111, 107, 1, - 0, 0, 0, 112, 9, 1, 0, 0, 0, 113, 114, 6, 5, -1, 0, 114, 115, 3, 26, 13, - 0, 115, 116, 3, 10, 5, 9, 116, 132, 1, 0, 0, 0, 117, 118, 5, 42, 0, 0, - 118, 119, 3, 10, 5, 0, 119, 120, 5, 43, 0, 0, 120, 132, 1, 0, 0, 0, 121, - 122, 5, 49, 0, 0, 122, 124, 5, 42, 0, 0, 123, 125, 3, 16, 8, 0, 124, 123, - 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 126, 1, 0, 0, 0, 126, 128, 5, 43, - 0, 0, 127, 129, 3, 14, 7, 0, 128, 127, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, - 129, 132, 1, 0, 0, 0, 130, 132, 3, 24, 12, 0, 131, 113, 1, 0, 0, 0, 131, - 117, 1, 0, 0, 0, 131, 121, 1, 0, 0, 0, 131, 130, 1, 0, 0, 0, 132, 150, - 1, 0, 0, 0, 133, 134, 10, 7, 0, 0, 134, 135, 5, 35, 0, 0, 135, 149, 3, - 10, 5, 8, 136, 137, 10, 6, 0, 0, 137, 138, 5, 40, 0, 0, 138, 139, 5, 40, - 0, 0, 139, 149, 3, 10, 5, 7, 140, 141, 10, 5, 0, 0, 141, 142, 7, 2, 0, - 0, 142, 149, 3, 10, 5, 6, 143, 144, 10, 4, 0, 0, 144, 145, 7, 3, 0, 0, - 145, 149, 3, 10, 5, 5, 146, 147, 10, 8, 0, 0, 147, 149, 5, 40, 0, 0, 148, - 133, 1, 0, 0, 0, 148, 136, 1, 0, 0, 0, 148, 140, 1, 0, 0, 0, 148, 143, - 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, 149, 152, 1, 0, 0, 0, 150, 148, 1, 0, - 0, 0, 150, 151, 1, 0, 0, 0, 151, 11, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, - 153, 154, 5, 48, 0, 0, 154, 157, 7, 4, 0, 0, 155, 158, 3, 4, 2, 0, 156, - 158, 3, 10, 5, 0, 157, 155, 1, 0, 0, 0, 157, 156, 1, 0, 0, 0, 158, 13, - 1, 0, 0, 0, 159, 168, 5, 44, 0, 0, 160, 165, 3, 12, 6, 0, 161, 162, 5, - 4, 0, 0, 162, 164, 3, 12, 6, 0, 163, 161, 1, 0, 0, 0, 164, 167, 1, 0, 0, - 0, 165, 163, 1, 0, 0, 0, 165, 166, 1, 0, 0, 0, 166, 169, 1, 0, 0, 0, 167, - 165, 1, 0, 0, 0, 168, 160, 1, 0, 0, 0, 168, 169, 1, 0, 0, 0, 169, 170, - 1, 0, 0, 0, 170, 171, 5, 45, 0, 0, 171, 15, 1, 0, 0, 0, 172, 175, 3, 10, - 5, 0, 173, 175, 5, 49, 0, 0, 174, 172, 1, 0, 0, 0, 174, 173, 1, 0, 0, 0, - 175, 178, 1, 0, 0, 0, 176, 177, 5, 4, 0, 0, 177, 179, 3, 16, 8, 0, 178, - 176, 1, 0, 0, 0, 178, 179, 1, 0, 0, 0, 179, 17, 1, 0, 0, 0, 180, 183, 3, - 10, 5, 0, 181, 182, 5, 4, 0, 0, 182, 184, 3, 18, 9, 0, 183, 181, 1, 0, - 0, 0, 183, 184, 1, 0, 0, 0, 184, 19, 1, 0, 0, 0, 185, 188, 7, 5, 0, 0, - 186, 187, 5, 4, 0, 0, 187, 189, 3, 20, 10, 0, 188, 186, 1, 0, 0, 0, 188, - 189, 1, 0, 0, 0, 189, 198, 1, 0, 0, 0, 190, 191, 5, 42, 0, 0, 191, 194, - 7, 5, 0, 0, 192, 193, 5, 4, 0, 0, 193, 195, 3, 20, 10, 0, 194, 192, 1, - 0, 0, 0, 194, 195, 1, 0, 0, 0, 195, 196, 1, 0, 0, 0, 196, 198, 5, 43, 0, - 0, 197, 185, 1, 0, 0, 0, 197, 190, 1, 0, 0, 0, 198, 21, 1, 0, 0, 0, 199, - 202, 5, 48, 0, 0, 200, 201, 5, 4, 0, 0, 201, 203, 3, 22, 11, 0, 202, 200, - 1, 0, 0, 0, 202, 203, 1, 0, 0, 0, 203, 212, 1, 0, 0, 0, 204, 205, 5, 42, - 0, 0, 205, 208, 5, 48, 0, 0, 206, 207, 5, 4, 0, 0, 207, 209, 3, 22, 11, - 0, 208, 206, 1, 0, 0, 0, 208, 209, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, - 212, 5, 43, 0, 0, 211, 199, 1, 0, 0, 0, 211, 204, 1, 0, 0, 0, 212, 23, - 1, 0, 0, 0, 213, 218, 3, 28, 14, 0, 214, 218, 5, 46, 0, 0, 215, 218, 5, - 47, 0, 0, 216, 218, 5, 48, 0, 0, 217, 213, 1, 0, 0, 0, 217, 214, 1, 0, - 0, 0, 217, 215, 1, 0, 0, 0, 217, 216, 1, 0, 0, 0, 218, 25, 1, 0, 0, 0, - 219, 222, 5, 38, 0, 0, 220, 222, 5, 39, 0, 0, 221, 219, 1, 0, 0, 0, 221, - 220, 1, 0, 0, 0, 222, 27, 1, 0, 0, 0, 223, 224, 5, 5, 0, 0, 224, 225, 5, - 42, 0, 0, 225, 226, 3, 10, 5, 0, 226, 227, 5, 43, 0, 0, 227, 352, 1, 0, - 0, 0, 228, 229, 5, 6, 0, 0, 229, 230, 5, 42, 0, 0, 230, 231, 3, 10, 5, - 0, 231, 232, 5, 43, 0, 0, 232, 352, 1, 0, 0, 0, 233, 234, 5, 7, 0, 0, 234, - 235, 5, 42, 0, 0, 235, 236, 3, 10, 5, 0, 236, 237, 5, 43, 0, 0, 237, 352, - 1, 0, 0, 0, 238, 239, 5, 8, 0, 0, 239, 240, 5, 42, 0, 0, 240, 241, 3, 10, - 5, 0, 241, 242, 5, 43, 0, 0, 242, 352, 1, 0, 0, 0, 243, 244, 5, 9, 0, 0, - 244, 245, 5, 42, 0, 0, 245, 246, 3, 10, 5, 0, 246, 247, 5, 43, 0, 0, 247, - 352, 1, 0, 0, 0, 248, 249, 5, 10, 0, 0, 249, 250, 5, 42, 0, 0, 250, 251, - 3, 10, 5, 0, 251, 252, 5, 43, 0, 0, 252, 352, 1, 0, 0, 0, 253, 254, 5, - 11, 0, 0, 254, 255, 5, 42, 0, 0, 255, 256, 3, 10, 5, 0, 256, 257, 5, 43, - 0, 0, 257, 352, 1, 0, 0, 0, 258, 259, 5, 12, 0, 0, 259, 260, 5, 42, 0, - 0, 260, 261, 3, 10, 5, 0, 261, 262, 5, 43, 0, 0, 262, 352, 1, 0, 0, 0, - 263, 264, 5, 13, 0, 0, 264, 265, 5, 42, 0, 0, 265, 266, 3, 10, 5, 0, 266, - 267, 5, 43, 0, 0, 267, 352, 1, 0, 0, 0, 268, 269, 5, 14, 0, 0, 269, 270, - 5, 42, 0, 0, 270, 271, 3, 10, 5, 0, 271, 272, 5, 43, 0, 0, 272, 352, 1, - 0, 0, 0, 273, 274, 5, 15, 0, 0, 274, 275, 5, 42, 0, 0, 275, 276, 3, 10, - 5, 0, 276, 277, 5, 43, 0, 0, 277, 352, 1, 0, 0, 0, 278, 279, 5, 16, 0, - 0, 279, 280, 5, 42, 0, 0, 280, 281, 3, 10, 5, 0, 281, 282, 5, 43, 0, 0, - 282, 352, 1, 0, 0, 0, 283, 284, 5, 17, 0, 0, 284, 285, 5, 42, 0, 0, 285, - 286, 3, 10, 5, 0, 286, 287, 5, 43, 0, 0, 287, 352, 1, 0, 0, 0, 288, 289, - 5, 18, 0, 0, 289, 290, 5, 42, 0, 0, 290, 291, 3, 10, 5, 0, 291, 292, 5, - 43, 0, 0, 292, 352, 1, 0, 0, 0, 293, 294, 5, 19, 0, 0, 294, 295, 5, 42, - 0, 0, 295, 296, 3, 10, 5, 0, 296, 297, 5, 43, 0, 0, 297, 352, 1, 0, 0, - 0, 298, 299, 5, 17, 0, 0, 299, 300, 5, 42, 0, 0, 300, 301, 3, 10, 5, 0, - 301, 302, 5, 4, 0, 0, 302, 303, 3, 10, 5, 0, 303, 304, 5, 43, 0, 0, 304, - 352, 1, 0, 0, 0, 305, 306, 5, 8, 0, 0, 306, 307, 5, 42, 0, 0, 307, 308, - 3, 10, 5, 0, 308, 309, 5, 4, 0, 0, 309, 310, 3, 10, 5, 0, 310, 311, 5, - 43, 0, 0, 311, 352, 1, 0, 0, 0, 312, 313, 5, 20, 0, 0, 313, 314, 5, 42, - 0, 0, 314, 315, 3, 18, 9, 0, 315, 316, 5, 43, 0, 0, 316, 352, 1, 0, 0, - 0, 317, 318, 5, 21, 0, 0, 318, 319, 5, 42, 0, 0, 319, 320, 3, 18, 9, 0, - 320, 321, 5, 43, 0, 0, 321, 352, 1, 0, 0, 0, 322, 323, 5, 22, 0, 0, 323, - 324, 5, 42, 0, 0, 324, 325, 3, 18, 9, 0, 325, 326, 5, 43, 0, 0, 326, 352, - 1, 0, 0, 0, 327, 328, 5, 23, 0, 0, 328, 329, 5, 42, 0, 0, 329, 330, 3, - 18, 9, 0, 330, 331, 5, 4, 0, 0, 331, 332, 3, 10, 5, 0, 332, 333, 5, 43, - 0, 0, 333, 352, 1, 0, 0, 0, 334, 335, 5, 24, 0, 0, 335, 336, 5, 42, 0, - 0, 336, 337, 3, 18, 9, 0, 337, 338, 5, 43, 0, 0, 338, 352, 1, 0, 0, 0, - 339, 340, 5, 25, 0, 0, 340, 341, 5, 42, 0, 0, 341, 342, 3, 18, 9, 0, 342, - 343, 5, 43, 0, 0, 343, 352, 1, 0, 0, 0, 344, 345, 5, 26, 0, 0, 345, 346, - 5, 42, 0, 0, 346, 347, 3, 18, 9, 0, 347, 348, 5, 4, 0, 0, 348, 349, 3, - 10, 5, 0, 349, 350, 5, 43, 0, 0, 350, 352, 1, 0, 0, 0, 351, 223, 1, 0, - 0, 0, 351, 228, 1, 0, 0, 0, 351, 233, 1, 0, 0, 0, 351, 238, 1, 0, 0, 0, - 351, 243, 1, 0, 0, 0, 351, 248, 1, 0, 0, 0, 351, 253, 1, 0, 0, 0, 351, - 258, 1, 0, 0, 0, 351, 263, 1, 0, 0, 0, 351, 268, 1, 0, 0, 0, 351, 273, - 1, 0, 0, 0, 351, 278, 1, 0, 0, 0, 351, 283, 1, 0, 0, 0, 351, 288, 1, 0, - 0, 0, 351, 293, 1, 0, 0, 0, 351, 298, 1, 0, 0, 0, 351, 305, 1, 0, 0, 0, - 351, 312, 1, 0, 0, 0, 351, 317, 1, 0, 0, 0, 351, 322, 1, 0, 0, 0, 351, - 327, 1, 0, 0, 0, 351, 334, 1, 0, 0, 0, 351, 339, 1, 0, 0, 0, 351, 344, - 1, 0, 0, 0, 352, 29, 1, 0, 0, 0, 27, 41, 50, 71, 80, 91, 98, 111, 124, - 128, 131, 148, 150, 157, 165, 168, 174, 178, 183, 188, 194, 197, 202, 208, - 211, 217, 221, 351, + 5, 7, 1, 0, 1, 2, 1, 0, 14, 15, 1, 0, 16, 17, 2, 0, 3, 3, 9, 9, 1, 0, 26, + 27, 254, 0, 41, 1, 0, 0, 0, 2, 50, 1, 0, 0, 0, 4, 91, 1, 0, 0, 0, 6, 101, + 1, 0, 0, 0, 8, 111, 1, 0, 0, 0, 10, 131, 1, 0, 0, 0, 12, 153, 1, 0, 0, + 0, 14, 159, 1, 0, 0, 0, 16, 174, 1, 0, 0, 0, 18, 180, 1, 0, 0, 0, 20, 197, + 1, 0, 0, 0, 22, 211, 1, 0, 0, 0, 24, 217, 1, 0, 0, 0, 26, 221, 1, 0, 0, + 0, 28, 223, 1, 0, 0, 0, 30, 31, 3, 2, 1, 0, 31, 32, 5, 0, 0, 1, 32, 42, + 1, 0, 0, 0, 33, 34, 3, 4, 2, 0, 34, 35, 5, 0, 0, 1, 35, 42, 1, 0, 0, 0, + 36, 37, 3, 18, 9, 0, 37, 38, 5, 0, 0, 1, 38, 42, 1, 0, 0, 0, 39, 40, 5, + 27, 0, 0, 40, 42, 5, 0, 0, 1, 41, 30, 1, 0, 0, 0, 41, 33, 1, 0, 0, 0, 41, + 36, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 42, 1, 1, 0, 0, 0, 43, 44, 3, 22, 11, + 0, 44, 45, 5, 9, 0, 0, 45, 46, 3, 18, 9, 0, 46, 51, 1, 0, 0, 0, 47, 48, + 5, 27, 0, 0, 48, 49, 5, 9, 0, 0, 49, 51, 3, 8, 4, 0, 50, 43, 1, 0, 0, 0, + 50, 47, 1, 0, 0, 0, 51, 3, 1, 0, 0, 0, 52, 53, 6, 2, -1, 0, 53, 54, 3, + 10, 5, 0, 54, 55, 5, 9, 0, 0, 55, 56, 5, 9, 0, 0, 56, 57, 3, 10, 5, 0, + 57, 92, 1, 0, 0, 0, 58, 59, 3, 10, 5, 0, 59, 60, 5, 10, 0, 0, 60, 61, 3, + 10, 5, 0, 61, 92, 1, 0, 0, 0, 62, 63, 3, 10, 5, 0, 63, 64, 5, 11, 0, 0, + 64, 65, 3, 10, 5, 0, 65, 92, 1, 0, 0, 0, 66, 71, 3, 10, 5, 0, 67, 68, 5, + 10, 0, 0, 68, 72, 5, 9, 0, 0, 69, 70, 5, 9, 0, 0, 70, 72, 5, 10, 0, 0, + 71, 67, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 74, 3, + 10, 5, 0, 74, 92, 1, 0, 0, 0, 75, 80, 3, 10, 5, 0, 76, 77, 5, 11, 0, 0, + 77, 81, 5, 9, 0, 0, 78, 79, 5, 9, 0, 0, 79, 81, 5, 11, 0, 0, 80, 76, 1, + 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 83, 3, 10, 5, 0, 83, + 92, 1, 0, 0, 0, 84, 85, 5, 8, 0, 0, 85, 92, 3, 4, 2, 3, 86, 87, 5, 20, + 0, 0, 87, 88, 3, 4, 2, 0, 88, 89, 5, 21, 0, 0, 89, 92, 1, 0, 0, 0, 90, + 92, 3, 6, 3, 0, 91, 52, 1, 0, 0, 0, 91, 58, 1, 0, 0, 0, 91, 62, 1, 0, 0, + 0, 91, 66, 1, 0, 0, 0, 91, 75, 1, 0, 0, 0, 91, 84, 1, 0, 0, 0, 91, 86, + 1, 0, 0, 0, 91, 90, 1, 0, 0, 0, 92, 98, 1, 0, 0, 0, 93, 94, 10, 4, 0, 0, + 94, 95, 7, 0, 0, 0, 95, 97, 3, 4, 2, 5, 96, 93, 1, 0, 0, 0, 97, 100, 1, + 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 5, 1, 0, 0, 0, 100, + 98, 1, 0, 0, 0, 101, 102, 7, 1, 0, 0, 102, 7, 1, 0, 0, 0, 103, 104, 3, + 20, 10, 0, 104, 105, 5, 12, 0, 0, 105, 106, 3, 18, 9, 0, 106, 112, 1, 0, + 0, 0, 107, 108, 5, 20, 0, 0, 108, 109, 5, 21, 0, 0, 109, 110, 5, 12, 0, + 0, 110, 112, 3, 18, 9, 0, 111, 103, 1, 0, 0, 0, 111, 107, 1, 0, 0, 0, 112, + 9, 1, 0, 0, 0, 113, 114, 6, 5, -1, 0, 114, 115, 3, 26, 13, 0, 115, 116, + 3, 10, 5, 9, 116, 132, 1, 0, 0, 0, 117, 118, 5, 20, 0, 0, 118, 119, 3, + 10, 5, 0, 119, 120, 5, 21, 0, 0, 120, 132, 1, 0, 0, 0, 121, 122, 5, 27, + 0, 0, 122, 124, 5, 20, 0, 0, 123, 125, 3, 16, 8, 0, 124, 123, 1, 0, 0, + 0, 124, 125, 1, 0, 0, 0, 125, 126, 1, 0, 0, 0, 126, 128, 5, 21, 0, 0, 127, + 129, 3, 14, 7, 0, 128, 127, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 132, + 1, 0, 0, 0, 130, 132, 3, 24, 12, 0, 131, 113, 1, 0, 0, 0, 131, 117, 1, + 0, 0, 0, 131, 121, 1, 0, 0, 0, 131, 130, 1, 0, 0, 0, 132, 150, 1, 0, 0, + 0, 133, 134, 10, 7, 0, 0, 134, 135, 5, 13, 0, 0, 135, 149, 3, 10, 5, 8, + 136, 137, 10, 6, 0, 0, 137, 138, 5, 18, 0, 0, 138, 139, 5, 18, 0, 0, 139, + 149, 3, 10, 5, 7, 140, 141, 10, 5, 0, 0, 141, 142, 7, 2, 0, 0, 142, 149, + 3, 10, 5, 6, 143, 144, 10, 4, 0, 0, 144, 145, 7, 3, 0, 0, 145, 149, 3, + 10, 5, 5, 146, 147, 10, 8, 0, 0, 147, 149, 5, 18, 0, 0, 148, 133, 1, 0, + 0, 0, 148, 136, 1, 0, 0, 0, 148, 140, 1, 0, 0, 0, 148, 143, 1, 0, 0, 0, + 148, 146, 1, 0, 0, 0, 149, 152, 1, 0, 0, 0, 150, 148, 1, 0, 0, 0, 150, + 151, 1, 0, 0, 0, 151, 11, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 153, 154, 5, + 26, 0, 0, 154, 157, 7, 4, 0, 0, 155, 158, 3, 4, 2, 0, 156, 158, 3, 10, + 5, 0, 157, 155, 1, 0, 0, 0, 157, 156, 1, 0, 0, 0, 158, 13, 1, 0, 0, 0, + 159, 168, 5, 22, 0, 0, 160, 165, 3, 12, 6, 0, 161, 162, 5, 4, 0, 0, 162, + 164, 3, 12, 6, 0, 163, 161, 1, 0, 0, 0, 164, 167, 1, 0, 0, 0, 165, 163, + 1, 0, 0, 0, 165, 166, 1, 0, 0, 0, 166, 169, 1, 0, 0, 0, 167, 165, 1, 0, + 0, 0, 168, 160, 1, 0, 0, 0, 168, 169, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, + 170, 171, 5, 23, 0, 0, 171, 15, 1, 0, 0, 0, 172, 175, 3, 10, 5, 0, 173, + 175, 5, 27, 0, 0, 174, 172, 1, 0, 0, 0, 174, 173, 1, 0, 0, 0, 175, 178, + 1, 0, 0, 0, 176, 177, 5, 4, 0, 0, 177, 179, 3, 16, 8, 0, 178, 176, 1, 0, + 0, 0, 178, 179, 1, 0, 0, 0, 179, 17, 1, 0, 0, 0, 180, 183, 3, 10, 5, 0, + 181, 182, 5, 4, 0, 0, 182, 184, 3, 18, 9, 0, 183, 181, 1, 0, 0, 0, 183, + 184, 1, 0, 0, 0, 184, 19, 1, 0, 0, 0, 185, 188, 7, 5, 0, 0, 186, 187, 5, + 4, 0, 0, 187, 189, 3, 20, 10, 0, 188, 186, 1, 0, 0, 0, 188, 189, 1, 0, + 0, 0, 189, 198, 1, 0, 0, 0, 190, 191, 5, 20, 0, 0, 191, 194, 7, 5, 0, 0, + 192, 193, 5, 4, 0, 0, 193, 195, 3, 20, 10, 0, 194, 192, 1, 0, 0, 0, 194, + 195, 1, 0, 0, 0, 195, 196, 1, 0, 0, 0, 196, 198, 5, 21, 0, 0, 197, 185, + 1, 0, 0, 0, 197, 190, 1, 0, 0, 0, 198, 21, 1, 0, 0, 0, 199, 202, 5, 26, + 0, 0, 200, 201, 5, 4, 0, 0, 201, 203, 3, 22, 11, 0, 202, 200, 1, 0, 0, + 0, 202, 203, 1, 0, 0, 0, 203, 212, 1, 0, 0, 0, 204, 205, 5, 20, 0, 0, 205, + 208, 5, 26, 0, 0, 206, 207, 5, 4, 0, 0, 207, 209, 3, 22, 11, 0, 208, 206, + 1, 0, 0, 0, 208, 209, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, 212, 5, 21, + 0, 0, 211, 199, 1, 0, 0, 0, 211, 204, 1, 0, 0, 0, 212, 23, 1, 0, 0, 0, + 213, 218, 3, 28, 14, 0, 214, 218, 5, 24, 0, 0, 215, 218, 5, 25, 0, 0, 216, + 218, 5, 26, 0, 0, 217, 213, 1, 0, 0, 0, 217, 214, 1, 0, 0, 0, 217, 215, + 1, 0, 0, 0, 217, 216, 1, 0, 0, 0, 218, 25, 1, 0, 0, 0, 219, 222, 5, 16, + 0, 0, 220, 222, 5, 17, 0, 0, 221, 219, 1, 0, 0, 0, 221, 220, 1, 0, 0, 0, + 222, 27, 1, 0, 0, 0, 223, 224, 5, 26, 0, 0, 224, 225, 5, 20, 0, 0, 225, + 226, 3, 18, 9, 0, 226, 227, 5, 21, 0, 0, 227, 29, 1, 0, 0, 0, 26, 41, 50, + 71, 80, 91, 98, 111, 124, 128, 131, 148, 150, 157, 165, 168, 174, 178, + 183, 188, 194, 197, 202, 208, 211, 217, 221, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -245,7 +182,7 @@ func NewAbacusParser(input antlr.TokenStream) *AbacusParser { this.RuleNames = staticData.ruleNames this.LiteralNames = staticData.literalNames this.SymbolicNames = staticData.symbolicNames - this.GrammarFileName = "Abacus.g4" + this.GrammarFileName = "java-escape" return this } @@ -257,55 +194,33 @@ const ( AbacusParserT__1 = 2 AbacusParserT__2 = 3 AbacusParserT__3 = 4 - AbacusParserT__4 = 5 - AbacusParserT__5 = 6 - AbacusParserT__6 = 7 - AbacusParserT__7 = 8 - AbacusParserT__8 = 9 - AbacusParserT__9 = 10 - AbacusParserT__10 = 11 - AbacusParserT__11 = 12 - AbacusParserT__12 = 13 - AbacusParserT__13 = 14 - AbacusParserT__14 = 15 - AbacusParserT__15 = 16 - AbacusParserT__16 = 17 - AbacusParserT__17 = 18 - AbacusParserT__18 = 19 - AbacusParserT__19 = 20 - AbacusParserT__20 = 21 - AbacusParserT__21 = 22 - AbacusParserT__22 = 23 - AbacusParserT__23 = 24 - AbacusParserT__24 = 25 - AbacusParserT__25 = 26 - AbacusParserAND = 27 - AbacusParserOR = 28 - AbacusParserXOR = 29 - AbacusParserNOT = 30 - AbacusParserEQ = 31 - AbacusParserLS = 32 - AbacusParserGR = 33 - AbacusParserARROW = 34 - AbacusParserPOW = 35 - AbacusParserMUL = 36 - AbacusParserDIV = 37 - AbacusParserADD = 38 - AbacusParserSUB = 39 - AbacusParserPER = 40 - AbacusParserPOINT = 41 - AbacusParserLPAREN = 42 - AbacusParserRPAREN = 43 - AbacusParserLSQPAREN = 44 - AbacusParserRSQPAREN = 45 - AbacusParserCONSTANT = 46 - AbacusParserSCIENTIFIC_NUMBER = 47 - AbacusParserVARIABLE = 48 - AbacusParserLAMBDA_VARIABLE = 49 - AbacusParserDIGITS = 50 - AbacusParserUPPERCASE = 51 - AbacusParserLOWERCASE = 52 - AbacusParserWHITESPACE = 53 + AbacusParserAND = 5 + AbacusParserOR = 6 + AbacusParserXOR = 7 + AbacusParserNOT = 8 + AbacusParserEQ = 9 + AbacusParserLS = 10 + AbacusParserGR = 11 + AbacusParserARROW = 12 + AbacusParserPOW = 13 + AbacusParserMUL = 14 + AbacusParserDIV = 15 + AbacusParserADD = 16 + AbacusParserSUB = 17 + AbacusParserPER = 18 + AbacusParserPOINT = 19 + AbacusParserLPAREN = 20 + AbacusParserRPAREN = 21 + AbacusParserLSQPAREN = 22 + AbacusParserRSQPAREN = 23 + AbacusParserCONSTANT = 24 + AbacusParserSCIENTIFIC_NUMBER = 25 + AbacusParserVARIABLE = 26 + AbacusParserLAMBDA_VARIABLE = 27 + AbacusParserDIGITS = 28 + AbacusParserUPPERCASE = 29 + AbacusParserLOWERCASE = 30 + AbacusParserWHITESPACE = 31 ) // AbacusParser rules. @@ -1789,7 +1704,7 @@ func (p *AbacusParser) boolExpression(_p int) (localctx IBoolExpressionContext) _la = p.GetTokenStream().LA(1) - if !(((_la)&-(0x1f+1)) == 0 && ((1<