Example #1
0
        public void VisitNode(ClassBody node)
        {
            // Create a list of FieldDcls children  (should only be one)
            List <FieldDcls> matchingChildren = Utilities.GetChildren(node, typeof(FieldDcls)).Cast <FieldDcls>().ToList();

            foreach (FieldDcls f in matchingChildren)
            {
                this.VisitNode(f);
            }
        }
        protected void VisitNode(ClassBody node)
        {
            // Write class header
            StringBuilder sb = new StringBuilder();

            // Open bracket
            InsertIntoFile("{\n");

            // Create a list of FieldDcls children  (should only be one)
            Utilities.VisitSpecificChild(node, typeof(FieldDcls), this);

            // Close bracket
            InsertIntoFile("\n}\n");
        }
        protected override void DoAction(int action)
        {
#pragma warning disable 162, 1522
            switch (action)
            {
            case 2: // CompilationUnit -> ClassDeclaration
            { CurrentSemanticValue = new CompilationUnit(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 3: // CompilationUnit -> MethodDeclarations
            { CurrentSemanticValue = new CompilationUnit(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 4: // MethodDeclarations -> MethodDeclaration
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 5: // MethodDeclarations -> MethodDeclarations, MethodDeclaration
            { ValueStack[ValueStack.Depth - 2].makeSibling(ValueStack[ValueStack.Depth - 1]); CurrentSemanticValue = ValueStack[ValueStack.Depth - 2]; }
            break;

            case 6: // MethodDeclaration -> Modifiers, TypeSpecifier, MethodSignature, MethodBody
            { CurrentSemanticValue = new MethodDeclaration(ValueStack[ValueStack.Depth - 4], ValueStack[ValueStack.Depth - 3], ValueStack[ValueStack.Depth - 2], ValueStack[ValueStack.Depth - 1]); }
            break;

            case 7: // MethodSignature -> Identifier, LPAREN, ParameterList, RPAREN
            { CurrentSemanticValue = new MethodSignature(ValueStack[ValueStack.Depth - 4], ValueStack[ValueStack.Depth - 2]); }
            break;

            case 8: // MethodSignature -> Identifier, LPAREN, RPAREN
            { CurrentSemanticValue = new MethodSignature(ValueStack[ValueStack.Depth - 3]); }
            break;

            case 9: // ParameterList -> Parameter
            { CurrentSemanticValue = new ParameterList(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 10: // ParameterList -> ParameterList, COMMA, Parameter
            { ValueStack[ValueStack.Depth - 3].adoptChildren(ValueStack[ValueStack.Depth - 1]); CurrentSemanticValue = ValueStack[ValueStack.Depth - 3]; }
            break;

            case 11: // Parameter -> TypeSpecifier, Identifier
            { CurrentSemanticValue = new Parameter(ValueStack[ValueStack.Depth - 2], ValueStack[ValueStack.Depth - 1]); }
            break;

            case 12: // MethodBody -> Block
            { CurrentSemanticValue = new MethodBody(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 13: // ClassDeclaration -> Modifiers, CLASS, Identifier, ClassBody
            { CurrentSemanticValue = new ClassDeclaration(ValueStack[ValueStack.Depth - 4], ValueStack[ValueStack.Depth - 2], ValueStack[ValueStack.Depth - 1]); }
            break;

            case 14: // Modifiers -> PUBLIC
            { CurrentSemanticValue = new Modifiers(ModifierType.PUBLIC); }
            break;

            case 15: // Modifiers -> PRIVATE
            { CurrentSemanticValue = new Modifiers(ModifierType.PRIVATE); }
            break;

            case 16: // Modifiers -> STATIC
            { CurrentSemanticValue = new Modifiers(ModifierType.STATIC); }
            break;

            case 17: // Modifiers -> Modifiers, PUBLIC
            { ValueStack[ValueStack.Depth - 2].addModifierType(ModifierType.PUBLIC); CurrentSemanticValue = ValueStack[ValueStack.Depth - 2]; }
            break;

            case 18: // Modifiers -> Modifiers, PRIVATE
            { ValueStack[ValueStack.Depth - 2].addModifierType(ModifierType.PRIVATE); CurrentSemanticValue = ValueStack[ValueStack.Depth - 2]; }
            break;

            case 19: // Modifiers -> Modifiers, STATIC
            { ValueStack[ValueStack.Depth - 2].addModifierType(ModifierType.STATIC); CurrentSemanticValue = ValueStack[ValueStack.Depth - 2]; }
            break;

            case 20: // ClassBody -> LBRACE, FieldDeclarations, RBRACE
            { CurrentSemanticValue = new ClassBody(ValueStack[ValueStack.Depth - 2]); }
            break;

            case 29: // StructDeclaration -> Modifiers, STRUCT, Identifier, ClassBody
            { CurrentSemanticValue = new StructDeclaration(ValueStack[ValueStack.Depth - 4], ValueStack[ValueStack.Depth - 2], ValueStack[ValueStack.Depth - 1]); }
            break;

            case 30: // FieldVariableDeclaration -> Modifiers, TypeSpecifier, FieldVariableDeclarators
            {}
            break;

            case 31: // TypeSpecifier -> TypeName
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 33: // TypeName -> PrimitiveType
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 35: // ArraySpecifier -> TypeName, LBRACKET, RBRACKET
            {}
            break;

            case 36: // PrimitiveType -> BOOLEAN
            { CurrentSemanticValue = new PrimitiveType(EnumPrimitiveType.BOOLEAN); }
            break;

            case 37: // PrimitiveType -> INT
            { CurrentSemanticValue = new PrimitiveType(EnumPrimitiveType.INT); }
            break;

            case 38: // PrimitiveType -> VOID
            { CurrentSemanticValue = new PrimitiveType(EnumPrimitiveType.VOID); }
            break;

            case 39: // FieldVariableDeclarators -> FieldVariableDeclaratorName
            {}
            break;

            case 40: // FieldVariableDeclarators -> FieldVariableDeclarators, COMMA,
                     //                             FieldVariableDeclaratorName
            {}
            break;

            case 41: // FieldVariableDeclaratorName -> Identifier
            {}
            break;

            case 42: // ConstructorDeclaration -> Modifiers, MethodSignature, Block
            {}
            break;

            case 43: // StaticInitializer -> STATIC, Block
            {}
            break;

            case 44: // Block -> LBRACE, LocalItems, RBRACE
            { CurrentSemanticValue = new Block(ValueStack[ValueStack.Depth - 2]); }
            break;

            case 45: // Block -> LBRACE, RBRACE
            { CurrentSemanticValue = new Block(new Identifier("Empty Block")); }
            break;

            case 46: // LocalItems -> LocalItem
            { CurrentSemanticValue = new LocalItems(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 47: // LocalItems -> LocalItems, LocalItem
            { ValueStack[ValueStack.Depth - 2].adoptChildren(ValueStack[ValueStack.Depth - 1]); CurrentSemanticValue = ValueStack[ValueStack.Depth - 2]; }
            break;

            case 50: // LocalVariableDeclaration -> TypeSpecifier, LocalVariableNames, SEMICOLON
            { CurrentSemanticValue = new LocalVariableDeclaration(ValueStack[ValueStack.Depth - 3], ValueStack[ValueStack.Depth - 2]); }
            break;

            case 52: // LocalVariableNames -> Identifier
            { CurrentSemanticValue = new LocalVariableNames(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 53: // LocalVariableNames -> LocalVariableNames, COMMA, Identifier
            { ValueStack[ValueStack.Depth - 3].adoptChildren(ValueStack[ValueStack.Depth - 1]); CurrentSemanticValue = ValueStack[ValueStack.Depth - 3]; }
            break;

            case 62: // SelectionStatement -> IF, LPAREN, Expression, RPAREN, Statement, ELSE,
                     //                       Statement
            { CurrentSemanticValue = new SelectionStatement(ValueStack[ValueStack.Depth - 5], ValueStack[ValueStack.Depth - 3], ValueStack[ValueStack.Depth - 1]); }
            break;

            case 63: // IterationStatement -> WHILE, LPAREN, Expression, RPAREN, Statement
            { CurrentSemanticValue = new IterationStatement(ValueStack[ValueStack.Depth - 3], ValueStack[ValueStack.Depth - 1]); }
            break;

            case 64: // ReturnStatement -> RETURN, Expression, SEMICOLON
            { CurrentSemanticValue = new ReturnStatement(ValueStack[ValueStack.Depth - 2]); }
            break;

            case 66: // ArgumentList -> Expression
            { CurrentSemanticValue = new ArgumentList(ValueStack[ValueStack.Depth - 1]); }
            break;

            case 67: // ArgumentList -> ArgumentList, COMMA, Expression
            { ValueStack[ValueStack.Depth - 3].adoptChildren(ValueStack[ValueStack.Depth - 1]); CurrentSemanticValue = ValueStack[ValueStack.Depth - 3]; }
            break;

            case 68: // Expression -> QualifiedName, EQUALS, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.EQUALS, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 69: // Expression -> Expression, OP_LOR, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_LOR, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 70: // Expression -> Expression, OP_LAND, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_LAND, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 71: // Expression -> Expression, PIPE, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.PIPE, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 72: // Expression -> Expression, HAT, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.HAT, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 73: // Expression -> Expression, AND, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.AND, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 74: // Expression -> Expression, OP_EQ, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_EQ, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 75: // Expression -> Expression, OP_NE, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_NE, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 76: // Expression -> Expression, OP_GT, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_GT, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 77: // Expression -> Expression, OP_LT, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_LT, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 78: // Expression -> Expression, OP_LE, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_LE, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 79: // Expression -> Expression, OP_GE, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.OP_GE, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 80: // Expression -> Expression, PLUSOP, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.PLUSOP, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 81: // Expression -> Expression, MINUSOP, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.MINUSOP, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 82: // Expression -> Expression, ASTERISK, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.ASTERISK, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 83: // Expression -> Expression, RSLASH, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.RSLASH, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 84: // Expression -> Expression, PERCENT, Expression
            { CurrentSemanticValue = new Expression(ValueStack[ValueStack.Depth - 3], ExprKind.PERCENT, ValueStack[ValueStack.Depth - 1]); }
            break;

            case 86: // Expression -> PrimaryExpression
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 89: // PrimaryExpression -> QualifiedName
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 90: // PrimaryExpression -> NotJustName
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 91: // NotJustName -> SpecialName
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 92: // NotJustName -> ComplexPrimary
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 93: // ComplexPrimary -> LPAREN, Expression, RPAREN
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 2]; }
            break;

            case 94: // ComplexPrimary -> ComplexPrimaryNoParenthesis
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 95: // ComplexPrimaryNoParenthesis -> LITERAL
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 96: // ComplexPrimaryNoParenthesis -> Number
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 97: // ComplexPrimaryNoParenthesis -> FieldAccess
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 98: // ComplexPrimaryNoParenthesis -> MethodCall
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 99: // FieldAccess -> NotJustName, PERIOD, Identifier
            { CurrentSemanticValue = new Identifier("Not Implemented: FieldAccess"); }
            break;

            case 100: // MethodCall -> MethodReference, LPAREN, ArgumentList, RPAREN
            { CurrentSemanticValue = new MethodCall(ValueStack[ValueStack.Depth - 4], ValueStack[ValueStack.Depth - 2]); }
            break;

            case 101: // MethodCall -> MethodReference, LPAREN, RPAREN
            { CurrentSemanticValue = new MethodCall(ValueStack[ValueStack.Depth - 3]); }
            break;

            case 109: // Identifier -> IDENTIFIER
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;

            case 110: // Number -> INT_NUMBER
            { CurrentSemanticValue = ValueStack[ValueStack.Depth - 1]; }
            break;
            }
#pragma warning restore 162, 1522
        }