Exemplo n.º 1
0
        private ParserStatus ParseBracket(char c)
        {
            switch (_state)
            {
            case ParserState.INT:
            case ParserState.FLOAT:
                CompleteValue();
                goto case ParserState.VALUE;

            case ParserState.VALUE:
            case ParserState.VARIABLE:
                if (c == '(' || c == '<')
                {
                    _tree.AddNode(new MultiplicationOperNode());
                }
                goto case ParserState.UOPER;

            case ParserState.UOPER:
            case ParserState.NOPER:
            case ParserState.BEGIN:
            case ParserState.OPEN_PARENTHESIS:
            {
                if (c == '(')
                {
                    _tree.AddNode(new ParenthesisOperNode());
                    _parenthesisDepth++;
                    _state = ParserState.OPEN_PARENTHESIS;
                }
                else if (c == ')')
                {
                    if (_parenthesisDepth == 0)
                    {
                        return(EnterErrorState(ErrorType.UNPAIRED_PARENTHESIS));
                    }
                    else if (_state == ParserState.OPEN_PARENTHESIS)
                    {
                        return(EnterErrorState(ErrorType.CANNOT_PROCEED));
                    }

                    _parenthesisDepth--;
                    _tree.CloseParenthesis();
                    _state = ParserState.VALUE;
                }
                else if (c == '<')
                {
                    _activeFunctionParser = FunctionParser.MakeFunctionParser(c);
                    _activeFunctionParser.ParseFirstChar(c);
                    _state = ParserState.FUNCTION;
                }
                else
                {
                    return(EnterErrorState(ErrorType.UNPAIRED_PARENTHESIS));
                }
                return(GetSuccessState());
            }

            default:
                return(EnterErrorState(ErrorType.UNKNOWN));
            }
        }