public void ReturnsASubroutineDeclaration()
 {
     classUnderTest
     .LoadTokens(sd1, sd2, sd3, sd4, sd5, sd6, sd7, sd8, sd9, sd10, sd11, sd12)
     .ParseSubroutineDeclaration()
     .ShouldGenerateXml(@"
         <subroutineDec>
             <keyword>constructor</keyword>
             <keyword>void</keyword>
             <identifier>doSomething</identifier>
             <symbol>(</symbol>
             <parameterList>
                 <keyword>int</keyword>
                 <identifier>x</identifier>
                 <symbol>,</symbol>
                 <identifier>Game</identifier>
                 <identifier>game</identifier>
             </parameterList>
             <symbol>)</symbol>
             <subroutineBody>
                 <symbol>{</symbol>
                 <symbol>}</symbol>
             </subroutineBody>
         </subroutineDec>
     ");
 }
示例#2
0
 public void ReturnsASubroutineDeclaration()
 {
     classUnderTest
     .LoadTokens(sd1, sd2, sd3, sd4, sd5, sd6, sd7, sd8, sd9, sd10, sd11, sd12)
     .ParseSubroutineDeclaration()
     .ShouldGenerateXml(@"
         <subroutineDec>
             <keyword>constructor</keyword>
             <keyword>void</keyword>
             <identifier kind='subroutine' isDefinition='true'>doSomething</identifier>
             <symbol>(</symbol>
             <parameterList>
                 <keyword>int</keyword>
                 <identifier kind='argument' isDefinition='true' number='0'>x</identifier>
                 <symbol>,</symbol>
                 <identifier kind='class' isDefinition='false'>Game</identifier>
                 <identifier kind='argument' isDefinition='true' number='1' classType='Game'>game</identifier>
             </parameterList>
             <symbol>)</symbol>
             <subroutineBody>
                 <symbol>{</symbol>
                 <symbol>}</symbol>
             </subroutineBody>
         </subroutineDec>
     ");
 }
示例#3
0
 public void ReturnsAClassNode()
 {
     classUnderTest.LoadTokens(t1, t2, t3, t4).ParseClass().ShouldGenerateXml(@"
         <class>
           <keyword>class</keyword>
           <identifier kind='class' isDefinition='true'>blah</identifier>
           <symbol>{</symbol>
           <symbol>}</symbol>
         </class>");
 }
示例#4
0
 public void ShouldParseCorrectlyWithNoReturnValue()
 {
     classUnderTest.LoadTokens(t1, t3)
     .ParseReturnStatement()
     .ShouldGenerateXml(@"
             <returnStatement>
                 <keyword>return</keyword>
                 <symbol>;</symbol>
             </returnStatement>
         ");
 }
示例#5
0
 public void RecognisesStaticClassVariableDeclaration()
 {
     classUnderTest
     .LoadTokens(cvd1, cvd2, cvd3, cvd4, cvd5, cvd6)
     .ParseClassVariableDeclaration()
     .ShouldGenerateXml(@"
           <classVarDec>
             <keyword>static</keyword>
             <keyword>boolean</keyword>
             <identifier kind='static' isDefinition='true' number='0'>hasStarted</identifier>
             <symbol>,</symbol>
             <identifier kind='static' isDefinition='true' number='1'>hasFinished</identifier>
             <symbol>;</symbol>
           </classVarDec>
     ");
 }
示例#6
0
 public void ShouldResetSubroutineSymbolTable()
 {
     classUnderTest
     .LoadTokens(tokens)
     .ParseClass()
     .ShouldGenerateXml(@"
             <class>
                 <keyword>class</keyword>
                 <identifier kind='class' isDefinition='true'>MyClass</identifier>
                 <symbol>{</symbol>
                 <subroutineDec>
                     <keyword>function</keyword>
                     <keyword>void</keyword>
                     <identifier kind='subroutine' isDefinition='true'>doSomething</identifier>
                     <symbol>(</symbol>
                     <parameterList>
                         <keyword>int</keyword>
                         <identifier kind='argument' number='0' isDefinition='true'>x</identifier>
                     </parameterList>
                     <symbol>)</symbol>
                     <subroutineBody>
                         <symbol>{</symbol>
                         <varDec>
                             <keyword>var</keyword>
                             <keyword>boolean</keyword>
                             <identifier kind='var' number='0' isDefinition='true'>hasStarted</identifier>
                             <symbol>;</symbol>
                         </varDec>
                         <symbol>}</symbol>
                     </subroutineBody>
                 </subroutineDec>
                 <subroutineDec>
                     <keyword>function</keyword>
                     <keyword>void</keyword>
                     <identifier kind='subroutine' isDefinition='true'>doSomethingElse</identifier>
                     <symbol>(</symbol>
                     <parameterList>
                         <keyword>int</keyword>
                         <identifier kind='argument' number='0' isDefinition='true'>x</identifier>
                     </parameterList>
                     <symbol>)</symbol>
                     <subroutineBody>
                         <symbol>{</symbol>
                         <varDec>
                             <keyword>var</keyword>
                             <keyword>boolean</keyword>
                             <identifier kind='var' number='0' isDefinition='true'>hasStarted</identifier>
                             <symbol>;</symbol>
                         </varDec>
                         <symbol>}</symbol>
                     </subroutineBody>
                 </subroutineDec>
                 <symbol>}</symbol>
             </class>
         ");
 }
 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, ";")
         );
 }
示例#8
0
 public void Setup()
 {
     classUnderTest = new Grammarian();
     classUnderTest.LoadTokens(
         new Token(NodeType.Identifier, "myClass"),
         new Token(NodeType.Symbol, "."),
         new Token(NodeType.Identifier, "doSomething"),
         new Token(NodeType.Symbol, "("),
         new Token(NodeType.IntegerConstant, "5"),
         new Token(NodeType.Symbol, ")")
         );
 }
示例#9
0
 public void Setup()
 {
     classUnderTest = new Grammarian();
     classUnderTest.LoadTokens(
         new Token(NodeType.Identifier, "subroutineName"),
         new Token(NodeType.Symbol, "("),
         new Token(NodeType.IntegerConstant, "5"),
         new Token(NodeType.Symbol, ","),
         new Token(NodeType.StringConstant, "rhubarb"),
         new Token(NodeType.Symbol, ")")
         );
 }
 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, ";")
         );
 }
示例#11
0
 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>&gt;</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 ParsesCorrectlyWithoutAnElseBlock()
 {
     classUnderTest.LoadTokens(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14);
     classUnderTest.ParseIfStatement().ShouldGenerateXml(@"
         <ifStatement>
           <keyword>if</keyword>
           <symbol>(</symbol>
           <expression>
             <term>
                 <symbol>(</symbol>
                 <expression>
                     <term>
                         <identifier>x</identifier>
                     </term>
                     <symbol>*</symbol>
                     <term>
                         <integerConstant>5</integerConstant>
                     </term>
                 </expression>
                 <symbol>)</symbol>
             </term>
             <symbol>&gt;</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 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, "}")
         );
 }
示例#14
0
 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");
 }
示例#15
0
 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);
 }