Ejemplo n.º 1
0
        protected override void DoAction(int action)
        {
#pragma warning disable 162, 1522
            switch (action)
            {
            case 5: // ClassDeclaration -> CLASS, ClassName, Extension, IS, MemberDeclarations, END
            { ClassDeclaration c = new ClassDeclaration(); c.ClassName = ValueStack[ValueStack.Depth - 5].obj as ClassName; c.Extends = ValueStack[ValueStack.Depth - 4].obj as Identifier; c.Members = ValueStack[ValueStack.Depth - 2].obj as List <MemberDeclaration>;  Root.Classes.Add(c); }
            break;

            case 6: // ClassName -> IDENTIFIER
            { CurrentSemanticValue.obj = new ClassName(new Identifier(ValueStack[ValueStack.Depth - 1].identifier)); }
            break;

            case 7: // ClassName -> IDENTIFIER, LBRACKET, ClassName, RBRACKET
            { CurrentSemanticValue.obj = new ClassName(new Identifier(ValueStack[ValueStack.Depth - 4].identifier), ValueStack[ValueStack.Depth - 2].obj as ClassName); }
            break;

            case 9: // Extension -> EXTENDS, IDENTIFIER
            { CurrentSemanticValue.obj = new Identifier(ValueStack[ValueStack.Depth - 1].identifier); }
            break;

            case 10: // MemberDeclarations -> MemberDeclaration
            { CurrentSemanticValue.obj = new List <MemberDeclaration>(); (CurrentSemanticValue.obj as List <MemberDeclaration>).Add(ValueStack[ValueStack.Depth - 1].obj as MemberDeclaration); }
            break;

            case 11: // MemberDeclarations -> MemberDeclarations, MemberDeclaration
            { (CurrentSemanticValue.obj as List <MemberDeclaration>).Add(ValueStack[ValueStack.Depth - 1].obj as MemberDeclaration); }
            break;

            case 12: // MemberDeclaration -> /* empty */
            { CurrentSemanticValue.obj = null; }
            break;

            case 13: // MemberDeclaration -> VariableDeclaration
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 14: // MemberDeclaration -> MethodDeclaration
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 15: // MemberDeclaration -> ConstructorDeclaration
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 16: // ConstructorDeclaration -> THIS, Parameters, IS, Body, END
            { CurrentSemanticValue.obj = new ConstructorDeclaration(ValueStack[ValueStack.Depth - 4].obj as List <Parameter>, ValueStack[ValueStack.Depth - 2].obj as Body); }
            break;

            case 17: // VariableDeclaration -> VAR, IDENTIFIER, COLON, Expression
            { CurrentSemanticValue.obj = new VariableDeclaration(new Identifier(ValueStack[ValueStack.Depth - 3].identifier), ValueStack[ValueStack.Depth - 1].obj as Expression); }
            break;

            case 18: // MethodDeclaration -> METHOD, IDENTIFIER, Parameters, MethodReturn, IS, Body,
                     //                      END
            { CurrentSemanticValue.obj = new MethodDeclaration(new Identifier(ValueStack[ValueStack.Depth - 6].identifier), ValueStack[ValueStack.Depth - 5].obj as List <Parameter>, ValueStack[ValueStack.Depth - 4].obj as Identifier, ValueStack[ValueStack.Depth - 2].obj as Body); }
            break;

            case 19: // MethodReturn -> /* empty */
            { CurrentSemanticValue.obj = null; }
            break;

            case 20: // MethodReturn -> COLON, IDENTIFIER
            { CurrentSemanticValue.obj = new Identifier(ValueStack[ValueStack.Depth - 1].identifier); }
            break;

            case 21: // Parameters -> /* empty */
            { CurrentSemanticValue.obj = new List <Parameter>(); }
            break;

            case 22: // Parameters -> LPAREN, ParameterList, RPAREN
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 2].obj; }
            break;

            case 23: // ParameterList -> Parameter
            { CurrentSemanticValue.obj = new List <Parameter>(); (CurrentSemanticValue.obj as List <Parameter>).Add(ValueStack[ValueStack.Depth - 1].obj as Parameter); }
            break;

            case 24: // ParameterList -> ParameterList, COMMA, Parameter
            { (CurrentSemanticValue.obj as List <Parameter>).Add(ValueStack[ValueStack.Depth - 1].obj as Parameter); }
            break;

            case 25: // Parameter -> IDENTIFIER, COLON, ClassName
            { CurrentSemanticValue.obj = new Parameter(new Identifier(ValueStack[ValueStack.Depth - 3].identifier), ValueStack[ValueStack.Depth - 1].obj as ClassName); }
            break;

            case 26: // Body -> /* empty */
            { CurrentSemanticValue.obj = new Body(); }
            break;

            case 27: // Body -> VariableDeclarations, Statements
            { Body b = new Body(); b.Variables = ValueStack[ValueStack.Depth - 2].obj as List <VariableDeclaration>; b.Statements = ValueStack[ValueStack.Depth - 1].obj as List <Statement>; CurrentSemanticValue.obj = b; }
            break;

            case 28: // VariableDeclarations -> VariableDeclaration
            { CurrentSemanticValue.obj = new List <VariableDeclaration>(); (CurrentSemanticValue.obj as List <VariableDeclaration>).Add(ValueStack[ValueStack.Depth - 1].obj as VariableDeclaration); }
            break;

            case 29: // VariableDeclarations -> VariableDeclarations, VariableDeclaration
            { (CurrentSemanticValue.obj as List <VariableDeclaration>).Add(ValueStack[ValueStack.Depth - 1].obj as VariableDeclaration); }
            break;

            case 31: // Statements -> Statement
            { CurrentSemanticValue.obj = new List <Statement>(); (CurrentSemanticValue.obj as List <Statement>).Add(ValueStack[ValueStack.Depth - 1].obj as Statement); }
            break;

            case 32: // Statements -> Statements, Statement
            { (CurrentSemanticValue.obj as List <Statement>).Add(ValueStack[ValueStack.Depth - 1].obj as Statement); }
            break;

            case 34: // Statement -> Assignment
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 35: // Statement -> IfStatement
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 36: // Statement -> WhileLoop
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 37: // Statement -> ReturnStatement
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 38: // Assignment -> IDENTIFIER, ASSIGN, Expression
            { CurrentSemanticValue.obj = new Assignment(new Identifier(ValueStack[ValueStack.Depth - 3].identifier), ValueStack[ValueStack.Depth - 1].obj as Expression); }
            break;

            case 39: // IfStatement -> IF, Expression, THEN, Body, END
            { CurrentSemanticValue.obj = new IfStatement(ValueStack[ValueStack.Depth - 4].obj as Expression, ValueStack[ValueStack.Depth - 2].obj as Body); }
            break;

            case 40: // IfStatement -> IF, Expression, THEN, Body, ELSE, Body, END
            { CurrentSemanticValue.obj = new IfStatement(ValueStack[ValueStack.Depth - 6].obj as Expression, ValueStack[ValueStack.Depth - 4].obj as Body, ValueStack[ValueStack.Depth - 2].obj as Body); }
            break;

            case 41: // WhileLoop -> WHILE, Expression, LOOP, Body, END
            { CurrentSemanticValue.obj = new WhileLoop(ValueStack[ValueStack.Depth - 4].obj as Expression, ValueStack[ValueStack.Depth - 2].obj as Body); }
            break;

            case 42: // ReturnStatement -> RETURN
            { CurrentSemanticValue.obj = new ReturnStatement(); }
            break;

            case 43: // ReturnStatement -> RETURN, Expression
            { CurrentSemanticValue.obj = new ReturnStatement(ValueStack[ValueStack.Depth - 1].obj as Expression); }
            break;

            case 44: // Expression -> Primary
            { CurrentSemanticValue.obj = new Expression(ValueStack[ValueStack.Depth - 1].obj as Primary); }
            break;

            case 45: // Expression -> Primary, ExpressionArguments
            { CurrentSemanticValue.obj = new Expression(ValueStack[ValueStack.Depth - 2].obj as Primary, ValueStack[ValueStack.Depth - 1].obj as List <ExpressionArgument>); }
            break;

            case 46: // ExpressionArguments -> ExpressionArgument
            { CurrentSemanticValue.obj = new List <ExpressionArgument>(); (CurrentSemanticValue.obj as List <ExpressionArgument>).Add(ValueStack[ValueStack.Depth - 1].obj as ExpressionArgument); }
            break;

            case 47: // ExpressionArguments -> ExpressionArguments, ExpressionArgument
            { (CurrentSemanticValue.obj as List <ExpressionArgument>).Add(ValueStack[ValueStack.Depth - 1].obj as ExpressionArgument); }
            break;

            case 48: // ExpressionArgument -> DOT, IDENTIFIER, Arguments
            { CurrentSemanticValue.obj = new ExpressionArgument(new Identifier(ValueStack[ValueStack.Depth - 2].identifier), ValueStack[ValueStack.Depth - 1].obj as List <Expression>); }
            break;

            case 49: // Arguments -> LPAREN, Expressions, RPAREN
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 2].obj as List <Expression>; }
            break;

            case 51: // Expressions -> Expression
            { CurrentSemanticValue.obj = new List <Expression>(); (CurrentSemanticValue.obj as List <Expression>).Add(ValueStack[ValueStack.Depth - 1].obj as Expression); }
            break;

            case 52: // Expressions -> Expressions, COMMA, Expression
            { (CurrentSemanticValue.obj as List <Expression>).Add(ValueStack[ValueStack.Depth - 1].obj as Expression); }
            break;

            case 53: // Primary -> THIS
            { CurrentSemanticValue.obj = new Identifier("this"); }
            break;

            case 54: // Primary -> ClassName
            { CurrentSemanticValue.obj = ValueStack[ValueStack.Depth - 1].obj; }
            break;

            case 55: // Primary -> NUMBER
            { CurrentSemanticValue.obj = new Integer(ValueStack[ValueStack.Depth - 1].intNumber); }
            break;
            }
#pragma warning restore 162, 1522
        }