getTokenString() публичный Метод

public getTokenString ( ) : string
Результат string
Пример #1
0
        private AST plusplusOrMinusminus()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("plusplusOrMinusminus");
#endif
            Token nameToken     = match(Token.TokenType.NAME);
            Token operatorToken = match(Token.TokenType.OPERATOR);

            AST operationTree = null;

            if (operatorToken.getTokenString() == "++")
            {
                operationTree = new AST(new Token(Token.TokenType.OPERATOR, "+"));
            }
            else if (operatorToken.getTokenString() == "--")
            {
                operationTree = new AST(new Token(Token.TokenType.OPERATOR, "-"));
            }
            else
            {
                throw new Exception("Error!");
            }

            operationTree.addChild(new AST(nameToken));
            operationTree.addChild(new AST(new TokenWithValue(Token.TokenType.NUMBER, "1", new ReturnValue(1.0f))));

            AST assignmentTree = new AST_Assignment(new Token(Token.TokenType.ASSIGNMENT, "="), nameToken.getTokenString());
            assignmentTree.addChild(operationTree);

            return(assignmentTree);
        }
Пример #2
0
 void checkRightHandSide(AST rhs, Token operatorToken)
 {
     if (rhs == null)
     {
         m_errorHandler.errorOccured(
             "No expression on the right side of '" + operatorToken.getTokenString() + "'",
             Error.ErrorType.SYNTAX, operatorToken.LineNr, operatorToken.LinePosition + 2);
     }
 }
Пример #3
0
        private AST assignmentAndOperator()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("assignment and operator");
#endif

            Token nameToken      = match(Token.TokenType.NAME);
            Token operatorToken  = match(Token.TokenType.OPERATOR);
            AST   expressionTree = expression();

            if (expressionTree != null)
            {
                AST_Assignment assignmentTree = new AST_Assignment(new Token(Token.TokenType.ASSIGNMENT, "="), nameToken.getTokenString());
                AST            selfOperation  = null;

                if (operatorToken.getTokenString() == "+=")
                {
                    selfOperation = new AST(new Token(Token.TokenType.OPERATOR, "+"));
                }
                else
                {
                    throw new Error("Can't handle the operator '" + operatorToken.getTokenString() + "'",
                                    Error.ErrorType.SYNTAX, assignmentTree.getToken().LineNr,
                                    assignmentTree.getToken().LinePosition);
                }
                selfOperation.addChild(nameToken);
                selfOperation.addChild(expressionTree);
                assignmentTree.addChild(selfOperation);

                return(assignmentTree);
            }
            else
            {
                throw new Error("The expression after " + operatorToken.getTokenString()
                                + " makes no sense", Error.ErrorType.SYNTAX,
                                operatorToken.LineNr, operatorToken.LinePosition);
            }
        }
Пример #4
0
        private AST_VariableDeclaration declaration()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("declaration");
#endif
            Token typeName     = match(Token.TokenType.BUILT_IN_TYPE_NAME);
            Token variableName = match(Token.TokenType.NAME);

            AST_VariableDeclaration declarationTree = new AST_VariableDeclaration(
                new Token(Token.TokenType.VAR_DECLARATION, "<VAR_DECL>", lookAhead(1).LineNr, lookAhead(1).LinePosition),
                ReturnValue.getReturnValueTypeFromString(typeName.getTokenString()),
                variableName.getTokenString());

            return(declarationTree);
        }
Пример #5
0
        public override bool Equals(object obj)
        {
            if (obj is Token)
            {
                Token other = obj as Token;

                if (this.getTokenString() == "")
                {
                    return(m_tokenType == other.getTokenType());
                }
                else
                {
                    return(m_tokenString == other.getTokenString());
                }
            }

            return(false);
        }
Пример #6
0
        private AST assignment()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("assignment");
#endif

            Token nameToken       = match(Token.TokenType.NAME);
            Token assignmentToken = match(Token.TokenType.ASSIGNMENT);
            AST   expressionTree  = expression();

            if (expressionTree != null)
            {
                AST_Assignment assignmentTree = new AST_Assignment(assignmentToken, nameToken.getTokenString());
                assignmentTree.addChild(expressionTree);

                return(assignmentTree);
            }
            else
            {
                throw new Error("The expression after = makes no sense", Error.ErrorType.SYNTAX,
                                assignmentToken.LineNr, assignmentToken.LinePosition);
            }
        }
Пример #7
0
 void checkRightHandSide(AST rhs, Token operatorToken)
 {
     if(rhs == null) {
         throw new Error("No expression on the right side of '" + operatorToken.getTokenString() + "'",
             Error.ErrorType.SYNTAX, operatorToken.LineNr, operatorToken.LinePosition + 2);
     }
 }
Пример #8
0
 void checkLeftHandSide(AST lhs, Token operatorToken)
 {
     if(lhs == null) {
         throw new Error("No expression on the left side of '" + operatorToken.getTokenString() + "'",
             Error.ErrorType.SYNTAX, operatorToken.LineNr, operatorToken.LinePosition - 1);
     }
 }
Пример #9
0
        private AST assignmentToArray()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("assignment to array");
#endif

            Token nameToken = null;
            AST   indexNode = null;

                        #if WRITE_DEBUG_INFO
            Console.WriteLine("normal array");
                        #endif
            nameToken = match(Token.TokenType.NAME);
            match(Token.TokenType.BRACKET_LEFT);
            indexNode = expression();
            match(Token.TokenType.BRACKET_RIGHT);

            if (lookAheadType(1) == Token.TokenType.NEW_LINE ||
                lookAheadType(1) == Token.TokenType.EOF)
            {
                // it's a statement without assignment
                return(indexNode);
            }

            Token assignmentToken = match(Token.TokenType.ASSIGNMENT);
            AST   expressionTree  = expression();

            if (expressionTree != null)
            {
                Token          arrayAssignmentToken = new Token(Token.TokenType.ASSIGNMENT_TO_ARRAY, "=", assignmentToken.LineNr, assignmentToken.LinePosition);
                AST_Assignment assignmentTree       = new AST_Assignment(arrayAssignmentToken, nameToken.getTokenString());
                assignmentTree.addChild(indexNode);
                assignmentTree.addChild(expressionTree);

                /*ASTPainter p = new ASTPainter();
                 * Console.WriteLine("---AST---");
                 * p.PaintAST(assignmentTree);
                 * Console.WriteLine("---------");*/
                return(assignmentTree);
            }
            else
            {
                throw new Error("The expression after = makes no sense", Error.ErrorType.SYNTAX,
                                assignmentToken.LineNr, assignmentToken.LinePosition);
            }
        }
Пример #10
0
        private AST functionCall()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("function call");
#endif

            Token nameToken = match(Token.TokenType.NAME);

            AST functionCallTree =
                new AST_FunctionCall(new Token(Token.TokenType.FUNCTION_CALL, nameToken.getTokenString(), nameToken.LineNr, nameToken.LinePosition));

            match(Token.TokenType.PARANTHESIS_LEFT);

            functionCallTree.getToken().LineNr       = nameToken.LineNr;
            functionCallTree.getToken().LinePosition = nameToken.LinePosition;

            AST argumentList = new AST(new Token(Token.TokenType.NODE_GROUP, "<ARGUMENT_LIST>"));

            if (lookAheadType(1) != Token.TokenType.PARANTHESIS_RIGHT)
            {
                while (true)
                {
                    AST expressionTree = expression();

                    if (expressionTree != null)
                    {
                        argumentList.addChild(expressionTree);                         // add arguments as subtrees
                    }
                    else
                    {
                        throw new Error("Something is wrong with the argument list", Error.ErrorType.SYNTAX,
                                        lookAhead(1).LineNr, lookAhead(1).LinePosition);
                    }

                    if (lookAheadType(1) == Token.TokenType.COMMA)
                    {
                        match(Token.TokenType.COMMA);
                        continue;
                    }
                    else
                    {
                        // Is something wrong?
                        if (lookAheadType(1) == Token.TokenType.NEW_LINE ||
                            lookAheadType(1) == Token.TokenType.EOF)
                        {
                            throw new Error("Ending parenthesis is missing in function call"
                                            , Error.ErrorType.SYNTAX,
                                            lookAhead(1).LineNr, lookAhead(1).LinePosition);
                        }
                        else if (lookAheadType(1) == Token.TokenType.NAME ||
                                 lookAheadType(1) == Token.TokenType.QUOTED_STRING ||
                                 lookAheadType(1) == Token.TokenType.NUMBER)
                        {
                            throw new Error("A comma is missing in argument list"
                                            , Error.ErrorType.SYNTAX,
                                            lookAhead(1).LineNr, lookAhead(1).LinePosition);
                        }

                        break;
                    }
                }
            }

            match(Token.TokenType.PARANTHESIS_RIGHT);

            functionCallTree.addChild(argumentList);

            return(functionCallTree);
        }
Пример #11
0
        private AST operand()
        {
#if WRITE_DEBUG_INFO
            Console.WriteLine("operand");
#endif

            AST operandTree = null;

            if (lookAheadType(1) == Token.TokenType.NAME &&
                lookAheadType(2) == Token.TokenType.PARANTHESIS_LEFT)
            {
                operandTree = functionCall();
            }
            else if (lookAheadType(1) == Token.TokenType.NAME &&
                     lookAheadType(2) == Token.TokenType.BRACKET_LEFT)
            {
                operandTree = arrayLookup();
            }
            else if (lookAheadType(1) == Token.TokenType.FROM)
            {
                operandTree = fromMinToMaxArrayCreation();
            }
            else if (lookAheadType(1) == Token.TokenType.NAME)
            {
                Token operandToken = match(Token.TokenType.NAME);
                operandTree = new AST(operandToken);
            }
            else if (lookAheadType(1) == Token.TokenType.NUMBER)
            {
                Token operandToken = match(Token.TokenType.NUMBER);


                float number = (float)Convert.ToDouble(operandToken.getTokenString(),
                                                       CultureInfo.InvariantCulture
                                                       );

                operandTree = new AST(new TokenWithValue(operandToken.getTokenType(),
                                                         operandToken.getTokenString(),
                                                         new ReturnValue(number)));
            }
            else if (lookAheadType(1) == Token.TokenType.QUOTED_STRING)
            {
                Token operandToken = match(Token.TokenType.QUOTED_STRING);
                operandTree = new AST(new TokenWithValue(operandToken.getTokenType(),
                                                         operandToken.getTokenString(),
                                                         new ReturnValue(operandToken.getTokenString())));
            }
            else if (lookAheadType(1) == Token.TokenType.BOOLEAN_VALUE)
            {
                Token operandToken = match(Token.TokenType.BOOLEAN_VALUE);
                bool  boolean      = operandToken.getTokenString() == "true" ? true : false;
                operandTree = new AST(new TokenWithValue(operandToken.getTokenType(),
                                                         operandToken.getTokenString(),
                                                         new ReturnValue(boolean)));
            }
            else if (lookAheadType(1) == Token.TokenType.OPERATOR &&
                     lookAhead(1).getTokenString() == "-")
            {
                operandTree = negativeExpression();
            }
            else if (lookAheadType(1) == Token.TokenType.BRACKET_LEFT)
            {
                operandTree = arrayCreation();
            }

            return(operandTree);
        }