protected override void DoAction(int action) { switch (action) { case 2: // progr -> block { root = ValueStack[ValueStack.Depth - 1].blVal; } break; case 3: // stlist -> statement { CurrentSemanticValue.blVal = new BlockNode(ValueStack[ValueStack.Depth - 1].stVal); } break; case 4: // stlist -> stlist, SEMICOLON, statement { ValueStack[ValueStack.Depth - 3].blVal.Add(ValueStack[ValueStack.Depth - 1].stVal); CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 3].blVal; } break; case 5: // statement -> assign { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 6: // statement -> block { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].blVal; } break; case 7: // statement -> cycle { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 8: // statement -> while { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 9: // statement -> repeat { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 10: // statement -> for { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 11: // statement -> write { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 12: // statement -> if { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 13: // statement -> var { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 14: // ident -> ID { if (!InDefSect) { if (SymbolTable.vars.ContainsKey(ValueStack[ValueStack.Depth - 1].sVal)) { throw new Exception("(" + LocationStack[LocationStack.Depth - 1].StartLine + "," + LocationStack[LocationStack.Depth - 1].StartColumn + "): ѕеременна¤ " + ValueStack[ValueStack.Depth - 1].sVal + " уже определена"); } } CurrentSemanticValue.eVal = new IdNode(ValueStack[ValueStack.Depth - 1].sVal); } break; case 15: // assign -> ident, ASSIGN, expr { CurrentSemanticValue.stVal = new AssignNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode, ValueStack[ValueStack.Depth - 1].eVal); } break; case 16: // block -> BEGIN, stlist, END { CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 2].blVal; } break; case 17: // cycle -> CYCLE, expr, statement { CurrentSemanticValue.stVal = new CycleNode(ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 18: // while -> WHILE, expr, DO, statement { CurrentSemanticValue.stVal = new WhileNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 19: // repeat -> REPEAT, stlist, UNTIL, expr { CurrentSemanticValue.stVal = new RepeatNode(ValueStack[ValueStack.Depth - 3].blVal, ValueStack[ValueStack.Depth - 1].eVal); } break; case 20: // for -> FOR, ident, ASSIGN, expr, TO, expr, DO, statement { CurrentSemanticValue.stVal = new ForNode(ValueStack[ValueStack.Depth - 7].eVal as IdNode, ValueStack[ValueStack.Depth - 5].eVal, ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 21: // write -> WRITE, LEFT_BRACKET, expr, RIGHT_BRACKET { CurrentSemanticValue.stVal = new WriteNode(ValueStack[ValueStack.Depth - 2].eVal); } break; case 22: // if -> IF, expr, THEN, statement, ELSE, statement { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 5].eVal, ValueStack[ValueStack.Depth - 3].stVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 23: // if -> IF, expr, THEN, statement { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 24: // varlist -> ident { CurrentSemanticValue.stVal = new VarDefNode(ValueStack[ValueStack.Depth - 1].eVal as IdNode); } break; case 25: // varlist -> varlist, COMMA, ident { (ValueStack[ValueStack.Depth - 3].stVal as VarDefNode).Add(ValueStack[ValueStack.Depth - 1].eVal as IdNode); CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 3].stVal; } break; case 26: // Anon@1 -> /* empty */ { InDefSect = true; } break; case 27: // var -> VAR, Anon@1, varlist, SEMICOLON { foreach (var v in (ValueStack[ValueStack.Depth - 2].stVal as VarDefNode).Ids) { SymbolTable.NewVarDef(v.Name, type.tint); } InDefSect = false; } break; case 28: // expr -> expr, PLUS, T { CurrentSemanticValue.eVal = new BinaryNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '+'); } break; case 29: // expr -> expr, MINUS, T { CurrentSemanticValue.eVal = new BinaryNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '-'); } break; case 30: // expr -> T { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; } break; case 31: // T -> T, MULT, F { CurrentSemanticValue.eVal = new BinaryNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '*'); } break; case 32: // T -> T, DIV, F { CurrentSemanticValue.eVal = new BinaryNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '/'); } break; case 33: // T -> F { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; } break; case 34: // F -> ident { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as IdNode; } break; case 35: // F -> INUM { CurrentSemanticValue.eVal = new IntNumNode(ValueStack[ValueStack.Depth - 1].iVal); } break; case 36: // F -> LEFT_BRACKET, expr, RIGHT_BRACKET { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 2].eVal; } break; } }
protected override void DoAction(int action) { #pragma warning disable 162, 1522 switch (action) { case 2: // progr -> block { root = ValueStack[ValueStack.Depth - 1].blVal; } break; case 3: // stlist -> statement { CurrentSemanticValue.blVal = new BlockNode(ValueStack[ValueStack.Depth - 1].stVal); } break; case 4: // stlist -> stlist, SEMICOLON, statement { ValueStack[ValueStack.Depth - 3].blVal.Add(ValueStack[ValueStack.Depth - 1].stVal); CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 3].blVal; } break; case 5: // statement -> assign { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 6: // statement -> block { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].blVal; } break; case 7: // statement -> cycle { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 8: // statement -> write { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 9: // statement -> var { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 10: // statement -> empty { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 11: // statement -> if { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; } break; case 12: // empty -> /* empty */ { CurrentSemanticValue.stVal = new EmptyNode(); } break; case 13: // ident -> ID { if (!InDefSect) { if (!SymbolTable.vars.ContainsKey(ValueStack[ValueStack.Depth - 1].sVal)) { throw new Exception("(" + LocationStack[LocationStack.Depth - 1].StartLine + "," + LocationStack[LocationStack.Depth - 1].StartColumn + "): Ïåðåìåííàÿ " + ValueStack[ValueStack.Depth - 1].sVal + " íå îïèñàíà"); } } CurrentSemanticValue.eVal = new IdNode(ValueStack[ValueStack.Depth - 1].sVal); } break; case 14: // assign -> ident, ASSIGN, expr { CurrentSemanticValue.stVal = new AssignNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode, ValueStack[ValueStack.Depth - 1].eVal); } break; case 15: // expr -> expr, PLUS, T { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '+'); } break; case 16: // expr -> expr, MINUS, T { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '-'); } break; case 17: // expr -> T { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; } break; case 18: // T -> T, MULT, F { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '*'); } break; case 19: // T -> T, DIVIDE, F { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '/'); } break; case 20: // T -> T, MOD, F { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '%'); } break; case 21: // T -> F { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; } break; case 22: // F -> ident { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as IdNode; } break; case 23: // F -> INUM { CurrentSemanticValue.eVal = new IntNumNode(ValueStack[ValueStack.Depth - 1].iVal); } break; case 24: // F -> LPAREN, expr, RPAREN { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 2].eVal; } break; case 25: // block -> BEGIN, stlist, END { CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 2].blVal; } break; case 26: // cycle -> CYCLE, expr, statement { CurrentSemanticValue.stVal = new CycleNode(ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 27: // write -> WRITE, LPAREN, expr, RPAREN { CurrentSemanticValue.stVal = new WriteNode(ValueStack[ValueStack.Depth - 2].eVal); } break; case 28: // Anon@1 -> /* empty */ { InDefSect = true; } break; case 29: // var -> VAR, Anon@1, varlist { foreach (var v in (ValueStack[ValueStack.Depth - 1].stVal as VarDefNode).vars) { SymbolTable.NewVarDef(v.Name, type.tint); } InDefSect = false; } break; case 30: // varlist -> ident { CurrentSemanticValue.stVal = new VarDefNode(ValueStack[ValueStack.Depth - 1].eVal as IdNode); } break; case 31: // varlist -> varlist, COLUMN, ident { (ValueStack[ValueStack.Depth - 3].stVal as VarDefNode).Add(ValueStack[ValueStack.Depth - 1].eVal as IdNode); CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 3].stVal; } break; case 32: // if -> IF, expr, THEN, statement { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); } break; case 33: // if -> IF, expr, THEN, statement, ELSE, statement { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 5].eVal, ValueStack[ValueStack.Depth - 3].stVal, ValueStack[ValueStack.Depth - 1].stVal); } break; } #pragma warning restore 162, 1522 }