Skip to content

Commit

Permalink
#236 - Rework parser (remove RPN)
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Jan 12, 2020
1 parent c929a2d commit 7231e51
Show file tree
Hide file tree
Showing 129 changed files with 2,993 additions and 3,564 deletions.
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "xFunc.Benchmark",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build",
"program": "${workspaceFolder}/xFunc.Benchmark/bin/Debug/netcoreapp2.2/xFunc.Benchmark.dll",
"args": [],
"cwd": "${workspaceFolder}/xFunc.Benchmark",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "xFunc.DotnetTool",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build",
"program": "${workspaceFolder}/xFunc.DotnetTool/bin/Debug/netcoreapp2.1/xFunc.DotnetTool.dll",
"args": [],
"cwd": "${workspaceFolder}/xFunc.DotnetTool",
"console": "integratedTerminal",
"stopAtEntry": false
}
]
}
50 changes: 50 additions & 0 deletions xFunc Grammar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# It's just a reference grammar for xFunc (The implementaion is not completely equal to grammar).

statement = unaryAssign
/ binaryAssign
/ assign
/ exp

unaryAssign = variable ('++' / '--')
binaryAssign = variable ('+=' / '-=' / '*=' / '/=') exp
assign = (functionDeclaration / variable) ':=' exp

exp = binary
binary = conditional

conditional = bitwise (('&&' / '||') bitwise)*
bitwise = equality (('&' / 'and' / '|' / 'or' / 'xor' / '=>' / '->' / 'impl' / '<=>' / '<->' / 'eq' / 'nor' / 'nand') equality)*
equality = addSub (('==' / '!=' / '<' / '<=' / '>' / '>=') addSub)*
addSub = mulDivMod (('+' / '-') mulDivMod)*
mulDivMod = mulImplicit (('*' / '/' / '%') mulImplicit)*
mulImplicit = '-'* number rightUnary / leftUnary
leftUnary = ('~' / '-')* exponentiation
exponentiation = rightUnary ('^' exponentiation)*
rightUnary = operand '!'*

operand = number
/ vector
/ matrix
/ function
/ variable
/ boolean
/ bracketExp

digitWithoutZero = [1-9]
digit = [0] / digitWithoutZero
letter = [a-z]

number = digitWithoutZero (digit)*
id = letter (digit / letter)*
variable = id
boolean = 'true' / 'false'

bracketExp = '(' exp ')'

function = id '(' parameters ')'
parameters = (statement (',' statement)*)*

vector = 'vector' ('{' / '(') parameters ('}' / ')')
matrix = 'matrix' ('{' / '(') vector (',' vector) ('}' / ')')

functionDeclaration = id '(' (variable (',' variable)* / '') ')'
14 changes: 14 additions & 0 deletions xFunc.Benchmark/Benchmarks/LexerBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using xFunc.Maths.Tokenization;
Expand Down
102 changes: 54 additions & 48 deletions xFunc.Benchmark/Benchmarks/ParserBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using BenchmarkDotNet.Attributes;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
using xFunc.Maths;
using xFunc.Maths.Expressions;
Expand All @@ -23,102 +37,94 @@ public void Setup()

// (100.1 + 2(3sin(4cos(5tan(6ctg(10x)))) * 3) / (func(a, b, c) ^ 2)) - (cos(y) - 111.3) & (true | false -> true <-> false) + (det({{1, 2}, {3, 4}}) * 10log(2, 3))
tokens = new TokensBuilder()
.OpenBracket()
.OpenParenthesis()
.Number(100.1)
.Operation(Operations.Addition)
.Number(2)
.Operation(Operations.Multiplication)
.OpenBracket()
.OpenParenthesis()
.Number(3)
.Operation(Operations.Multiplication)
.Function(Functions.Sine, 1)
.OpenBracket()
.Id("sin")
.OpenParenthesis()
.Number(4)
.Operation(Operations.Multiplication)
.Function(Functions.Cosine, 1)
.OpenBracket()
.Id("cos")
.OpenParenthesis()
.Number(5)
.Operation(Operations.Multiplication)
.Function(Functions.Tangent, 1)
.OpenBracket()
.Id("tan")
.OpenParenthesis()
.Number(6)
.Operation(Operations.Multiplication)
.Function(Functions.Cotangent, 1)
.OpenBracket()
.Id("cot")
.OpenParenthesis()
.Number(10)
.Operation(Operations.Multiplication)
.VariableX()
.CloseBracket()
.CloseBracket()
.CloseBracket()
.CloseBracket()
.CloseParenthesis()
.CloseParenthesis()
.CloseParenthesis()
.CloseParenthesis()
.Operation(Operations.Multiplication)
.Number(3)
.CloseBracket()
.CloseParenthesis()
.Operation(Operations.Division)
.OpenBracket()
.UserFunction("func", 3)
.OpenBracket()
.Variable("a")
.OpenParenthesis()
.Id("func")
.OpenParenthesis()
.Id("a")
.Comma()
.Variable("b")
.Id("b")
.Comma()
.Variable("c")
.CloseBracket()
.Id("c")
.CloseParenthesis()
.Operation(Operations.Exponentiation)
.Number(2)
.CloseBracket()
.CloseBracket()
.CloseParenthesis()
.CloseParenthesis()
.Operation(Operations.Subtraction)
.OpenBracket()
.Function(Functions.Cosine, 1)
.OpenBracket()
.OpenParenthesis()
.Id("cos")
.OpenParenthesis()
.VariableY()
.CloseBracket()
.CloseParenthesis()
.Operation(Operations.Subtraction)
.Number(111.3)
.CloseBracket()
.CloseParenthesis()
.Operation(Operations.And)
.OpenBracket()
.OpenParenthesis()
.True()
.Operation(Operations.Or)
.False()
.Operation(Operations.Implication)
.True()
.Operation(Operations.Equality)
.False()
.CloseBracket()
.CloseParenthesis()
.Operation(Operations.Addition)
.OpenBracket()
.Function(Functions.Determinant, 1)
.OpenBracket()
.Function(Functions.Matrix, 2)
.OpenParenthesis()
.Id("det")
.OpenParenthesis()
.OpenBrace()
.Function(Functions.Vector, 2)
.OpenBrace()
.Number(1)
.Comma()
.Number(2)
.CloseBrace()
.Comma()
.Function(Functions.Vector, 2)
.OpenBrace()
.Number(3)
.Comma()
.Number(4)
.CloseBrace()
.CloseBrace()
.CloseBracket()
.CloseParenthesis()
.Operation(Operations.Multiplication)
.Number(10)
.Operation(Operations.Multiplication)
.Function(Functions.Log, 2)
.OpenBracket()
.Id("log")
.OpenParenthesis()
.Number(2)
.Comma()
.Number(3)
.CloseBracket()
.CloseBracket()
.CloseParenthesis()
.CloseParenthesis()
.Tokens;
}

Expand Down
16 changes: 15 additions & 1 deletion xFunc.Benchmark/Benchmarks/ProcessorBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using BenchmarkDotNet.Attributes;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using BenchmarkDotNet.Attributes;
using xFunc.Maths;
using xFunc.Maths.Expressions;

Expand Down
16 changes: 15 additions & 1 deletion xFunc.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using BenchmarkDotNet.Configs;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
Expand Down
1 change: 1 addition & 0 deletions xFunc.Benchmark/xFunc.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 15 additions & 1 deletion xFunc.DotnetTool/Options/BaseOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using CommandLine;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using CommandLine;

namespace xFunc.DotnetTool.Options
{
Expand Down
16 changes: 15 additions & 1 deletion xFunc.DotnetTool/Options/DebugInfoOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using CommandLine;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using CommandLine;

namespace xFunc.DotnetTool.Options
{
Expand Down
16 changes: 15 additions & 1 deletion xFunc.DotnetTool/Options/InteractiveOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using CommandLine;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using CommandLine;
using CommandLine.Text;
using System.Collections.Generic;

Expand Down
16 changes: 15 additions & 1 deletion xFunc.DotnetTool/Options/ParseOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using CommandLine;
// Copyright 2012-2019 Dmitry Kischenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using CommandLine;
using CommandLine.Text;
using System.Collections.Generic;

Expand Down

0 comments on commit 7231e51

Please sign in to comment.