Example #1
0
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (context.GetRoot() != null)
            {
                if (context.GetCurrentConj() != null)
                {
                    context.SetRoot(new Tree.OrNode((Tree.Node)context.GetRoot(), (Tree.Node)context.GetCurrentConj()));
                }
            }
            else
            {
                context.SetRoot(context.GetCurrentConj());
            }
            context.SetCurrentConj(null);
            if (ps.HasChar())
            {
                ChangeState(new InitState(GetParent()));
            }
        }
Example #2
0
        public INode Parse(string a)
        {
            IParserState state;

            _context = new StateContext(new ParseString(a.ToUpper()), null);
            ChangeState(new InitState(this));
            while (_states.Count > 0)
            {
                state = _states.Pop();
                state.ProcessState(_context);
            }
            return(_context.GetRoot());
        }
Example #3
0
        public override void ProcessState(IStateContext context)
        {
            IParseString ps = context.GetParseString();

            if (!ps.HasChar())
            {
                if (context.GetCurrentConj() != null)
                {
                    ChangeState(new AddConjunctionState(GetParent()));
                    return;
                }
                else if (context.GetRoot() == null)
                {
                    GetParent().SetError("Unexpected } of line at position" + ps.GetPosition().ToString());
                    ChangeState(new ErrorState(GetParent()));
                }
                return;
            }
            switch (ps.GetChar())
            {
            case 'X':
                ChangeState(new StartTermState(GetParent()));
                break;

            case '+':
                if (context.GetCurrentConj() != null)
                {
                    ChangeState(new AddConjunctionState(GetParent()));
                    return;
                }
                else
                {
                    GetParent().SetError("Unexpected char position " + ps.GetPosition().ToString());
                    ChangeState(new ErrorState(GetParent()));
                }
                break;

            case '(':
                ChangeState(new StartExprState(GetParent()));
                break;

            case ')':
                ChangeState(new EndExprState(GetParent()));
                break;

            default:
                GetParent().SetError("Unexpected char at position " + (ps.GetPosition() - 1).ToString());
                ChangeState(new ErrorState(GetParent()));
                break;
            }
        }
Example #4
0
        public override void ProcessState(IStateContext context)
        {
            IParseString  ps         = context.GetParseString();
            IStateContext oldcontext = context.GetPrevousContext();

            if (oldcontext == null)
            {
                GetParent().SetError("Unexpected closing parenthesis at pos  " + (ps.GetPosition() - 1).ToString());
                ChangeState(new ErrorState(GetParent()));
                return;
            }
            if (context.GetRoot() == null)
            {
                if (context.GetCurrentConj() != null)
                {
                    context.SetRoot(context.GetCurrentConj()); // êîíåö êîíúþíêöèè
                }
                else
                {
                    GetParent()
                    .SetError("Empty expression between parenthesis at pos " + ((ps.GetPosition() - 1).ToString()));
                    ChangeState(new ErrorState(GetParent()));
                    return;
                }
            }
            else
            {
                if (context.GetCurrentConj() != null)
                {
                    context.SetRoot(
                        new Tree.OrNode((Tree.Node)context.GetRoot(), (Tree.Node)context.GetCurrentConj()));
                }
            }
            context.SetCurrentConj(null);
            if (ps.HasChar() && ps.PeekChar() == '"')
            {
                ps.GetChar();
                if (context.GetRoot() != null)
                {
                    context.SetRoot(new Tree.NotNode((Tree.Node)context.GetRoot()));
                }
            }
            if (oldcontext.GetCurrentConj() != null)
            {
                oldcontext.SetCurrentConj(new Tree.AndNode((Tree.Node)oldcontext.GetCurrentConj(),
                                                           (Tree.Node)context.GetRoot()));
            }
            else
            {
                oldcontext.SetCurrentConj(context.GetRoot());
            }

            GetParent().ChangeContext(oldcontext);
            if (!ps.HasChar() && oldcontext.GetPrevousContext() != null)
            {
                GetParent().SetError("Not found close bracket at pos " + ((ps.GetPosition() - 1).ToString()));
                ChangeState(new ErrorState(GetParent()));
            }
            else
            {
                ChangeState(new InitState(GetParent()));
            }
        }