public void RecognisesLetStatementWithMoreComplexExpression() { classUnderTest.AddToSymbolTable("y", IdentifierKind.Var, null); classUnderTest.AddToSymbolTable("x", IdentifierKind.Field, null); classUnderTest.AddToSymbolTable("finished", IdentifierKind.Field, null); classUnderTest.ParseLetStatement() .ShouldGenerateXml(@" <letStatement> <keyword>let</keyword> <identifier kind='var' isDefinition='false' number='0'>y</identifier> <symbol>[</symbol> <expression> <term> <identifier kind='field' isDefinition='false' number='0'>x</identifier> </term> <symbol>+</symbol> <term> <integerConstant>1</integerConstant> </term> </expression> <symbol>]</symbol> <symbol>=</symbol> <expression> <term> <symbol>~</symbol> <term> <identifier kind='field' isDefinition='false' number='1'>finished</identifier> </term> </term> </expression> <symbol>;</symbol> </letStatement> "); }
public void Setup() { classUnderTest = new Grammarian(); classUnderTest.LoadTokens( new Token(NodeType.Keyword, "do"), new Token(NodeType.Identifier, "myClass"), new Token(NodeType.Symbol, "."), new Token(NodeType.Identifier, "something"), new Token(NodeType.Symbol, "("), new Token(NodeType.IntegerConstant, "5"), new Token(NodeType.Symbol, "+"), new Token(NodeType.IntegerConstant, "3"), new Token(NodeType.Symbol, ","), new Token(NodeType.Identifier, "blah"), new Token(NodeType.Symbol, ")"), new Token(NodeType.Symbol, ";") ); classUnderTest.AddToSymbolTable("blah", IdentifierKind.Argument, null); classUnderTest.AddToSymbolTable("myClass", IdentifierKind.Field, "MyClass"); }
public void Setup() { classUnderTest = new Grammarian(); classUnderTest.LoadTokens( new Token(NodeType.Keyword, "while"), new Token(NodeType.Symbol, "("), new Token(NodeType.Identifier, "inProgress"), new Token(NodeType.Symbol, ")"), new Token(NodeType.Symbol, "{"), new Token(NodeType.Keyword, "let"), new Token(NodeType.Identifier, "x"), new Token(NodeType.Symbol, "="), new Token(NodeType.Identifier, "y"), new Token(NodeType.Symbol, ";"), new Token(NodeType.Symbol, "}") ); classUnderTest.AddToSymbolTable("x", IdentifierKind.Var, null); classUnderTest.AddToSymbolTable("y", IdentifierKind.Var, null); classUnderTest.AddToSymbolTable("inProgress", IdentifierKind.Field, null); }
public void Setup() { classUnderTest = new Grammarian(); classUnderTest.LoadTokens( new Token(NodeType.Keyword, "let"), new Token(NodeType.Identifier, "x"), new Token(NodeType.Symbol, "="), new Token(NodeType.IntegerConstant, "1234"), new Token(NodeType.Symbol, ";") ); classUnderTest.AddToSymbolTable("x", IdentifierKind.Var, null); }
public void Setup() { classUnderTest = new Grammarian(); classUnderTest.LoadTokens( new Token(NodeType.Keyword, "do"), new Token(NodeType.Identifier, "something"), new Token(NodeType.Symbol, "("), new Token(NodeType.Identifier, "x"), new Token(NodeType.Symbol, ")"), new Token(NodeType.Symbol, ";") ); classUnderTest.AddToSymbolTable("x", IdentifierKind.Var, null); }
public void ParsesCorrectlyWithoutAnElseBlock() { classUnderTest.LoadTokens(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14); classUnderTest.AddToSymbolTable("x", IdentifierKind.Static, null); classUnderTest.ParseIfStatement().ShouldGenerateXml(@" <ifStatement> <keyword>if</keyword> <symbol>(</symbol> <expression> <term> <symbol>(</symbol> <expression> <term> <identifier kind='static' isDefinition='false' number='0'>x</identifier> </term> <symbol>*</symbol> <term> <integerConstant>5</integerConstant> </term> </expression> <symbol>)</symbol> </term> <symbol>></symbol> <term> <integerConstant>30</integerConstant> </term> </expression> <symbol>)</symbol> <symbol>{</symbol> <statements> <returnStatement> <keyword>return</keyword> <symbol>;</symbol> </returnStatement> </statements> <symbol>}</symbol> </ifStatement> "); }
public void ShouldParseCorrectlyWithReturnExpression() { classUnderTest.LoadTokens(t1, t2, t3); classUnderTest.AddToSymbolTable("result", IdentifierKind.Var, "ResultClass"); classUnderTest .ParseReturnStatement() .ShouldGenerateXml(@" <returnStatement> <keyword>return</keyword> <expression> <term> <identifier kind='var' isDefinition='false' number='0' classType='ResultClass'>result</identifier> </term> </expression> <symbol>;</symbol> </returnStatement> "); }