/// <summary> /// Parsing condition in format [id] [operation] [id] /// If you want another modification, you may change this function /// </summary> /// <param name="left"></param> private void ParseCondition(LexAnalyzer.Token left) { var operation = TokenQueue.Dequeue(); var right = TokenQueue.Dequeue(); InputQueue.Enqueue(new ConditionElement(left, operation, right)); }
private void GetRightNmr(LexAnalyzer.Token token) { if (token.Type == LexAnalyzer.TokenTypes.Number) { RightValue = Convert.ToInt32(token.Value); } else if (token.Type == LexAnalyzer.TokenTypes.Hex) { RightValue = Convert.ToInt32(token.Value.Substring(2), 16); // skips 0x prefix } else { throw new SyntacticException("Unexpected token " + token.ToString()); } }
/// <summary> /// Parse token to element /// </summary> /// <param name="t">Token to parse</param> private void PushIntoInput(LexAnalyzer.Token t) { switch (t.Type) { case LexAnalyzer.TokenTypes.Id: string upper = t.Value.ToUpper(); switch (upper) /* Keywords parses to specials treeelements, in other case parse it as condition */ { case "AND": InputQueue.Enqueue(new TreeElement(TreeCode.And)); break; case "OR": InputQueue.Enqueue(new TreeElement(TreeCode.Or)); break; case "NOT": InputQueue.Enqueue(new TreeElement(TreeCode.Not)); break; default: ParseCondition(t); break; } break; case LexAnalyzer.TokenTypes.LBracket: InputQueue.Enqueue(new TreeElement(TreeCode.LBracket)); break; case LexAnalyzer.TokenTypes.RBracket: InputQueue.Enqueue(new TreeElement(TreeCode.RBracket)); break; case LexAnalyzer.TokenTypes.End: InputQueue.Enqueue(new TreeElement(TreeCode.End)); break; default: throw new SyntacticException("Unexpected token " + t.Type.ToString()); } }