Пример #1
0
        public void ProgramParsesLocalVariableDefinitionWithValue()
        {
            string code     = @"
int main()
{
    int foo = 5;
}
";
            var    program  = new ProgramNode();
            var    function = new FunctionNode(program, "main", new List <FunctionParameter>());

            function.AddChild(new VariableDeclarationNode(function, "int", "foo", "5"));
            program.AddChild(function);

            AssertResultMatchesExpectedProgram(code, program);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }