예제 #1
0
 ASTNode HandleUnary(SherlockToken token, ASTNode currentNode)
 {
     GC.KeepAlive(token);
     currentNode.Operation = ASTOperation.Not;
     currentNode.First     = new ASTNode(currentNode);
     return(currentNode.First);
 }
예제 #2
0
 ASTNode HandleParentheses(SherlockToken token, ASTNode currentNode)
 {
     if (token.TokenType == SherlockTokenType.ParenthesesBegin)
     {
         currentNode.First = new ASTNode(currentNode);
         return(currentNode.First);
     }
     return(currentNode.Parent);
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
 ASTNode HandleValues(SherlockToken token, ASTNode currentNode)
 {
     currentNode.Value = token.Value;
     return(currentNode);
 }
예제 #6
0
 ASTNode HandleBraces(SherlockToken token, ASTNode currentNode)
 {
     GC.KeepAlive(token);
     return(currentNode);
 }