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 -> 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: // statement -> while
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 13: // statement -> repeat
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 14: // empty -> /* empty */
            { CurrentSemanticValue.stVal = new EmptyNode(); }
            break;

            case 15: // 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 16: // assign -> ident, ASSIGN, expr
            { CurrentSemanticValue.stVal = new AssignNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode, ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 17: // expr -> expr, PLUS, T
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '+'); }
            break;

            case 18: // expr -> expr, MINUS, T
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '-'); }
            break;

            case 19: // expr -> T
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 20: // T -> T, MULT, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '*'); }
            break;

            case 21: // T -> T, DIV, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '/'); }
            break;

            case 22: // T -> T, MODI, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '%'); }
            break;

            case 23: // T -> F
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 24: // F -> ident
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as IdNode; }
            break;

            case 25: // F -> INUM
            { CurrentSemanticValue.eVal = new IntNumNode(ValueStack[ValueStack.Depth - 1].iVal); }
            break;

            case 26: // F -> LPAREN, expr, RPAREN
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 2].eVal; }
            break;

            case 27: // block -> BEGIN, stlist, END
            { CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 2].blVal; }
            break;

            case 28: // cycle -> CYCLE, expr, statement
            { CurrentSemanticValue.stVal = new CycleNode(ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 29: // write -> WRITE, LPAREN, expr, RPAREN
            { CurrentSemanticValue.stVal = new WriteNode(ValueStack[ValueStack.Depth - 2].eVal); }
            break;

            case 30: // Anon@1 -> /* empty */
            { InDefSect = true; }
            break;

            case 31: // 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 32: // varlist -> ident
            {
                CurrentSemanticValue.stVal = new VarDefNode(ValueStack[ValueStack.Depth - 1].eVal as IdNode);
            }
            break;

            case 33: // 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 34: // 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 35: // if -> IF, expr, THEN, statement
            { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 36: // while -> WHILE, expr, DO, statement
            { CurrentSemanticValue.stVal = new WhileNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 37: // repeat -> REPEAT, stlist, UNTIL, expr
            { CurrentSemanticValue.stVal = new RepeatNode(ValueStack[ValueStack.Depth - 1].eVal, ValueStack[ValueStack.Depth - 3].blVal); }
            break;
            }
        }
Exemple #2
0
        protected override void DoAction(int action)
        {
            switch (action)
            {
            case 2: // progr -> stlist
            { 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, statement
            {
                ValueStack[ValueStack.Depth - 2].blVal.Add(ValueStack[ValueStack.Depth - 1].stVal);
                CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 2].blVal;
            }
            break;

            case 5: // statement -> assign, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].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, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 11: // statement -> while
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 12: // statement -> for
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 13: // statement -> println
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 14: // statement -> if
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 15: // statement -> label
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 16: // statement -> goto
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 17: // statement -> idenlist, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 23: // empty -> /* empty */
            { CurrentSemanticValue.stVal = new EmptyNode(); }
            break;

            case 24: // ident -> ID
            {
                // if (!InDefSect)
                //	if (!SymbolTable.vars.ContainsKey($1))
                //		throw new Exception("("[email protected]+","[email protected]+"): ѕеременна¤ "+$1+" не описана");
                CurrentSemanticValue.eVal = new IdNode(ValueStack[ValueStack.Depth - 1].sVal);
            }
            break;

            case 26: // assign -> ident, ASSIGN, expr
            { CurrentSemanticValue.stVal = new AssignNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode, ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 27: // assign -> TYPE, ident, ASSIGN, expr
            { CurrentSemanticValue.stVal = new AssignNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode, ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 28: // block -> OPEN_BLOCK, stlist, CLOSE_BLOCK
            { CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 2].blVal; }
            break;

            case 29: // cycle -> CYCLE, expr, statement
            { CurrentSemanticValue.stVal = new CycleNode(ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 30: // write -> WRITE, OPEN_BRACKET, expr, CLOSE_BRACKET
            { CurrentSemanticValue.stVal = new WriteNode(ValueStack[ValueStack.Depth - 2].eVal); }
            break;

            case 31: // Anon@1 -> /* empty */
            { InDefSect = true; }
            break;

            case 32: // 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 33: // varlist -> ident
            {
                CurrentSemanticValue.stVal = new VarDefNode(ValueStack[ValueStack.Depth - 1].eVal as IdNode);
            }
            break;

            case 34: // 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 35: // while -> WHILE, OPEN_BRACKET, expr, CLOSE_BRACKET, statement
            { CurrentSemanticValue.stVal = new WhileNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 36: // for -> FOR, OPEN_BRACKET, assign, TO, expr, CLOSE_BRACKET, statement
            { CurrentSemanticValue.stVal = new ForNode(ValueStack[ValueStack.Depth - 5].stVal, ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 38: // if -> IF, OPEN_BRACKET, expr, CLOSE_BRACKET, statement
            { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 39: // if -> IF, OPEN_BRACKET, expr, CLOSE_BRACKET, statement, ELSE, statement
            { CurrentSemanticValue.stVal = new IfNode(ValueStack[ValueStack.Depth - 5].eVal, ValueStack[ValueStack.Depth - 3].stVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 40: // label -> LABEL, INUM, COLON
            { CurrentSemanticValue.stVal = new LabelNode(ValueStack[ValueStack.Depth - 2].iVal); }
            break;

            case 41: // goto -> GOTO, label
            { CurrentSemanticValue.stVal = new GotoNode(ValueStack[ValueStack.Depth - 1].stVal as LabelNode); }
            break;

            case 42: // expr -> T
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 43: // expr -> expr, EQUAL, T
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "=="); }
            break;

            case 44: // expr -> expr, MORE, T
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, ">"); }
            break;

            case 45: // expr -> expr, LESS, T
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "<"); }
            break;

            case 46: // expr -> expr, NOT_EQUAL, T
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "!="); }
            break;

            case 47: // expr -> expr, MORE_EQUAL, T
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, ">="); }
            break;

            case 48: // expr -> expr, LESS_EQUAL, T
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "<="); }
            break;

            case 49: // T -> F
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as ExprNode; }
            break;

            case 50: // T -> T, PLUS, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "+"); }
            break;

            case 51: // T -> T, MINUS, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "-"); }
            break;

            case 52: // T -> T, OR, F
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "||"); }
            break;

            case 53: // F -> S
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as ExprNode; }
            break;

            case 54: // F -> F, MULT, S
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "*"); }
            break;

            case 55: // F -> F, DIV, S
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "/"); }
            break;

            case 56: // F -> F, MOD, S
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "%"); }
            break;

            case 57: // F -> F, AND, S
            { CurrentSemanticValue.eVal = new LogicOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, "&&"); }
            break;

            case 58: // S -> ident
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as IdNode; }
            break;

            case 59: // S -> ident, OPEN_BRACKET, CLOSE_BRACKET
            { CurrentSemanticValue.eVal = new FunctionNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode); }
            break;

            case 60: // S -> NOT, S
            { CurrentSemanticValue.eVal = new LogicNotNode(ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 61: // S -> MINUS, S
            { CurrentSemanticValue.eVal = new UnOpNode(ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 62: // S -> INUM
            { CurrentSemanticValue.eVal = new IntNumNode(ValueStack[ValueStack.Depth - 1].iVal); }
            break;

            case 63: // S -> RNUM
            { CurrentSemanticValue.eVal = new DoubleNumNode(ValueStack[ValueStack.Depth - 1].dVal); }
            break;

            case 64: // S -> TRUE
            { CurrentSemanticValue.eVal = new BoolNode(true); }
            break;

            case 65: // S -> FALSE
            { CurrentSemanticValue.eVal = new BoolNode(false); }
            break;

            case 66: // S -> OPEN_BRACKET, expr, CLOSE_BRACKET
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 2].eVal as ExprNode; }
            break;
            }
        }
        protected override void DoAction(int action)
        {
            switch (action)
            {
            case 2: // progr -> stlist
            { root = ValueStack[ValueStack.Depth - 1].blVal; }
            break;

            case 3: // stlist -> statement
            { CurrentSemanticValue.blVal = new StListNode(ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 4: // stlist -> stlist, statement
            {
                ValueStack[ValueStack.Depth - 2].blVal.Add(ValueStack[ValueStack.Depth - 1].stVal);
                CurrentSemanticValue.blVal = ValueStack[ValueStack.Depth - 2].blVal;
            }
            break;

            case 5: // statement -> assign, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 6: // statement -> for
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 7: // statement -> while
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 8: // statement -> if
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 9: // statement -> block
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 10: // statement -> input, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 11: // statement -> print, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 12: // statement -> var, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 13: // statement -> goto, SEMICOLON
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 2].stVal; }
            break;

            case 14: // statement -> labelstatement
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 15: // 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 + "): Variable " + ValueStack[ValueStack.Depth - 1].sVal + " not described");
                    }
                }
                CurrentSemanticValue.eVal = new IdNode(ValueStack[ValueStack.Depth - 1].sVal);
            }
            break;

            case 16: // assign -> ident, ASSIGN, expr
            { CurrentSemanticValue.stVal = new AssignNode(ValueStack[ValueStack.Depth - 3].eVal as IdNode, ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 17: // block -> BEGIN, stlist, END
            { CurrentSemanticValue.stVal = new BlockNode(ValueStack[ValueStack.Depth - 2].blVal); }
            break;

            case 18: // for -> FOR, ident, ASSIGN, expr, COMMA, expr, statement
            { CurrentSemanticValue.stVal = new ForNode(ValueStack[ValueStack.Depth - 6].eVal as IdNode, ValueStack[ValueStack.Depth - 4].eVal, ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 19: // while -> WHILE, expr, statement
            { CurrentSemanticValue.stVal = new WhileNode(ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 20: // if -> IF, expr, statement, ELSE, statement
            { CurrentSemanticValue.stVal = new IfElseNode(ValueStack[ValueStack.Depth - 4].eVal, ValueStack[ValueStack.Depth - 3].stVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 21: // if -> IF, expr, statement
            { CurrentSemanticValue.stVal = new IfElseNode(ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 22: // expr -> expr, OR, A
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.OR); }
            break;

            case 23: // expr -> A
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 24: // A -> A, AND, B
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.AND); }
            break;

            case 25: // A -> B
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 26: // B -> B, EQUAL, C
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.EQUAL); }
            break;

            case 27: // B -> B, NOTEQUAL, C
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.NOTEQUAL); }
            break;

            case 28: // B -> C
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 29: // C -> C, GREATER, E
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.GREATER); }
            break;

            case 30: // C -> C, LESS, E
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.LESS); }
            break;

            case 31: // C -> C, EQGREATER, E
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.EQGREATER); }
            break;

            case 32: // C -> C, EQLESS, E
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.EQLESS); }
            break;

            case 33: // C -> E
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 34: // E -> E, PLUS, T
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.PLUS); }
            break;

            case 35: // E -> E, MINUS, T
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.MINUS); }
            break;

            case 36: // E -> T
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 37: // T -> T, MULT, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.MULT); }
            break;

            case 38: // T -> T, DIV, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, OpType.DIV); }
            break;

            case 39: // T -> F
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal; }
            break;

            case 40: // F -> ident
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 1].eVal as IdNode; }
            break;

            case 41: // F -> INUM
            { CurrentSemanticValue.eVal = new IntNumNode(ValueStack[ValueStack.Depth - 1].iVal); }
            break;

            case 42: // F -> LPAR, expr, RPAR
            { CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 2].eVal; }
            break;

            case 43: // F -> BOOL
            { CurrentSemanticValue.eVal = new BoolValNode(ValueStack[ValueStack.Depth - 1].bVal); }
            break;

            case 44: // F -> MINUS, F
            { CurrentSemanticValue.eVal = new UnOpNode(ValueStack[ValueStack.Depth - 1].eVal, OpType.UNMINUS); }
            break;

            case 45: // F -> NOT, F
            { CurrentSemanticValue.eVal = new UnOpNode(ValueStack[ValueStack.Depth - 1].eVal, OpType.NOT); }
            break;

            case 46: // input -> INPUT, LPAR, ident, RPAR
            { CurrentSemanticValue.stVal = new InputNode(ValueStack[ValueStack.Depth - 2].eVal as IdNode); }
            break;

            case 47: // exprlist -> expr
            { CurrentSemanticValue.eVal = new ExprListNode(ValueStack[ValueStack.Depth - 1].eVal); }
            break;

            case 48: // exprlist -> exprlist, COMMA, expr
            {
                (ValueStack[ValueStack.Depth - 3].eVal as ExprListNode).Add(ValueStack[ValueStack.Depth - 1].eVal);
                CurrentSemanticValue.eVal = ValueStack[ValueStack.Depth - 3].eVal;
            }
            break;

            case 49: // print -> PRINT, LPAR, exprlist, RPAR
            { CurrentSemanticValue.stVal = new PrintNode(ValueStack[ValueStack.Depth - 2].eVal as ExprListNode); }
            break;

            case 50: // varlist -> ident
            { CurrentSemanticValue.stVal = new VarListNode(ValueStack[ValueStack.Depth - 1].eVal as IdNode); }
            break;

            case 51: // varlist -> varlist, COMMA, ident
            {
                (ValueStack[ValueStack.Depth - 3].stVal as VarListNode).Add(ValueStack[ValueStack.Depth - 1].eVal as IdNode);
                CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 3].stVal;
            }
            break;

            case 52: // Anon@1 -> /* empty */
            { InDefSect = true; }
            break;

            case 53: // var -> VAR, Anon@1, varlist
            {
                foreach (var v in (ValueStack[ValueStack.Depth - 1].stVal as VarListNode).vars)
                {
                    SymbolTable.NewVarDef(v.Name);
                }
                InDefSect = false;
            }
            break;

            case 54: // goto -> GOTO, INUM
            { CurrentSemanticValue.stVal = new GotoNode(ValueStack[ValueStack.Depth - 1].iVal); }
            break;

            case 55: // labelstatement -> INUM, COLON, statement
            { CurrentSemanticValue.stVal = new LabelStatementNode(ValueStack[ValueStack.Depth - 3].iVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;
            }
        }
Exemple #4
0
        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 -> for
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 9: // statement -> write
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 10: // statement -> var
            { CurrentSemanticValue.stVal = ValueStack[ValueStack.Depth - 1].stVal; }
            break;

            case 11: // statement -> empty
            { 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, DIV, F
            { CurrentSemanticValue.eVal = new BinOpNode(ValueStack[ValueStack.Depth - 3].eVal, ValueStack[ValueStack.Depth - 1].eVal, '/'); }
            break;

            case 20: // T -> T, REMINDER, 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: // for -> FOR, assign, TO, expr, statement
            { CurrentSemanticValue.stVal = new ForNode(ValueStack[ValueStack.Depth - 4].stVal as AssignNode, ValueStack[ValueStack.Depth - 2].eVal, ValueStack[ValueStack.Depth - 1].stVal); }
            break;

            case 28: // write -> WRITE, LPAREN, expr, RPAREN
            { CurrentSemanticValue.stVal = new WriteNode(ValueStack[ValueStack.Depth - 2].eVal); }
            break;

            case 29: // Anon@1 -> /* empty */
            { InDefSect = true; }
            break;

            case 30: // 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 31: // varlist -> ident
            {
                CurrentSemanticValue.stVal = new VarDefNode(ValueStack[ValueStack.Depth - 1].eVal as IdNode);
            }
            break;

            case 32: // 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;
            }
#pragma warning restore 162, 1522
        }