當前位置: 首頁>>代碼示例>>C#>>正文


C# AST.getTokenType方法代碼示例

本文整理匯總了C#中ProgrammingLanguageNr1.AST.getTokenType方法的典型用法代碼示例。如果您正苦於以下問題:C# AST.getTokenType方法的具體用法?C# AST.getTokenType怎麽用?C# AST.getTokenType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ProgrammingLanguageNr1.AST的用法示例。


在下文中一共展示了AST.getTokenType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: evaluate

 private float evaluate(AST tree)
 {
     float returnValue = 0;
     if(tree.getTokenType() == Token.TokenType.NUMBER) {
         returnValue = (float)System.Convert.ToDouble(tree.getTokenString());
     }
     else if(tree.getTokenType() == Token.TokenType.OPERATOR) {
         if(tree.getTokenString() == "+") {
             returnValue = evaluate(tree.getChild(0)) + evaluate(tree.getChild(1));
         }
         else if(tree.getTokenString() == "-") {
             returnValue = evaluate(tree.getChild(0)) - evaluate(tree.getChild(1));
         }
         else if(tree.getTokenString() == "*") {
             returnValue = evaluate(tree.getChild(0)) * evaluate(tree.getChild(1));
         }
         else if(tree.getTokenString() == "/") {
             returnValue = evaluate(tree.getChild(0)) / evaluate(tree.getChild(1));
         }
         else if(tree.getTokenString() == "<") {
             returnValue = (evaluate(tree.getChild(0)) < evaluate(tree.getChild(1))) ? 1 : 0;
         }
         else if(tree.getTokenString() == ">") {
             returnValue = (evaluate(tree.getChild(0)) > evaluate(tree.getChild(1))) ? 1 : 0;
         }
         else if(tree.getTokenString() == "<=") {
             returnValue = (evaluate(tree.getChild(0)) <= evaluate(tree.getChild(1))) ? 1 : 0;
         }
         else if(tree.getTokenString() == ">=") {
             returnValue = (evaluate(tree.getChild(0)) >= evaluate(tree.getChild(1))) ? 1 : 0;
         }
         else if(tree.getTokenString() == "&&") {
             returnValue = (evaluate(tree.getChild(0)) != 0 && evaluate(tree.getChild(1)) != 0) ? 1 : 0;
         }
         else if(tree.getTokenString() == "||") {
             returnValue = (evaluate(tree.getChild(0)) != 0 || evaluate(tree.getChild(1)) != 0) ? 1 : 0;
         }
         else if(tree.getTokenString() == "!=") {
             returnValue = (evaluate(tree.getChild(0)) != evaluate(tree.getChild(1))) ? 1 : 0;
         }
         else if(tree.getTokenString() == "==") {
             returnValue = (evaluate(tree.getChild(0)) == evaluate(tree.getChild(1))) ? 1 : 0;
         }
         else {
             throw new InvalidOperationException("ExpressionEvaluator can't handle operators with string " + tree.getTokenString());
         }
     }
     else {
         throw new InvalidOperationException("ExpressionEvaluator can't handle tokens of type " + tree.getTokenType());
     }
     return returnValue;
 }
開發者ID:bloomingbridges,項目名稱:hxSprak,代碼行數:52,代碼來源:ExpressionEvaluator.cs

示例2: addToList

        private void addToList(List<AST> list, AST ast)
        {
            switch (ast.getTokenType())
            {
                case  Token.TokenType.FUNC_DECLARATION:
                    addToList(list, ast.getChild(2));
                    addToList(list, ast.getChild(3));
                    break;

                case Token.TokenType.IF:
                    addToList(list, ast.getChild(0));
                    list.Add(ast);
            #if WRITE_DEBUG_INFO
                    Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
            #endif
                    break;

                case Token.TokenType.LOOP:
                    list.Add(ast);
            #if WRITE_DEBUG_INFO
                    Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
            #endif
                    break;

                case Token.TokenType.LOOP_BLOCK:
                    list.Add(ast);
            #if WRITE_DEBUG_INFO
                    Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
            #endif
                    break;

                default:
                    addChildren(list, ast);
            #if WRITE_DEBUG_INFO
                    Console.WriteLine(": " + ast.getTokenString() + " of type " + ast.getTokenType());
            #endif
                    list.Add(ast);
                    break;
            }
        }
開發者ID:substans,項目名稱:Sprak,代碼行數:40,代碼來源:MemorySpace.cs

示例3: evaluateScopeDeclarations

        private void evaluateScopeDeclarations(AST tree)
        {
            Debug.Assert(tree != null);

            if (tree.getTokenType() == Token.TokenType.FUNC_DECLARATION)
            {
                evaluateFunctionScope(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.IF) {
                evaluateIfScope(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.LOOP) {
                evaluateLoopScope(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.LOOP_BLOCK) {
               	evaluateLoopBlockScope(tree);
            }
            else if (tree.getChildren() != null)
            {
                evaluateScopeDeclarationsInAllChildren(tree);
            }
        }
開發者ID:substans,項目名稱:Sprak,代碼行數:22,代碼來源:ScopeBuilder.cs

示例4: execute

        private ReturnValue execute(AST tree)
        {
            Token.TokenType tokenType = tree.getToken().getTokenType();
            ReturnValue returnValue = null;

            if (tokenType == Token.TokenType.FUNC_DECLARATION)
            {
                return new ReturnValue();
            }

            #if WRITE_DEBUG_INFO
            Console.WriteLine("Executing " + tree.getTokenType() + " " + tree.getTokenString());
            #endif

            if (tokenType == Token.TokenType.STATEMENT_LIST)
            {
                executeAllChildNodes(tree);
            }
            else if (tokenType == Token.TokenType.FUNCTION_CALL) {
                returnValue = functionCall(tree);
            }
            else if (tokenType == Token.TokenType.NAME) {
                returnValue = name(tree);
            }
            else if (tokenType == Token.TokenType.NUMBER) {
                returnValue = number(tree);
            }
            else if (tokenType == Token.TokenType.OPERATOR) {
                returnValue = operation(tree);
            }
            else if (tokenType == Token.TokenType.QUOTED_STRING) {
                returnValue = quotedString(tree);
            }
            else if (tokenType == Token.TokenType.IF) {
                ifThenElse(tree);
            }
            else if (tokenType == Token.TokenType.VAR_DECLARATION) {
                varDeclaration(tree);
            }
            else if (tokenType == Token.TokenType.ASSIGNMENT) {
                assignment(tree);
            }
            else if (tokenType == Token.TokenType.RETURN) {
                returnStatement(tree);
            }
            else {
                throw new NotImplementedException("The interpreter hasn't got support for token type " + tokenType + " yet!");
            }
            return returnValue;
        }
開發者ID:bloomingbridges,項目名稱:hxSprak,代碼行數:50,代碼來源:Interpreter.cs

示例5: evaluateReferences

        private void evaluateReferences(AST tree)
        {
            Debug.Assert(tree != null);

            if (tree.getTokenType() == Token.TokenType.VAR_DECLARATION)
            {
                evaluateReferencesForVAR_DECLARATION(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.ASSIGNMENT)
            {
                evaluateReferencesForASSIGNMENT(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.ASSIGNMENT_TO_ARRAY)
            {
                evaluateReferencesForASSIGNMENT_TO_ARRAY(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.FUNC_DECLARATION)
            {
                evaluateReferencesForFUNC_DECLARATION(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.FUNCTION_CALL)
            {
                evaluateReferencesForFUNCTION_CALL(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.IF)
            {
                evaluateReferencesForIF(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.NAME)
            {
                evaluateReferencesForNAME(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.LOOP_BLOCK)
            {
                evaluateReferencesForLOOP_BLOCK(tree);
            }
            else if (tree.getTokenType() == Token.TokenType.LOOP)
            {
                evaluateReferencesForLOOP(tree);
            }
            else
            {
                evaluateReferencesInAllChildren(tree);
            }
        }
開發者ID:substans,項目名稱:Sprak,代碼行數:45,代碼來源:ScopeBuilder.cs


注:本文中的ProgrammingLanguageNr1.AST.getTokenType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。