public override void ProcessState(IStateContext context) { IStateContext newcontext = new StateContext(context.GetParseString(), context); GetParent().ChangeContext(newcontext); ChangeState(new InitState(GetParent())); }
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; } }
public override void ProcessState(IStateContext context) { IParseString ps = context.GetParseString(); if (ps.HasChar()) { if (Char.IsDigit(ps.PeekChar())) { ps.CollectTerm(); ChangeState(new CollectTermState(GetParent())); return; } } ChangeState(new AddTermState(GetParent())); }
public override void ProcessState(IStateContext context) { IParseString ps = context.GetParseString(); if (ps.HasChar()) { switch (ps.GetChar()) { case 'X': ChangeState(new StartTermState(GetParent())); break; case '+': if (!ps.HasChar() || ps.PeekChar() != 'X' && ps.PeekChar() != '(') { GetParent().SetError("second term isn't found at position " + ps.GetPosition().ToString()); ChangeState(new ErrorState(GetParent())); } else { ChangeState(new AddConjunctionState(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; } } else { ChangeState(new AddConjunctionState(GetParent())); } }
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())); } }
public override void ProcessState(IStateContext context) { IParseString ps = context.GetParseString(); Tree v = new Tree(ps.GetVarNum()); if (ps.HasChar() && ps.PeekChar() == '"') { ps.GetChar(); v.AddNot(); } if (context.GetCurrentConj() == null) { context.SetCurrentConj(v.ReturnRoot()); } else { context.SetCurrentConj(new Tree.AndNode((Tree.Node)context.GetCurrentConj(), (Tree.Node)v.ReturnRoot())); } ps.ClearTerm(); ChangeState(new FindOperationState(GetParent())); }
public override void ProcessState(IStateContext context) { IParseString ps = context.GetParseString(); if (!ps.HasChar()) { GetParent().SetError("Missed number of variable at } of expression'"); ChangeState(new ErrorState(GetParent())); return; } if (Char.IsDigit(ps.PeekChar())) { ps.ClearTerm(); ps.CollectTerm(); ChangeState(new CollectTermState(GetParent())); } else { GetParent().SetError("Unexpected char at position " + ps.GetPosition().ToString()); ChangeState(new ErrorState(GetParent())); } }
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())); } }