Skip to content

Commit 90ab5de

Browse files
removed comparison expression and added factorial
1 parent 4e6eda5 commit 90ab5de

21 files changed

+130
-171
lines changed

ExpressionTest/TokenizerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void TestEveryTokenType()
3333
AssertTokensMatch("false", Token(TokenType.False, "false", 0), Token(TokenType.EndOfFile, "", 5));
3434
AssertTokensMatch("365", Token(TokenType.Numeric, "365", 0), Token(TokenType.EndOfFile, "", 3));
3535
AssertTokensMatch("x", Token(TokenType.Identifier, "x", 0), Token(TokenType.EndOfFile, "", 1));
36-
AssertTokensMatch("!", Token(TokenType.Unknown, "!", 0), Token(TokenType.EndOfFile, "", 1));
36+
AssertTokensMatch("!", Token(TokenType.Exclamation, "!", 0), Token(TokenType.EndOfFile, "", 1));
3737
AssertTokensMatch(" ", Token(TokenType.WhiteSpace, " ", 0), Token(TokenType.EndOfFile, "", 2));
3838
AssertTokensMatch("\t ", Token(TokenType.WhiteSpace, "\t ", 0), Token(TokenType.EndOfFile, "", 2));
3939
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Demo: https://ci.appveyor.com/api/projects/timmi-on-rails/mathparser/artifacts/D
44

55
TODO
66
faculty !
7-
modulo %
7+
88
vector algebra
9-
evaluate stuff like "3x+2"
109

1110
not 100% confident with the Identifier solution

shunting_yard/MathParser.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
<Compile Include="src\expressions\PostfixExpressionType.cs" />
5757
<Compile Include="src\parser\Associativity.cs" />
5858
<Compile Include="src\expressions\TernaryExpression.cs" />
59-
<Compile Include="src\expressions\ComparisonExpression.cs" />
60-
<Compile Include="src\expressions\ComparisonExpressionType.cs" />
6159
<Compile Include="src\expressions\FunctionAssignmentExpression.cs" />
6260
<Compile Include="src\visitors\BottomUpExpressionVisitor.cs" />
6361
<Compile Include="src\visitors\AssignVisitor.cs" />
@@ -75,7 +73,6 @@
7573
<Compile Include="src\parser\parselets\PostfixOperatorParselet.cs" />
7674
<Compile Include="src\parser\parselets\PrefixOperatorParselet.cs" />
7775
<Compile Include="src\parser\parselets\BinaryOperatorParselet.cs" />
78-
<Compile Include="src\parser\parselets\ComparisonParselet.cs" />
7976
<Compile Include="src\parser\parselets\GroupParselet.cs" />
8077
<Compile Include="src\parser\parselets\TernaryParselet.cs" />
8178
<Compile Include="src\parser\parselets\NumberParselet.cs" />

shunting_yard/src/expressions/BinaryExpressionType.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ enum BinaryExpressionType
77
Multiplication,
88
Division,
99
Power,
10-
Modulo
10+
Modulo,
11+
Equal,
12+
NotEqual,
13+
Less,
14+
LessOrEqual,
15+
Greater,
16+
GreaterOrEqual
1117
}
1218
}

shunting_yard/src/expressions/CallExpression.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ namespace MathParser
55
{
66
class CallExpression : IExpression
77
{
8-
public string FunctionName { get; }
8+
public IExpression FunctionExpression { get; }
99

1010
public IEnumerable<IExpression> Arguments { get; }
1111

12-
public CallExpression(string functionName, IEnumerable<IExpression> arguments)
12+
public CallExpression(IExpression functionExpression, IEnumerable<IExpression> arguments)
1313
{
14-
FunctionName = functionName;
14+
FunctionExpression = functionExpression;
1515
Arguments = arguments.ToArray();
1616
}
1717

1818
public void Accept(IExpressionVisitor visitor)
1919
{
20-
visitor.Traverse(() => visitor.Visit(this), Arguments.ToArray());
20+
IExpression[] children = new[] { FunctionExpression }.Concat(Arguments).ToArray();
21+
visitor.Traverse(() => visitor.Visit(this), children);
2122
}
2223
}
2324
}

shunting_yard/src/expressions/ComparisonExpression.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

shunting_yard/src/expressions/ComparisonExpressionType.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

shunting_yard/src/expressions/PostfixExpressionType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
{
33
enum PostfixExpressionType
44
{
5+
Factorial
56
}
67
}

shunting_yard/src/expressions/TernaryExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
class TernaryExpression : IExpression
44
{
5-
public IExpression Condition { get; } //differ between value expressions and conditionexpressions?! or is condition just some value
5+
public IExpression Condition { get; }
66

77
public IExpression TrueCase { get; }
88

shunting_yard/src/expressions/Value.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static Value Boolean(bool b)
5757
{
5858
return new Value(ValueType.Boolean, b);
5959
}
60-
60+
// TODO function with identifier and argument names
6161
public static Value Function(Function function)
6262
{
6363
return new Value(ValueType.Function, function);

0 commit comments

Comments
 (0)