当前位置: 首页>>代码示例>>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;未经允许,请勿转载。