コード例 #1
0
ファイル: parser.cs プロジェクト: rmorgan0076/CUP
 /** Invoke a user supplied parse action. */
 public override CUP.runtime.Symbol do_action(
     int act_num,
     CUP.runtime.lr_parser parser,
     CUP.runtime.SymbolStack stack,
     int top)
 {
     /* call code in generated class */
     return(action_obj.CUP_parser_do_action(act_num, parser, stack, top));
 }
コード例 #2
0
ファイル: parser.cs プロジェクト: rmorgan0076/CUP
        /** Method with the actual generated action code. */
        public CUP.runtime.Symbol CUP_parser_do_action(
            int CUP_parser_act_num,
            CUP.runtime.lr_parser CUP_parser_parser,
            CUP.runtime.SymbolStack CUP_parser_stack,
            int CUP_parser_top)
        {
            /* Symbol object for return from actions */
            CUP.runtime.Symbol CUP_parser_result;

            /* select the action based on the action number */
            switch (CUP_parser_act_num)
            {
            /*. . . . . . . . . . . . . . . . . . . .*/
            case 13: // expr ::= LPAREN expr RPAREN
            {
                decimal RESULT = decimal.Zero;
                int     eleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                int     eright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                decimal e      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).Value;
                RESULT            = e;
                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 12: // expr ::= MINUS expr
            {
                decimal RESULT = decimal.Zero;
                int     eleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     eright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = -e;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 11: // expr ::= REAL
            {
                decimal RESULT = decimal.Zero;
                int     nleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     nright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal n      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = n;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 10: // expr ::= INTEGER
            {
                decimal RESULT = decimal.Zero;
                int     nleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     nright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                int     n      = (int)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = n;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 9: // expr ::= expr MOD expr
            {
                decimal RESULT  = decimal.Zero;
                int     e1left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                int     e1right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                decimal e1      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).Value;
                int     e2left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     e2right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e2      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = (decimal)((int)e1 % (int)e2);

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 8: // expr ::= expr DIVIDE expr
            {
                decimal RESULT  = decimal.Zero;
                int     e1left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                int     e1right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                decimal e1      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).Value;
                int     e2left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     e2right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e2      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = e1 / e2;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 7: // expr ::= expr TIMES expr
            {
                decimal RESULT  = decimal.Zero;
                int     e1left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                int     e1right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                decimal e1      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).Value;
                int     e2left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     e2right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e2      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = e1 * e2;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 6: // expr ::= expr MINUS expr
            {
                decimal RESULT  = decimal.Zero;
                int     e1left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                int     e1right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                decimal e1      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).Value;
                int     e2left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     e2right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e2      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = e1 - e2;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 5: // expr ::= expr PLUS expr
            {
                decimal RESULT  = decimal.Zero;
                int     e1left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                int     e1right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                decimal e1      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).Value;
                int     e2left  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     e2right = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e2      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;

                RESULT = e1 + e2;

                CUP_parser_result = new CUP.runtime.Symbol(3 /*expr*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 4: // expr_part ::= expr NT$0 SEMI
            {
                decimal RESULT = decimal.Zero;
                // propagate RESULT from NT$0
                if (((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).Value != null)
                {
                    RESULT = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).Value;
                }
                int     eleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                int     eright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                decimal e      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).Value;

                CUP_parser_result = new CUP.runtime.Symbol(2 /*expr_part*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 3: // NT$0 ::=
            {
                Object  RESULT = null;
                int     eleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     eright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;
                RESULT = e;
                Console.WriteLine("= " + e);

                CUP_parser_result = new CUP.runtime.Symbol(4 /*NT$0*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 2: // expr_list ::= expr_part
            {
                decimal RESULT = decimal.Zero;
                int     eleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                int     eright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                decimal e      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).Value;
                RESULT            = e;
                CUP_parser_result = new CUP.runtime.Symbol(1 /*expr_list*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 1: // $START ::= expr_list EOF
            {
                Object  RESULT         = null;
                int     start_valleft  = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                int     start_valright = ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                decimal start_val      = (decimal)((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).Value;
                RESULT            = start_val;
                CUP_parser_result = new CUP.runtime.Symbol(0 /*$START*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                /* ACCEPT */
                CUP_parser_parser.done_parsing();
                return(CUP_parser_result);

            /*. . . . . . . . . . . . . . . . . . . .*/
            case 0: // expr_list ::= expr_list expr_part
            {
                decimal RESULT = decimal.Zero;

                CUP_parser_result = new CUP.runtime.Symbol(1 /*expr_list*/, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((CUP.runtime.Symbol)CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
            }
                return(CUP_parser_result);

            /* . . . . . .*/
            default:
                throw new Exception(
                          "Invalid action number found in internal parse table");
            }
        }