public void TestCallHasParameter() { Parser parser = new Parser ( TestModule.GetTestKernel() ); parser.Parse ( GetBlockCallTokens () ); Variable variable = parser.MainBlock[1] as Variable; Assert.IsInstanceOfType( typeof(ArrayExpr), variable.Parameters ); }
static Block ParseIf() { var tokens = GetIf (); IKernel kernel = TestModule.GetTestKernel (); Block block = new Parser ( kernel ).Parse ( tokens ); return block; }
public void ParseNestedBlockTest() { Tokens tokens = new Tokens (); tokens.AddTokens ( new string[] { "x", "=", "{", "if", "x", "==", "5", "{", "print", "x", "}", "}", "print", "x" } ); Parser parser = new Parser ( TestModule.GetTestKernel () ); Block block = parser.Parse ( tokens ); Assert.AreEqual ( 2, block.Count, "Should be two statements, one assign, one print"); }
public void TestCallEvaluatesParameters() { Parser parser = new Parser ( TestModule.GetTestKernel() ); parser.Parse ( GetBlockCallTokens () ); Variable variable = parser.MainBlock[1] as Variable; Dynamic parameters = variable.Parameters.Evaluate(); Assert.AreEqual ( DynamicType.arrayType, parameters.Type ); }
public void ParseBlockAssignment() { Tokens tokens = new Tokens (); tokens.AddTokens ( new string[] { "x", "=", "{", "print", "'bong'", "}" } ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( typeof ( Assign ), parser.MainBlock[0] ); Assign ass = parser.MainBlock[0] as Assign; Assert.IsInstanceOfType ( typeof ( Block ), ass.Expr ); }
public void TestCallPassesParameters() { IKernel kernel = TestModule.GetTestKernel(); Parser parser = new Parser ( kernel ); parser.Parse ( GetBlockCallTokens () ); new Executor ( parser.MainBlock ); // It should give give us the correct value in standard out StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy; Assert.AreEqual ( "yay", output.Text ); }
public void ParseBlockCall() { Tokens tokens = new Tokens (); tokens.AddTokens ( new string[] { "x", "=", "{", "print", "'bong'", "}", "x" } ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( typeof ( Assign ), parser.MainBlock[0] ); Assert.IsInstanceOfType ( typeof ( Variable ), parser.MainBlock[1] ); Assert.AreEqual ( "x", (parser.MainBlock[1] as Variable).Ident ); }
public void TestBlockPassesAsParameter() { Tokens tokens = new Tokens(); tokens.AddTokens(new string[] {"x", "(", "{", "print", "'yay'","}",")"}); IKernel kernel = TestModule.GetTestKernel(); Parser parser = new Parser ( kernel ); parser.Parse ( tokens ); Variable variable = parser.MainBlock[0] as Variable; ArrayExpr array = variable.Parameters; Assert.AreEqual ( 1, array.Elements.Count, "Should only be one parameter" ); Assert.IsInstanceOfType ( typeof(Block), array.Elements[0] ); }
public void Run( Stream program ) { Scanner scanner = new Scanner ( program ); try { Parser parser = new Parser ( _kernel ); Block block = parser.Parse( scanner.Tokens ); block.Execute (); } catch ( ParseException ex ) { Console.WriteLine ( ex.Message ); } }
public void TestParseArrayIndex() { Tokens tokens = new Tokens(); tokens.AddToken("x"); tokens.AddToken("["); tokens.AddToken("0"); tokens.AddToken("]"); Parser parser = new Parser ( TestModule.GetTestKernel() ); parser.Parse ( tokens ); Variable variable = parser.MainBlock[0] as Variable; Dynamic indexer = variable.Indexer.Evaluate (); Assert.AreEqual(0, indexer.NumberValue, "Indexer should evaluate to 0"); }
public void ExpressionAssignmentTest() { Tokens tokens = new Tokens (); tokens.Add ( new Token ( "ong" ) ); tokens.Add ( new Token ( "=" ) ); tokens.Add ( new Token ( "bong" ) ); tokens.Add ( new Token ( "+" ) ); tokens.Add ( new Token ( "10" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); ArithExpr expression = (ArithExpr)( (Assign)parser.MainBlock[0] ).Expr; Assert.IsInstanceOfType ( typeof ( Variable ), expression.Left); Assert.AreEqual ( ArithOp.Add, expression.Op ); Assert.AreEqual ( 10, ((NumberLiteral) expression.Right).Value ); }
public void ParseBlockAssignment() { List<Token> tokens = new List<Token> (); tokens.Add ( new Token ( "x" ) ); tokens.Add ( new Token ( "=" ) ); tokens.Add ( new Token ( "{" ) ); tokens.Add ( new Token ( ">" ) ); tokens.Add ( new Token ( "'bong'" ) ); tokens.Add ( new Token ( "}" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( parser.Statements[0], typeof ( Assign ) ); Assign ass = parser.Statements[0] as Assign; Assert.IsInstanceOfType ( ass.Expr, typeof ( Block ) ); }
public void StringLiteralPrintTest() { Tokens tokens = new Tokens (); tokens.Add ( new Token ( "print" ) ); tokens.Add ( new Token ( "'ongle'" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( typeof ( Print ), parser.MainBlock[0] ); Print print = (Print)parser.MainBlock[0]; Assert.IsInstanceOfType ( typeof ( StringLiteral ), print.Expr ); Assert.AreEqual ( ((StringLiteral)print.Expr).Value, "ongle" ); }
public void ParsePrintAddingStringsTest() { List<Token> tokens = new List<Token> (); tokens.Add ( new Token ( ">" ) ); tokens.Add ( new Token ( "'ongle'" ) ); tokens.Add ( new Token ( "+" ) ); tokens.Add ( new Token ( "'ooog'" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( ( (Print)parser.Statements[0] ).Expr, typeof ( ArithExpr ) ); }
public void ParsePrintAddingStringsTest() { Tokens tokens = new Tokens (); tokens.Add ( new Token ( "print" ) ); tokens.Add ( new Token ( "'ongle'" ) ); tokens.Add ( new Token ( "+" ) ); tokens.Add ( new Token ( "'ooog'" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( typeof ( ArithExpr ), ( (Print)parser.MainBlock[0] ).Expr ); }
public void ParseSimplePrintTest() { List<Token> tokens = new List<Token>(); tokens.Add(new Token(">")); tokens.Add(new Token("'ongle'")); Parser parser = new Parser ( TestModule.GetTestKernel() ); parser.Parse ( tokens ); Assert.AreEqual(1, parser.Statements.Count); Assert.IsInstanceOfType ( parser.Statements[0], typeof ( Print ) ); }
public void StringLiteralPrintTest() { List<Token> tokens = new List<Token> (); tokens.Add ( new Token ( ">" ) ); tokens.Add ( new Token ( "'ongle'" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( parser.Statements[0], typeof ( Print ) ); Print print = (Print)parser.Statements[0]; Assert.IsInstanceOfType ( print.Expr, typeof ( StringLiteral ) ); Assert.AreEqual ( ((StringLiteral)print.Expr).Value, "ongle" ); }
private static Parser ParseSimpleIf() { Tokens tokens = new Tokens (); tokens.Add ( new Token ( "if" ) ); tokens.Add ( new Token ( "x" ) ); tokens.Add ( new Token ( "==" ) ); tokens.Add ( new Token ( "5" ) ); tokens.Add ( new Token ( "{" ) ); tokens.Add ( new Token ( "print" ) ); tokens.Add ( new Token ( "'yay'" ) ); tokens.Add ( new Token ( "}" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); return parser; }
public void VariableAssignmentTest() { List<Token> tokens = new List<Token> (); tokens.Add ( new Token ( "ong" ) ); tokens.Add ( new Token ( "=" ) ); tokens.Add ( new Token ( "10" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.AreEqual ( 1, parser.Statements.Count ); Assert.IsInstanceOfType ( parser.Statements[0], typeof ( Assign ) ); Assert.AreEqual ( ((Assign)parser.Statements[0]).Ident, "ong" ); }
public void ParseSimplePrintTest() { Tokens tokens = new Tokens(); tokens.Add(new Token("print")); tokens.Add(new Token("'ongle'")); Parser parser = new Parser ( TestModule.GetTestKernel() ); parser.Parse ( tokens ); Assert.AreEqual(1, parser.MainBlock.Count); Assert.IsInstanceOfType ( typeof ( Print ), parser.MainBlock[0] ); }
public void ParseBlockCall() { List<Token> tokens = new List<Token> (); tokens.Add ( new Token ( "x" ) ); tokens.Add ( new Token ( "=" ) ); tokens.Add ( new Token ( "{" ) ); tokens.Add ( new Token ( ">" ) ); tokens.Add ( new Token ( "'bong'" ) ); tokens.Add ( new Token ( "}" ) ); tokens.Add ( new Token ( "x" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.IsInstanceOfType ( parser.Statements[1], typeof ( Variable ) ); Assert.AreEqual ( "x", (parser.Statements[1] as Variable).Ident ); }
//[TestMethod ()] //public void ParseSimpleIfHasCorrectExpressionTest () //{ // Parser parser = ParseSimpleIf (); // Assert.AreEqual ( 1, parser.Statements.Count ); // Assert.IsInstanceOfType ( (parser.Statements[0] as If).Test, typeof ( Comparison ) ); //} private static Parser ParseSimpleIf() { List<Token> tokens = new List<Token> (); tokens.Add ( new Token ( "?" ) ); tokens.Add ( new Token ( "x" ) ); tokens.Add ( new Token ( "==" ) ); tokens.Add ( new Token ( "5" ) ); tokens.Add ( new Token ( ">" ) ); tokens.Add ( new Token ( "'yay'" ) ); tokens.Add ( new Token ( "." ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); return parser; }
public void VariableAssignmentTest() { Tokens tokens = new Tokens (); tokens.Add ( new Token ( "ong" ) ); tokens.Add ( new Token ( "=" ) ); tokens.Add ( new Token ( "10" ) ); Parser parser = new Parser ( TestModule.GetTestKernel () ); parser.Parse ( tokens ); Assert.AreEqual ( 1, parser.MainBlock.Count ); Assert.IsInstanceOfType ( typeof ( Assign ), parser.MainBlock[0] ); Assign assign = parser.MainBlock[0] as Assign; Assert.IsInstanceOfType ( typeof ( Variable ), assign.Ident ); Assert.AreEqual ( ((Variable)assign.Ident).Ident, "ong" ); }
public void TestParseVariableWithArrayIndexExpression() { Tokens tokens = new Tokens(); tokens.AddToken("x"); tokens.AddToken("["); tokens.AddToken("0"); tokens.AddToken("+"); tokens.AddToken("4"); tokens.AddToken("]"); Parser parser = new Parser ( TestModule.GetTestKernel() ); parser.Parse ( tokens ); Assert.AreEqual(1, parser.MainBlock.Count); Assert.IsInstanceOfType ( typeof ( Variable ), parser.MainBlock[0] ); }