public programNode program()
    {
        var token = lexer.GetToken();

        if (token.Id == 3)
        {
            var text = "";
            var arg0 = function();
            text += arg0.Text;
            var arg1 = program();
            text += arg1.Text;
            var result = new programNode(text, null, arg0, arg1);
            result.function = arg0;
            result.program  = arg1;
            result.res      = result.function.res + result.program.res;
            token           = lexer.GetToken();
            if (token.Id != -1)
            {
                throw new ParserException("Got unxpected token from lexer");
            }
            return(result);
        }
        if (token.Id == 4)
        {
            var text = "";
            var arg0 = var();
            text += arg0.Text;
            var arg1 = program();
            text += arg1.Text;
            var result = new programNode(text, null, arg0, arg1);
            result.var     = arg0;
            result.program = arg1;
            result.res     = result.var.res + result.program.res;
            token          = lexer.GetToken();
            if (token.Id != -1)
            {
                throw new ParserException("Got unxpected token from lexer");
            }
            return(result);
        }
        if (true)
        {
            var text   = "";
            var result = new programNode(text, null);
            result.res = EmptyStr;
            token      = lexer.GetToken();
            if (token.Id != -1)
            {
                throw new ParserException("Got unxpected token from lexer");
            }
            return(result);
        }
        throw new ParserException("Got unxpected token from lexer");
        //return null
    }
Пример #2
0
            public int VisitProgram(programNode program)
            {
                List <expressionNode> expressions = new List <expressionNode>();
                var cur = program.expressionStatement;

                while (cur != null)
                {
                    expressions.Add(cur.expression);
                    cur = cur.expressionStatement;
                }
                foreach (var e in expressions)
                {
                    VisitExpression(e);
                }

                return(0);
            }