Permalink
Browse files

ExpressionSample - fix parsing of numeric AND/OR expressions in parens

  • Loading branch information...
bobbymcr committed Apr 16, 2018
1 parent b73f861 commit e8f14f1255d4b90191c19b023fce32faf2f2f6b8
@@ -48,6 +48,8 @@ public void TypeMismatch(string input)
[InlineData("(1=2)", "Eq(NumL(1), NumL(2))")]
[InlineData("(X=234)", "Eq(NumV(X), NumL(234))")]
[InlineData("(X(234)=YZ1234)", "Eq(NumA(X, NumL(234)), NumV(YZ1234))")]
[InlineData("(X)=Y", "Eq(NumV(X), NumV(Y))")]
[InlineData("X=(Y)", "Eq(NumV(X), NumV(Y))")]
[Theory]
public void WithParens(string input, string output)
{
@@ -68,6 +70,10 @@ public void WithThreeTerms(string input, string output)
[InlineData("Z+1=X-Y", "Eq(Add(NumV(Z), NumL(1)), Sub(NumV(X), NumV(Y)))")]
[InlineData("(Z*1)=(X^Y)", "Eq(Mult(NumV(Z), NumL(1)), Pow(NumV(X), NumV(Y)))")]
[InlineData("Z*1=X^Y", "Eq(Mult(NumV(Z), NumL(1)), Pow(NumV(X), NumV(Y)))")]
[InlineData("(X AND 1)=Y", "Eq(And(NumV(X), NumL(1)), NumV(Y))")]
[InlineData("(X OR 1)=Y", "Eq(Or(NumV(X), NumL(1)), NumV(Y))")]
[InlineData("Y=(X AND 1)", "Eq(NumV(Y), And(NumV(X), NumL(1)))")]
[InlineData("Y=(X OR 1)", "Eq(NumV(Y), Or(NumV(X), NumL(1)))")]
[Theory]
public void WithOtherOperations(string input, string output)
{
@@ -22,6 +22,7 @@ public void ValidGoto(string input, string output)
[InlineData("IF 1 THEN X$=\"ok\"", "If(NumL(1), Assign(StrV(X), StrL(\"ok\")))")]
[InlineData("IF X THEN GOTO 1", "If(NumV(X), Goto(1))")]
[InlineData("IF X=1 THEN PRINT \"ok\"", "If(Eq(NumV(X), NumL(1)), Print(StrL(\"ok\")))")]
[InlineData("IF (OB(I) AND 127)=R THEN PRINT \" \";OB$(I)", "If(Eq(And(NumA(OB, NumV(I)), NumL(127)), NumV(R)), Print(StrL(\" \"), StrA(OB, NumV(I))))")]
[Theory]
public void ValidNonGoto(string input, string output)
{
@@ -286,7 +286,13 @@ private static class Num
from x in Add.Token()
select BasicOperator.Unary("Not", x);
private static readonly Parser<BasicExpression> Root = Not.Or(Relational);
private static readonly Parser<BasicExpression> And =
Parse.ChainOperator(Op.And, Not.Or(Relational), Op.Apply);
private static readonly Parser<BasicExpression> Or =
Parse.ChainOperator(Op.Or, And, Op.Apply);
private static readonly Parser<BasicExpression> Root = Or;
}
private static class Op

0 comments on commit e8f14f1

Please sign in to comment.