public void ProgramParsesGlobalVariableDefinitionWithValue() { string code = @"int foo = 5; int main() { } "; var program = new ProgramNode(); program.AddChild(new VariableDeclarationNode(program, "int", "foo", "5")); program.AddChild(new FunctionNode(program, "main", new List <FunctionParameter>())); AssertResultMatchesExpectedProgram(code, program); }
public void ProgramParsesReturnStatementWithIdentifier() { string code = @"int foo = 420; int main() { return foo; } "; var program = new ProgramNode(); program.AddChild(new VariableDeclarationNode(program, "int", "foo", "420")); var function = new FunctionNode(program, "main", new List <FunctionParameter>()); var returnStatement = new ReturnNode(function); var returnValue = new IdentifierNode(returnStatement, "foo"); returnStatement.AddChild(returnValue); function.AddChild(returnStatement); program.AddChild(function); AssertResultMatchesExpectedProgram(code, program); }
public void ProgramParsesEmptyMain() { string code = @" int main() { } "; var program = new ProgramNode(); program.AddChild(new FunctionNode(program, "main", new List <FunctionParameter>())); AssertResultMatchesExpectedProgram(code, program); }
public void ProgramParsesLocalVariableDefinition() { string code = @" int main() { int foo; } "; var program = new ProgramNode(); var function = new FunctionNode(program, "main", new List <FunctionParameter>()); function.AddChild(new VariableDeclarationNode(function, "int", "foo", null)); program.AddChild(function); AssertResultMatchesExpectedProgram(code, program); }
public void ProgramParsesReturnStatement() { string code = @" int main() { return; } "; var program = new ProgramNode(); var function = new FunctionNode(program, "main", new List <FunctionParameter>()); var returnStatement = new ReturnNode(function); function.AddChild(returnStatement); program.AddChild(function); AssertResultMatchesExpectedProgram(code, program); }
private void Program(ProgramNode node) { while (!TagIs(Tag.NULL)) { if (Utils.IsTypeTag(next.Tag)) { FunctionNode function = new FunctionNode(); node.AddChild(function); Function(function); } else { new UnknownTokenError().PrintErrMsg(); Move(); } } }
public void ProgramParsesReturnStatementWithUnsignedInteger() { string code = @" int main() { return 420u; } "; var program = new ProgramNode(); var function = new FunctionNode(program, "main", new List <FunctionParameter>()); var returnStatement = new ReturnNode(function); var returnValue = new UIntNode(returnStatement, 420u); returnStatement.AddChild(returnValue); function.AddChild(returnStatement); program.AddChild(function); AssertResultMatchesExpectedProgram(code, program); }