public void monadicEachOperatorTest2() { string input = "| each {(5;-2.7;-Inf)}"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Monadic operator Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.EachOperator( Node.Token(Tokens.ABSOLUTEVALUE, "|"), Node.Strand( Node.ConstantList( Node.IntConstant("5") ), Node.ConstantList( Node.FloatConstant("-2.7") ), Node.ConstantList( Node.InfConstant("-Inf") ) ) ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void MonadicFunction1() { string input = "+*%- 1 2 3 4.0"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Monadic Parsing FAILED!"); ConstantList floatList = Node.ConstantList(Node.IntConstant("1")); floatList.AddLast(Node.IntConstant("2")); floatList.AddLast(Node.IntConstant("3")); floatList.AddLast(Node.FloatConstant("4.0")); Node expectedTree = Node.ExpressionList(Node.ExpressionList( Node.MonadicFunction(Node.Token(Tokens.IDENTITY), Node.MonadicFunction(Node.Token(Tokens.SIGN), Node.MonadicFunction(Node.Token(Tokens.RECIPROCAL), Node.MonadicFunction(Node.Token(Tokens.NEGATE), floatList ) ) ) ) )); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void dyadicEachOperatorTest2() { string input = "(3;4) <= each (8;1)"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Dyadic operator Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.EachOperator( Node.Token(Tokens.LTE, "<="), Node.Strand( Node.ConstantList( Node.IntConstant("3") ), Node.ConstantList( Node.IntConstant("4") ) ), Node.Strand( Node.ConstantList( Node.IntConstant("8") ), Node.ConstantList( Node.IntConstant("1") ) ) ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void ExpressionListTestB() { string input = "+{(2);4 5}; -{(12)}; { 1;3;\n4;5}"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Expression List Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.DyadicFunction( Node.Token(Tokens.ADD, "+"), Node.ConstantList(Node.IntConstant("2")), Node.ConstantList(Node.IntConstant("4"), Node.IntConstant("5")) ), Node.MonadicFunction( Node.Token(Tokens.NEGATE, "-"), Node.ConstantList(Node.IntConstant("12")) ), Node.ExpressionList( Node.ConstantList(Node.IntConstant("1")), Node.ConstantList(Node.IntConstant("3")), Node.ConstantList(Node.IntConstant("4")), Node.ConstantList(Node.IntConstant("5")) ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void dyadicEachOperatorTest1() { string input = "3 ((f[0])each) 7"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Dyadic operator Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.EachOperator( Node.Indexing( Node.Identifier("f", IdentifierType.UnQualifiedName), Node.ExpressionList( Node.ConstantList( Node.IntConstant("0") ) ) ), Node.ConstantList( Node.IntConstant("3") ), Node.ConstantList( Node.IntConstant("7") ) ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void MonadicFunction4() { string input = "(iota 3 4)[1; 1 3]"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Monadic Parsing FAILED!"); Node expectedTree = Node.ExpressionList( Node.ExpressionList( Node.Indexing( Node.MonadicFunction( Node.Token(Tokens.INTERVAL, "iota"), Node.ConstantList( Node.IntConstant("3"), Node.IntConstant("4") ) ), Node.ExpressionList( Node.ConstantList( Node.IntConstant("1") ), Node.ConstantList( Node.IntConstant("1"), Node.IntConstant("3") ) ) ) ) ); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void DyadicFunction3() { string input = " {g} >= 2 * %{2}"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Dyadic Parsing FAILED!"); Node expectedTree = Node.ExpressionList( Node.ExpressionList( Node.DyadicFunction( Node.Token(Tokens.GTE), Node.ExpressionList( Node.Identifier("g", IdentifierType.UnQualifiedName) ), Node.DyadicFunction( Node.Token(Tokens.MULTIPLY), Node.ConstantList( Node.IntConstant("2") ), Node.MonadicFunction( Node.Token(Tokens.RECIPROCAL), Node.ConstantList( Node.IntConstant("2") ) ) ) ) ) ); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void monadicOperatorTest1() { string input = "+/ 5 6 , */ 45 6"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Monadic operator Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.MonadicFunction( Node.Token(Tokens.RADD, "+/"), Node.DyadicFunction( Node.Token(Tokens.CATENATE, ","), Node.ConstantList( Node.IntConstant("5"), Node.IntConstant("6") ), Node.MonadicFunction( Node.Token(Tokens.RMULTIPLY, "*/"), Node.ConstantList( Node.IntConstant("45"), Node.IntConstant("6") ) ) ) ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void ConditionalTestB() { string line = "1 + if (x <7) else 11"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsTrue(parser.Parse(), "Conditional Parsing FAILED!"); #region expected AST Node expectedTree = Node.ExpressionList(Node.ExpressionList( Node.DyadicFunction(Node.Token(Tokens.ADD), Node.ConstantList(Node.IntConstant("1")), Node.IfElse( Node.DyadicFunction(Node.Token(Tokens.LT), Node.UnQualifiedName("x"), Node.ConstantList(Node.IntConstant("7")) ), Node.NullConstant(), Node.ConstantList(Node.IntConstant("11")) ) ) )); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void FloatConstantListTest() { string input = "-3. .12 -2.2 4e2 -2.1e2 4.1e+4 .2.2.23.4 Inf -Inf"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Float list parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.ConstantList( Node.FloatConstant("-3."), Node.FloatConstant(".12"), Node.FloatConstant("-2.2"), Node.FloatConstant("4e2"), Node.FloatConstant("-2.1e2"), Node.FloatConstant("4.1e+4"), Node.FloatConstant(".2"), Node.FloatConstant(".2"), Node.FloatConstant(".23"), Node.FloatConstant(".4"), Node.InfConstant("Inf"), Node.InfConstant("-Inf") ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void UserDefinedFunctionCall() { string input = "f{a.g;'abc'[1];(3.4;_h)}"; AplusParser parser = TestUtils.BuildASCIIParser(input); Node expectedTree = Node.ExpressionList( Node.ExpressionList( Node.UserDefInvoke( Node.Identifier("f", IdentifierType.UnQualifiedName), Node.ExpressionList( Node.Identifier("a.g", IdentifierType.QualifiedName), Node.Indexing( Node.SingeQuotedConstant("abc"), Node.ExpressionList( Node.ConstantList( Node.IntConstant("1") ) ) ), Node.Strand( Node.ConstantList( Node.FloatConstant("3.4") ), Node.Identifier("_h", IdentifierType.SystemName) ) ) ) ) ); Assert.IsTrue(parser.Parse(), "Dyadic Parsing FAILED!"); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void UserDefOperatorIncorrect() { string line = "a (f x) : 1"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsFalse(parser.Parse(), "User Defined Operator Parsing should fail here"); }
public void MiscellaneousFunction() { string input = "4 + + + 5"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Dyadic Parsing FAILED!"); Node expectedTree = Node.ExpressionList(Node.ExpressionList( Node.DyadicFunction( Node.Token(Tokens.ADD, "+"), Node.ConstantList( Node.IntConstant("4") ), Node.MonadicFunction( Node.Token(Tokens.IDENTITY, "+"), Node.MonadicFunction( Node.Token(Tokens.IDENTITY, "+"), Node.ConstantList( Node.IntConstant("5") ) ) ) ) )); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void IntConstantListTest() { string input = "2 5 6 [2]"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Indexed int list parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.Indexing( Node.ConstantList( Node.IntConstant("2"), Node.IntConstant("5"), Node.IntConstant("6") ), Node.ExpressionList( Node.ConstantList( Node.IntConstant("2") ) ) ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void SingeQuotedKanaKanjiConstantTest() { string input = "'こんにちは世界'"; string expectedText = "こんにちは世界"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Singe quoted constant input parse FAILED"); ExpressionList expectedNodeA = Node.ExpressionList( Node.ExpressionList( Node.SingeQuotedConstant(expectedText) ) ); ExpressionList expectedNodeB = Node.ExpressionList( Node.ExpressionList( // for Single quoted characters remove the leading and trailing ' new Constant(expectedText, ConstantType.CharacterConstant) ) ); Assert.AreEqual(expectedNodeA, parser.Tree, "Invalid Node created! (Helper method used)"); Assert.AreEqual(expectedNodeB, parser.Tree, "Invalid Node created!"); Assert.IsTrue(parser.Tree == expectedNodeA, "Operator == Compare Failed!"); }
public void DoubleQuotedConstantTest() { string input = "\"@tes\\11st\""; string expectedText = "@tes\tst"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Double quoted constant input parse FAILED"); ExpressionList expectedNodeA = Node.ExpressionList( Node.ExpressionList( Node.DoubleQuotedConstant(expectedText) ) ); Assert.AreEqual(expectedNodeA, parser.Tree, "Invalid Node created! (Helper method used)"); Assert.IsTrue(parser.Tree == expectedNodeA, "Operator == Compare Failed!"); }
public void StrandTest1() { string input = "(;`3s`ss1`122[1];-Inf;_g;a.b[0 1];c;)"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Strand parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.Strand( Node.NullConstant(), Node.Indexing( Node.ConstantList( Node.SymbolConstant("3s"), Node.SymbolConstant("ss1"), Node.SymbolConstant("122") ), Node.ExpressionList( Node.ConstantList( Node.IntConstant("1") ) ) ), Node.ConstantList( Node.InfConstant("-Inf") ), Node.Identifier("_g", IdentifierType.SystemName), Node.Indexing( Node.Identifier("a.b", IdentifierType.QualifiedName), Node.ExpressionList( Node.ConstantList( Node.IntConstant("0"), Node.IntConstant("1") ) ) ), Node.Identifier("c", IdentifierType.UnQualifiedName), Node.NullConstant() ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void ANTLRLexerBugTest() { string input = "\"ABCDEFGHIJKLMONPRSTUVWYZ abcdefghijklmnopqrstuvwyz 0123456789\""; string expectedStr = "ABCDEFGHIJKLMONPRSTUVWYZ abcdefghijklmnopqrstuvwyz 0123456789"; AplusParser parser = TestUtils.BuildASCIIParser(input); // If this throws an exception (MismatchedSetException) then we ran into the bug.. Assert.IsTrue(parser.Parse(), "ANTLR Bug test failed parsing"); ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.DoubleQuotedConstant(expectedStr) ) ); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void UserDefOneLineB() { string line = "f{}: \n5"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsTrue(parser.Parse(), "User Defined Function Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.UserDefFunction( Node.UnQualifiedName("f"), Node.ExpressionList(), Node.ConstantList(Node.IntConstant("5")) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void DyadicFunction2() { string input = "(3 ,2) < (3,6) + 1 8"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Dyadic Parsing FAILED!"); Node expectedTree = Node.ExpressionList( Node.ExpressionList( Node.DyadicFunction( Node.Token(Tokens.LT), Node.DyadicFunction( Node.Token(Tokens.CATENATE), Node.ConstantList( Node.IntConstant("3") ), Node.ConstantList( Node.IntConstant("2") ) ), Node.DyadicFunction( Node.Token(Tokens.ADD), Node.DyadicFunction( Node.Token(Tokens.CATENATE), Node.ConstantList( Node.IntConstant("3") ), Node.ConstantList( Node.IntConstant("6") ) ), Node.ConstantList( Node.IntConstant("1"), Node.IntConstant("8") ) ) ) ) ); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void InfinityConstantTest() { string input = "Inf -Inf Inf"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Float input parse FAILED"); ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.ConstantList( Node.InfConstant("Inf"), Node.InfConstant("-Inf"), Node.InfConstant("Inf") ) ) ); Assert.AreEqual(expectedTree, parser.Tree, "Invalid Node created! (Helper method used)"); Assert.IsTrue(parser.Tree == expectedTree, "Operator == Compare Failed!"); }
public void GeneralFunctionOnLeftTest() { string input = "+{1;2} - 3"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Dyadic Parsing FAILED!"); Node expectedTree = Node.ExpressionList(Node.ExpressionList( Node.DyadicFunction( Node.Token(Tokens.SUBTRACT, "-"), Node.DyadicFunction(Node.Token(Tokens.ADD), Node.ConstantList(Node.IntConstant("1")), Node.ConstantList(Node.IntConstant("2")) ), Node.ConstantList(Node.IntConstant("3")) ) )); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void MonadicDoTest() { string line = "do { 3;4 }"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsTrue(parser.Parse(), "Monadic Do Parsing FAILED!"); #region expected AST Node expectedTree = Node.ExpressionList(Node.ExpressionList( Node.MonadicDo( Node.ExpressionList( Node.ConstantList(Node.IntConstant("3")), Node.ConstantList(Node.IntConstant("4")) ) ) )); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void MonadicFunction3() { string input = "|{-76}"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Monadic Parsing FAILED!"); Node expectedTree = Node.ExpressionList( Node.ExpressionList( Node.MonadicFunction( Node.Token(Tokens.ABSOLUTEVALUE, "|"), Node.ConstantList( Node.IntConstant("-76") ) ) ) ); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void MultiLineStrandTest() { string input = "(3;\n'hello')"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Strand parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.Strand( Node.ConstantList(Node.IntConstant("3")), Node.SingeQuotedConstant("hello") ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void UserDefOperatorMonadicMonadic() { string line = "(f x) a :1"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsTrue(parser.Parse(), "User Defined Operator Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.MonadicUserDefOperator( Node.UnQualifiedName("x"), Node.UnQualifiedName("f"), Node.UnQualifiedName("a"), Node.ConstantList(Node.IntConstant("1")), line ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void WhileTestA() { string line = "while x <7"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsTrue(parser.Parse(), "Conditional Parsing FAILED!"); #region expected AST Node expectedTree = Node.ExpressionList(Node.ExpressionList( Node.While( Node.UnQualifiedName("x"), Node.MonadicFunction( Node.Token(Tokens.ENCLOSE, "<"), Node.ConstantList(Node.IntConstant("7")) ) ) )); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void UserDefMultiLineB() { string line = "f{\nc\n}: -c"; AplusParser parser = TestUtils.BuildASCIIParser(line); Assert.IsTrue(parser.Parse(), "User Defined Function Parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.UserDefFunction( Node.UnQualifiedName("f"), Node.ExpressionList(Node.UnQualifiedName("c")), Node.MonadicFunction(Node.Token(Tokens.NEGATE, "-"), Node.UnQualifiedName("c")) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void SymbolConstantListTest() { string input = "`see1_2.1 `_2.2 `"; AplusParser parser = TestUtils.BuildASCIIParser(input); Assert.IsTrue(parser.Parse(), "Symbol constant list parsing FAILED!"); #region expected AST ExpressionList expectedTree = Node.ExpressionList( Node.ExpressionList( Node.ConstantList( Node.SymbolConstant("see1_2.1"), Node.SymbolConstant("_2.2"), Node.SymbolConstant("") ) ) ); #endregion Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }
public void MonadicUserDefInfixInvoke() { string input = "f 2"; AplusParser parser = TestUtils.BuildASCIIParser(input); parser.FunctionInfo = new AplusCore.Compiler.FunctionInformation("."); parser.FunctionInfo.RegisterGlobalFunction(".f"); Node expectedTree = Node.ExpressionList( Node.ExpressionList( Node.UserDefInvoke( Node.Identifier("f", IdentifierType.UnQualifiedName), Node.ExpressionList( Node.ConstantList(Node.IntConstant("2")) ) ) ) ); Assert.IsTrue(parser.Parse(), "Parsing of infix invocation of user defined function failed"); Assert.AreEqual(expectedTree, parser.Tree, "Incorrect AST generated!"); }