예제 #1
0
        private AST_operand Parse_operand(TokenKind followSet)
        {
            IncrementDepth();
            DebugPrint("opnd");

            Token       t = LookAheadToken();
            AST_operand operand;

            switch (t.Kind)
            {
            case int_Literal:
                operand = Parse_integer_literal();
                break;

            case string_Literal:
                operand = Parse_string_literal();
                break;

            case bool_Literal:
                operand = Parse_bool_literal(followSet);
                break;

            case Identifier:
                operand = Parse_identifier(followSet);
                break;

            case OpenParenthesis:
                Match(OpenParenthesis);
                operand = new AST_expression_operand(Parse_expression(followSet | CloseParenthesis));
                if (LookAheadToken().Kind == CloseParenthesis)
                {
                    Match(CloseParenthesis);
                }
                else
                {
                    Error("')' expected, '" + LookAheadToken().ToString() + "' found.", LookAheadToken());
                    SkipUntilFollow(followSet | CloseParenthesis);
                    if (LookAheadToken().Kind == CloseParenthesis)
                    {
                        Match(CloseParenthesis);
                    }
                }
                break;

            default:
                Error("Operand expected. '" + t.ToString() + "' does not start an operand.", t);
                SkipUntilFollow(followSet);
                operand = new ASTDummy_operand();
                break;
            }

            operand.Row    = t.Row;
            operand.Column = t.Column;

            DecrementDepth();

            return(operand);
        }
예제 #2
0
        private AST_expression Parse_expression(TokenKind followSet)
        {
            IncrementDepth();
            DebugPrint("expr");

            AST_expression expression;

            Token t = LookAheadToken();

            switch (t.Kind)
            {
            case Exclamation:
                expression = Parse_unary_operator_operand(followSet);
                break;

            default:
                if (isMemberOf(t.Kind, FirstSet_operand))
                {
                    AST_operand left_operand = Parse_operand(followSet | BinaryOperators);
                    if (IsBinaryOperator(LookAheadToken().Kind))
                    {
                        AST_binary_operator binary_operator = Parse_binary_operator(followSet);
                        AST_operand         right_operand   = Parse_operand(followSet);
                        binary_operator.SetLeft(left_operand);
                        binary_operator.SetRight(right_operand);
                        expression = binary_operator;
                    }
                    else
                    {
                        expression = left_operand;
                    }
                }
                else
                {
                    Error("Expression expected. '" + t.ToString() + "' does not start an expression.", t);
                    expression = new ASTDummy_operand();
                    SkipUntilFollow(followSet);
                }

                break;
            }

            DecrementDepth();

            return(expression);
        }
예제 #3
0
 public virtual void Visit(ASTDummy_operand dummy_operand)
 {
 }