当前位置: 首页>>代码示例>>C#>>正文


C# AST.getToken方法代码示例

本文整理汇总了C#中ProgrammingLanguageNr1.AST.getToken方法的典型用法代码示例。如果您正苦于以下问题:C# AST.getToken方法的具体用法?C# AST.getToken怎么用?C# AST.getToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgrammingLanguageNr1.AST的用法示例。


在下文中一共展示了AST.getToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: AddLocalVariables

        void AddLocalVariables(AST ast, VariableDefinition[] variableDefinitions)
        {
            AST nodeForDefiningGlobalVariables = ast.getChild(0).getChild(0);

            if(variableDefinitions == null) { return; }

            foreach(VariableDefinition vd in variableDefinitions) {

                Token token = new Token(Token.TokenType.VAR_DECLARATION,"<VAR_DECL>", ast.getToken().LineNr, ast.getToken().LinePosition);

                AST_VariableDeclaration declarationTree =
                    new AST_VariableDeclaration(token,
                                                vd.initValue.getReturnValueType(),
                                                vd.variableName);

                if(vd.initValue != null)
                {
                    AST assignmentTree = CreateAssignmentTreeFromInitValue(vd.variableName, vd.initValue);
                    AST declarationAndAssignmentTree = new AST(new Token(Token.TokenType.STATEMENT_LIST, "<DECLARATION_AND_ASSIGNMENT>", declarationTree.getToken().LineNr, declarationTree.getToken().LinePosition));
                    declarationAndAssignmentTree.addChild(declarationTree);
                    declarationAndAssignmentTree.addChild(assignmentTree);
                    nodeForDefiningGlobalVariables.addChild(declarationAndAssignmentTree);
                }
                else
                {
                    nodeForDefiningGlobalVariables.addChild(declarationTree);
                }
            }
        }
开发者ID:substans,项目名称:Sprak,代码行数:29,代码来源:SprakRunner.cs

示例3: functionCall

        private ReturnValue functionCall(AST tree)
        {
            ReturnValue returnValue = null;

            if (m_externalFunctionCreator.externalFunctions.ContainsKey(tree.getTokenString()))
            {
                ExternalFunctionCreator.OnFunctionCall functionCall = m_externalFunctionCreator.externalFunctions[tree.getTokenString()];
                if (functionCall != null)
                {
                    ReturnValue[] parameters = new ReturnValue[tree.getChildren().Count];
                    int i = 0;
                    foreach (AST parameter in tree.getChildren())
                    {
                        parameters[i] = execute(parameter);
                        i++;
                    }
                    returnValue = functionCall(parameters);
                }
                else
                {
                    throw new Error("Can't find external function " + tree.getTokenString(), Error.ErrorType.UNDEFINED, tree.getToken().LineNr, tree.getToken().LinePosition);
                }
            }
            else
            {
                // Call user defined function
                string functionName = tree.getTokenString();
                AST functionTree = getFunctionTreeNode(functionName);
                Assert.IsNotNull(functionTree);

                // Create list of parameter values
                List<ReturnValue> parameterValues = new List<ReturnValue>();
                List<AST> functionCallChildNodes = tree.getChildren();
                if (functionCallChildNodes != null)
                {
                    foreach(AST parameter in tree.getChildren())
                    {
                        ReturnValue val = execute(parameter);
                        parameterValues.Add(val);
                    }
                }

                returnValue = function(functionTree, parameterValues);
            }

            return returnValue;
        }
开发者ID:bloomingbridges,项目名称:hxSprak,代码行数:47,代码来源:Interpreter.cs

示例4: evaluateReferencesForVAR_DECLARATION

        private void evaluateReferencesForVAR_DECLARATION(AST tree)
        {
            AST_VariableDeclaration varDeclaration = tree as AST_VariableDeclaration;

            ReturnValueType typeToDeclare = varDeclaration.Type;
            string variableName = varDeclaration.Name;

            if (m_currentScope.isDefined(variableName))
            {
                m_errorHandler.errorOccured(
                    new Error("There is already a variable called '" + variableName + "'",
                    Error.ErrorType.LOGIC,
                    tree.getToken().LineNr,
                    tree.getToken().LinePosition));
            }
            else
            {
                m_currentScope.define(new VariableSymbol(variableName, typeToDeclare));
            #if WRITE_DEBUG_INFO
                Console.WriteLine("Defined variable with name " + variableName + " and type " + typeToDeclare + " (on line " + tree.getToken().LineNr + ")" + " in " + m_currentScope);
            #endif
            }
        }
开发者ID:substans,项目名称:Sprak,代码行数:23,代码来源:ScopeBuilder.cs

示例5: evaluateReferencesForNAME

        private void evaluateReferencesForNAME(AST tree)
        {
            Symbol symbol = m_currentScope.resolve(tree.getTokenString());

            if(symbol == null) {
                m_errorHandler.errorOccured(
                                            new  Error("Can't find anything called '" + tree.getTokenString() + "'",
                                                       Error.ErrorType.SYNTAX,
                                                       tree.getToken().LineNr,
                                                       tree.getToken().LinePosition));
            }
            else if (symbol is FunctionSymbol) {
                m_errorHandler.errorOccured(
                                            new  Error("'" + tree.getTokenString() + "' is a function and must be called with ()",
                                                       Error.ErrorType.SYNTAX,
                                                       tree.getToken().LineNr,
                                                       tree.getToken().LinePosition));
            }

            #if WRITE_DEBUG_INFO
            Console.WriteLine("Resolved symbol with name " + tree.getTokenString() + " (on line " + tree.getToken().LineNr + ")" + " in " + m_currentScope);
            #endif

            evaluateReferencesInAllChildren(tree);
        }
开发者ID:substans,项目名称:Sprak,代码行数:25,代码来源:ScopeBuilder.cs

示例6: evaluateReferencesForFUNCTION_CALL

        private void evaluateReferencesForFUNCTION_CALL(AST tree)
        {
            // Function name:
            string functionName = tree.getTokenString();
            FunctionSymbol function = (FunctionSymbol)m_currentScope.resolve(functionName);

            if (function == null)
            {
                m_errorHandler.errorOccured("Can't find function with name " + functionName,
                                            Error.ErrorType.SCOPE,
                                            tree.getToken().LineNr,
                                            tree.getToken().LinePosition
                                            );
            }
            else
            {
                #if WRITE_DEBUG_INFO
                Console.WriteLine("Resolved function call with name " + functionName + " (on line " + tree.getToken().LineNr + ")");
                #endif

                // Parameters
                evaluateReferencesInAllChildren(tree);

                AST node = function.getFunctionDefinitionNode();
                AST_FunctionDefinitionNode functionDefinitionTree = (AST_FunctionDefinitionNode)(node);

                /*if(functionDefinitionTree.getTokenString() != "<EXTERNAL_FUNC_DECLARATION>") {
                    evaluateReferencesForFUNC_DECLARATION(functionDefinitionTree);
                }*/

                // Setup reference to Function Definition AST node
                AST_FunctionCall functionCallAst = tree as AST_FunctionCall;
                Debug.Assert(functionCallAst != null);
                functionCallAst.FunctionDefinitionRef = functionDefinitionTree;

                List<AST> calleeParameterList = functionDefinitionTree.getChild(2).getChildren();

                // Check that the number of arguments is right
                AST callerParameterList = tree.getChild(0);
                List<AST> arguments = callerParameterList.getChildren();

                if (arguments.Count != calleeParameterList.Count)
                {
                    m_errorHandler.errorOccured(
                        "Wrong number of arguments to function"
                        , Error.ErrorType.SYNTAX, tree.getToken().LineNr, tree.getToken().LinePosition);
                }
            }
        }
开发者ID:substans,项目名称:Sprak,代码行数:49,代码来源:ScopeBuilder.cs

示例7: evaluateReferencesForASSIGNMENT_TO_ARRAY

        private void evaluateReferencesForASSIGNMENT_TO_ARRAY(AST tree)
        {
            AST_Assignment assignment = tree as AST_Assignment;

            Symbol variableNameSymbol = m_currentScope.resolve(assignment.VariableName);
            if(variableNameSymbol == null) {
                m_errorHandler.errorOccured("Can't assign to undefined array " + assignment.VariableName,
                                Error.ErrorType.SYNTAX,
                                tree.getToken().LineNr,
                                tree.getToken().LinePosition);
            }

            evaluateReferencesInAllChildren(tree);
        }
开发者ID:substans,项目名称:Sprak,代码行数:14,代码来源:ScopeBuilder.cs


注:本文中的ProgrammingLanguageNr1.AST.getToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。