コード例 #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));
            }
        }
コード例 #2
0
        private ParserStatus ParsePartialFunction(char c)
        {
            if (char.IsLetter(c))
            {
                _cache += c;
                return(GetSuccessState());
            }

            _activeFunctionParser = FunctionParser.MakeFunctionParser(_cache);
            if (_activeFunctionParser == null)
            {
                return(EnterErrorState(ErrorType.INVALID_FUNCTION));
            }

            _state = ParserState.FUNCTION;
            _cache = string.Empty;
            ParseError parseError = _activeFunctionParser.ParseFirstChar(c);

            return(GetSuccessState(parseError));
        }