ASTNode HandleUnary(SherlockToken token, ASTNode currentNode) { GC.KeepAlive(token); currentNode.Operation = ASTOperation.Not; currentNode.First = new ASTNode(currentNode); return(currentNode.First); }
ASTNode HandleParentheses(SherlockToken token, ASTNode currentNode) { if (token.TokenType == SherlockTokenType.ParenthesesBegin) { currentNode.First = new ASTNode(currentNode); return(currentNode.First); } return(currentNode.Parent); }
public ASTNode Parse(string toParse) { ASTNode currentNode = new ASTNode(null); SherlockToken currentToken = null; try { lexer.PresetProgram(new StringReader(toParse)); while ((currentToken = lexer.ReadNext()) != null) { state.CurrentColumn = currentToken.Column; if (!state.StateMachine.CanFire(currentToken.TokenType)) { throw new InvalidOperationException(); } state.StateMachine.Fire(currentToken.TokenType); switch (currentToken.TokenType) { case SherlockTokenType.UnaryOperator: break; case SherlockTokenType.BinaryOperator: break; case SherlockTokenType.Label: break; } } } catch (ParsingErrorException) { throw new ParsingErrorException(string.Format("Unexpected character '{0}' at column {1}.", currentToken.Value ?? "", currentToken.Column)); } return(toReturn); }
ASTNode HandleBinary(SherlockToken token, ASTNode currentNode) { GC.KeepAlive(token); ASTNode tempNode = GetFreeNode(currentNode); if (token.Value == "&&") { tempNode.Operation = ASTOperation.And; } else if (token.Value == "||") { tempNode.Operation = ASTOperation.Or; } if (tempNode.Parent == null) { toReturn = tempNode; } return(tempNode.Second); }
ASTNode HandleValues(SherlockToken token, ASTNode currentNode) { currentNode.Value = token.Value; return(currentNode); }
ASTNode HandleBraces(SherlockToken token, ASTNode currentNode) { GC.KeepAlive(token); return(currentNode); }