public void Add(string identifier, AST.Declaration decl)
 {
     if (table.ContainsKey(identifier))
     {
         throw new ArgumentException(string.Format("Already Defined {0}", identifier));
     }
     else
     {
         table.Add(identifier, decl);
     }
 }
Exemple #2
0
        protected override void DoAction(int action)
        {
#pragma warning disable 162, 1522
            switch (action)
            {
            case 2: // Program -> CompilationUnit
#line 128 "parser.y"
            { root = ValueStack[ValueStack.Depth - 1].decl; }
#line default
                break;

            case 3: // CompilationUnit -> OrdinaryCompilationUnit
#line 132 "parser.y"
            { CurrentSemanticValue.decl = new AST.CompilationUnitDeclarator(ValueStack[ValueStack.Depth - 1].node); }
#line default
                break;

            case 4: // OrdinaryCompilationUnit -> PackageDeclaration_Opt, ImportDeclarations,
                    //                            TypeDeclarations
#line 136 "parser.y"
            { CurrentSemanticValue.node = new AST.CompilationUnit(ValueStack[ValueStack.Depth - 1].decls); }
#line default
                break;

            case 7: // TypeDeclarations -> TypeDeclarations, TypeDeclaration
#line 148 "parser.y"
            { CurrentSemanticValue.decls = ValueStack[ValueStack.Depth - 2].decls; CurrentSemanticValue.decls.Add(ValueStack[ValueStack.Depth - 1].decl); }
#line default
                break;

            case 8: // TypeDeclarations -> /* empty */
#line 149 "parser.y"
            { CurrentSemanticValue.decls = new System.Collections.Generic.List <AST.Declaration>(); }
#line default
                break;

            case 9: // TypeDeclaration -> ClassDeclaration
#line 153 "parser.y"
            { CurrentSemanticValue.decl = ValueStack[ValueStack.Depth - 1].decl; }
#line default
                break;

            case 10: // ClassDeclaration -> NormalClassDeclaration
#line 157 "parser.y"
            { CurrentSemanticValue.decl = ValueStack[ValueStack.Depth - 1].decl; }
#line default
                break;

            case 11: // NormalClassDeclaration -> ClassModifiers, CLASS, TypeIdentifier,
                     //                           TypeParameters_Opt, Superclass_Opt,
                     //                           Superinterfaces_Opt, ClassBody
#line 161 "parser.y"
            { CurrentSemanticValue.decl = new AST.ClassDeclaration(ValueStack[ValueStack.Depth - 7].mods, ValueStack[ValueStack.Depth - 5].name, ValueStack[ValueStack.Depth - 1].decls); }
#line default
                break;

            case 12: // ClassModifiers -> ClassModifiers, ClassModifier
#line 165 "parser.y"
            { CurrentSemanticValue.mods = ValueStack[ValueStack.Depth - 2].mods; CurrentSemanticValue.mods.Add(ValueStack[ValueStack.Depth - 1].mod); }
#line default
                break;

            case 13: // ClassModifiers -> /* empty */
#line 166 "parser.y"
            { CurrentSemanticValue.mods = new System.Collections.Generic.List <AST.Modifier>(); }
#line default
                break;

            case 14: // ClassModifier -> PUBLIC
#line 170 "parser.y"
            { CurrentSemanticValue.mod = AST.Modifier.Public; }
#line default
                break;

            case 15: // TypeIdentifier -> IDENT
#line 174 "parser.y"
            { CurrentSemanticValue.name = ValueStack[ValueStack.Depth - 1].name; }
#line default
                break;

            case 19: // ClassBody -> '{', ClassBodyDeclarations, '}'
#line 190 "parser.y"
            { CurrentSemanticValue.decls = ValueStack[ValueStack.Depth - 2].decls; }
#line default
                break;

            case 20: // ClassBodyDeclarations -> ClassBodyDeclarations, ClassBodyDeclaration
#line 194 "parser.y"
            { CurrentSemanticValue.decls = ValueStack[ValueStack.Depth - 2].decls; CurrentSemanticValue.decls.Add(ValueStack[ValueStack.Depth - 1].decl); }
#line default
                break;

            case 21: // ClassBodyDeclarations -> /* empty */
#line 195 "parser.y"
            { CurrentSemanticValue.decls = new System.Collections.Generic.List <AST.Declaration>(); }
#line default
                break;

            case 22: // ClassBodyDeclaration -> ClassMemberDeclaration
#line 199 "parser.y"
            { CurrentSemanticValue.decl = ValueStack[ValueStack.Depth - 1].decl; }
#line default
                break;

            case 23: // ClassMemberDeclaration -> MethodDeclaration
#line 203 "parser.y"
            { CurrentSemanticValue.decl = ValueStack[ValueStack.Depth - 1].decl; }
#line default
                break;

            case 24: // MethodDeclaration -> MethodModifiers, MethodHeader, MethodBody
#line 207 "parser.y"
            { CurrentSemanticValue.decl = new AST.MethodDeclaration(ValueStack[ValueStack.Depth - 3].mods, ValueStack[ValueStack.Depth - 2].mHead, ValueStack[ValueStack.Depth - 1].bStmt); }
#line default
                break;

            case 25: // MethodModifiers -> MethodModifiers, MethodModifier
#line 211 "parser.y"
            { CurrentSemanticValue.mods = ValueStack[ValueStack.Depth - 2].mods; CurrentSemanticValue.mods.Add(ValueStack[ValueStack.Depth - 1].mod); }
#line default
                break;

            case 26: // MethodModifiers -> /* empty */
#line 212 "parser.y"
            { CurrentSemanticValue.mods = new System.Collections.Generic.List <AST.Modifier>(); }
#line default
                break;

            case 27: // MethodModifier -> PUBLIC
#line 216 "parser.y"
            { CurrentSemanticValue.mod = AST.Modifier.Public; }
#line default
                break;

            case 28: // MethodModifier -> STATIC
#line 217 "parser.y"
            { CurrentSemanticValue.mod = AST.Modifier.Static; }
#line default
                break;

            case 29: // MethodHeader -> Result, MethodDeclarator, Throws_Opt
#line 221 "parser.y"
            { CurrentSemanticValue.mHead = new AST.MethodHeader(ValueStack[ValueStack.Depth - 3].type, ValueStack[ValueStack.Depth - 2].mDecl); }
#line default
                break;

            case 31: // Result -> VOID
#line 229 "parser.y"
            { CurrentSemanticValue.type = new AST.VoidType(); }
#line default
                break;

            case 32: // MethodDeclarator -> IDENT, '(', ReceiverParameter_Opt, FormalParameters, ')',
                     //                     Dims_Opt
#line 233 "parser.y"
            { CurrentSemanticValue.mDecl = new AST.MethodDeclarator(ValueStack[ValueStack.Depth - 6].name, ValueStack[ValueStack.Depth - 3].fParms); }
#line default
                break;

            case 34: // FormalParameters -> FormalParameters, FormalParameter
#line 241 "parser.y"
            { CurrentSemanticValue.fParms = ValueStack[ValueStack.Depth - 2].fParms; CurrentSemanticValue.fParms.Add(ValueStack[ValueStack.Depth - 1].fParm); }
#line default
                break;

            case 35: // FormalParameters -> ',', FormalParameter
#line 242 "parser.y"
            { CurrentSemanticValue.fParms = new System.Collections.Generic.List <AST.FormalParameter>(); }
#line default
                break;

            case 36: // FormalParameters -> /* empty */
#line 243 "parser.y"
            { CurrentSemanticValue.fParms = new System.Collections.Generic.List <AST.FormalParameter>(); }
#line default
                break;

            case 37: // FormalParameter -> VariableModifiers, UnannType, VariableDeclaratorId
#line 247 "parser.y"
            { CurrentSemanticValue.fParm = new AST.FormalParameter(ValueStack[ValueStack.Depth - 2].type, ValueStack[ValueStack.Depth - 1].name); }
#line default
                break;

            case 39: // UnannType -> UnannReferenceType
#line 255 "parser.y"
            { CurrentSemanticValue.type = ValueStack[ValueStack.Depth - 1].type; }
#line default
                break;

            case 40: // UnannReferenceType -> UnannArrayType
#line 259 "parser.y"
            { CurrentSemanticValue.type = ValueStack[ValueStack.Depth - 1].type; }
#line default
                break;

            case 41: // UnannArrayType -> UnannClassOrInterfaceType, Dims
#line 263 "parser.y"
            { CurrentSemanticValue.type = new AST.ArrayType(ValueStack[ValueStack.Depth - 2].name); }
#line default
                break;

            case 42: // UnannClassOrInterfaceType -> UnannClassType
#line 267 "parser.y"
            { CurrentSemanticValue.name = ValueStack[ValueStack.Depth - 1].name; }
#line default
                break;

            case 43: // UnannClassType -> TypeIdentifier, TypeArguments_Opt
#line 271 "parser.y"
            { CurrentSemanticValue.name = ValueStack[ValueStack.Depth - 2].name; }
#line default
                break;

            case 44: // TypeIdentifier -> IDENT
#line 275 "parser.y"
            { CurrentSemanticValue.name = ValueStack[ValueStack.Depth - 1].name; }
#line default
                break;

            case 52: // MethodBody -> Block
#line 304 "parser.y"
            { CurrentSemanticValue.bStmt = ValueStack[ValueStack.Depth - 1].bStmt; }
#line default
                break;

            case 53: // Block -> '{', BlockStatements_Opt, '}'
#line 308 "parser.y"
            { CurrentSemanticValue.bStmt = new AST.BlockStatement(ValueStack[ValueStack.Depth - 2].stmts); }
#line default
                break;

            case 54: // BlockStatements_Opt -> BlockStatements_Opt, BlockStatement
#line 312 "parser.y"
            { CurrentSemanticValue.stmts = ValueStack[ValueStack.Depth - 2].stmts; CurrentSemanticValue.stmts.Add(ValueStack[ValueStack.Depth - 1].stmt); }
#line default
                break;

            case 55: // BlockStatements_Opt -> /* empty */
#line 313 "parser.y"
            { CurrentSemanticValue.stmts = new System.Collections.Generic.List <AST.Statement>(); }
#line default
                break;

            case 56: // BlockStatement -> LocalVariableDeclarationStatement
#line 317 "parser.y"
            { CurrentSemanticValue.stmt = ValueStack[ValueStack.Depth - 1].stmt; }
#line default
                break;

            case 57: // BlockStatement -> Statement
#line 318 "parser.y"
            { CurrentSemanticValue.stmt = ValueStack[ValueStack.Depth - 1].stmt; }
#line default
                break;

            case 58: // LocalVariableDeclarationStatement -> LocalVariableDeclaration, ';'
#line 322 "parser.y"
            { CurrentSemanticValue.stmt = ValueStack[ValueStack.Depth - 2].stmt; }
#line default
                break;

            case 59: // LocalVariableDeclaration -> VariableModifiers, LocalVariableType,
                     //                             VariableDeclarators
#line 326 "parser.y"
            { CurrentSemanticValue.stmt = new AST.LocalVariableDeclaration(ValueStack[ValueStack.Depth - 2].type, ValueStack[ValueStack.Depth - 1].vDecls); }
#line default
                break;

            case 60: // LocalVariableType -> UnannType
#line 330 "parser.y"
            { CurrentSemanticValue.type = ValueStack[ValueStack.Depth - 1].type; }
#line default
                break;

            case 61: // UnannType -> UnannPrimitiveType
#line 334 "parser.y"
            { CurrentSemanticValue.type = ValueStack[ValueStack.Depth - 1].type; }
#line default
                break;

            case 62: // UnannPrimitiveType -> NumericType
#line 338 "parser.y"
            { CurrentSemanticValue.type = ValueStack[ValueStack.Depth - 1].type; }
#line default
                break;

            case 63: // NumericType -> IntegralType
#line 342 "parser.y"
            { CurrentSemanticValue.type = ValueStack[ValueStack.Depth - 1].type; }
#line default
                break;

            case 64: // IntegralType -> INT
#line 346 "parser.y"
            { CurrentSemanticValue.type = new AST.IntType(); }
#line default
                break;

            case 65: // VariableDeclarators -> VariableDeclarators, VariableDeclarator
#line 349 "parser.y"
            { CurrentSemanticValue.vDecls = ValueStack[ValueStack.Depth - 2].vDecls; CurrentSemanticValue.vDecls.Add(ValueStack[ValueStack.Depth - 1].vDecl); }
#line default
                break;

            case 66: // VariableDeclarators -> /* empty */
#line 350 "parser.y"
            { CurrentSemanticValue.vDecls = new System.Collections.Generic.List <AST.VariableDeclarator>(); }
#line default
                break;

            case 67: // VariableDeclarator -> VariableDeclaratorId, VariableInitializer_Opt
#line 354 "parser.y"
            { CurrentSemanticValue.vDecl = new AST.VariableDeclarator(ValueStack[ValueStack.Depth - 2].name); }
#line default
                break;

            case 69: // VariableDeclaratorId -> IDENT, Dims_Opt
#line 362 "parser.y"
            { CurrentSemanticValue.name = ValueStack[ValueStack.Depth - 2].name; }
#line default
                break;

            case 72: // ExpressionStatement -> StatementExpression, ';'
#line 374 "parser.y"
            { CurrentSemanticValue.stmt = new AST.StatementFromExpression(ValueStack[ValueStack.Depth - 2].expr); }
#line default
                break;

            case 74: // Assignment -> LeftHandSide, AssignmentOperator, Expression
#line 382 "parser.y"
            { CurrentSemanticValue.expr = new AST.AssignmentExpression(ValueStack[ValueStack.Depth - 3].expr, ValueStack[ValueStack.Depth - 2].oper, ValueStack[ValueStack.Depth - 1].expr); }
#line default
                break;

            case 75: // LeftHandSide -> ExpressionName
#line 386 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 76: // ExpressionName -> IDENT
#line 390 "parser.y"
            { CurrentSemanticValue.expr = new AST.ExpressionName(ValueStack[ValueStack.Depth - 1].name); }
#line default
                break;

            case 77: // AssignmentOperator -> IDENT
#line 394 "parser.y"
            { CurrentSemanticValue.oper = new AST.AssignmentOperator(ValueStack[ValueStack.Depth - 1].name); }
#line default
                break;

            case 78: // Expression -> AssignmentExpression
#line 398 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 79: // AssignmentExpression -> ConditionalExpression
#line 402 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 80: // ConditionalExpression -> ConditionalOrExpression
#line 406 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 81: // ConditionalOrExpression -> ConditionalAndExpression
#line 410 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 82: // ConditionalAndExpression -> InclusiveOrExpression
#line 414 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 83: // InclusiveOrExpression -> ExclusiveOrExpression
#line 418 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 84: // ExclusiveOrExpression -> AndExpression
#line 422 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 85: // AndExpression -> EqualityExpression
#line 426 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 86: // EqualityExpression -> RelationalExpression
#line 430 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 87: // RelationalExpression -> ShiftExpression
#line 434 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 88: // ShiftExpression -> AdditiveExpression
#line 438 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 89: // AdditiveExpression -> MultiplicativeExpression
#line 442 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 90: // MultiplicativeExpression -> UnaryExpression
#line 446 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 91: // UnaryExpression -> UnaryExpressionNotPlusMinus
#line 450 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 92: // UnaryExpressionNotPlusMinus -> PostfixExpression
#line 454 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 93: // PostfixExpression -> Primary
#line 458 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 94: // Primary -> PrimaryNoNewArray
#line 462 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 95: // PrimaryNoNewArray -> Literal
#line 466 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 96: // Literal -> IntegerLiteral
#line 470 "parser.y"
            { CurrentSemanticValue.expr = ValueStack[ValueStack.Depth - 1].expr; }
#line default
                break;

            case 97: // IntegerLiteral -> NUMBER
#line 474 "parser.y"
            { CurrentSemanticValue.expr = new AST.IntegerLiteral(ValueStack[ValueStack.Depth - 1].num); }
#line default
                break;
            }
#pragma warning restore 162, 1522
        }