Esempio n. 1
0
 private BoundStatement BindStatement(StatementSyntaxNode node)
 {
     return(node.Kind switch
     {
         TokenKind.AbstractMethodDeclaration =>
         BindAbstractMethodDeclaration((AbstractMethodDeclarationSyntaxNode)node),
         TokenKind.BlockStatement =>
         BindBlockStatement((BlockStatementSyntaxNode)node),
         TokenKind.ClassDeclaration =>
         BindClassDeclaration((ClassDeclarationSyntaxNode)node),
         TokenKind.ConcreteMethodDeclaration =>
         BindConcreteMethodDeclaration((ConcreteMethodDeclarationSyntaxNode)node),
         TokenKind.EmptyStatement =>
         BindEmptyStatement((EmptyStatementSyntaxNode)node),
         TokenKind.ExpressionStatement =>
         BindExpressionStatement((ExpressionStatementSyntaxNode)node),
         TokenKind.ForStatement =>
         BindForStatement((ForStatementSyntaxNode)node),
         TokenKind.FunctionDeclaration =>
         BindFunctionDeclaration((FunctionDeclarationSyntaxNode)node),
         TokenKind.IfStatement =>
         BindIfStatement((IfStatementSyntaxNode)node),
         TokenKind.SwitchStatement =>
         BindSwitchStatement((SwitchStatementSyntaxNode)node),
         TokenKind.TryCatchStatement =>
         BindTryCatchStatement((TryCatchStatementSyntaxNode)node),
         TokenKind.WhileStatement =>
         BindWhileStatement((WhileStatementSyntaxNode)node),
         _ =>
         throw new Exception($"Invalid statement node kind '{node.Kind}'."),
     });
Esempio n. 2
0
        /// <summary>
        /// Core function for this object. It will attempt to build a source
        /// program tree from the stored list of tokens
        /// </summary>
        /// <returns></returns>
        public SyntaxNode ParseTree()
        {
            // Initialise the Query
            QuerySyntaxNode oQuery = new QuerySyntaxNode();

            // WHILE has tokens to process
            // Anytime we get here, create a new statement?
            while (TokenList.HasTokensLeftToProcess())
            {
                // Initialise a new statement every time we get here
                StatementSyntaxNode oStatement = new StatementSyntaxNode();

                // Pull off the first node
                SyntaxNode CurrentNode = SyntaxNodeFactory.ContextSensitiveConvertTokenToNode(new ParsingContext(oQuery, TokenList));

                // If we consumed anything
                if (CurrentNode.TryConsumeFromContext(new ParsingContext(CurrentNode, TokenList)))
                {
                }

                // Append to the statement anyways
                oStatement.Add(CurrentNode);

                oQuery.Add(oStatement);
            }

            // Return the Query
            return(oQuery);
        }
Esempio n. 3
0
        public StatementGenerator CreateStatement(BlockGenerator parentBlock, StatementSyntaxNode statement)
        {
            switch (statement)
            {
            case AssignmentStatementSyntaxNode assignment:
                return(new AssignmentStatementGenerator(this, parentBlock,
                                                        assignment.Variables.Select(v => CreateVariable(parentBlock, v)).ToList(),
                                                        assignment.Values));

            case GenericForBlockSyntaxNode genericFor:
                return(new GenericForStatementGenerator(this, parentBlock, genericFor));

            case GotoStatementSyntaxNode @goto:
                return(new GotoStatementGenerator(@goto.Target.Target));

            case IfStatementSyntaxNode @if:
                return(new IfStatementGenerator(this, parentBlock, @if));

            case InvocationStatementSyntaxNode invocation:
                return(new InvocationStatementGenerator(this, parentBlock, invocation));

            case LabelStatementSyntaxNode label:
                return(new LabelStatementGenerator(label));

            case LocalStatementSyntaxNode local:
                return(new AssignmentStatementGenerator(this, parentBlock,
                                                        local.Variables.Select(v => Function.Locals[v]).ToList(),
                                                        local.ExpressionList));

            case NumericForBlockSyntaxNode numericFor:
                return(new NumericForStatementGenerator(this, parentBlock, numericFor));

            case RepeatBlockSyntaxNode repeat:
                return(new RepeatStatementGenerator(this, parentBlock, repeat));

            case ReturnStatementSyntaxNode @return:
                if (@return.Values.Expressions.Count == 0)
                {
                    return(new ZeroReturnStatementGenerator());
                }
                else
                {
                    return(new MultiReturnStatementGenerator(this, parentBlock, @return));
                }

            case WhileBlockSyntaxNode @while:
                return(new WhileStatementGenerator(this, parentBlock, @while));

            case BlockSyntaxNode block:
                //Block as the last (should only match simple block and function definition).
                return(new BlockGenerator(this, parentBlock?.Stack ?? Function.LocalFragment, block));

            default:
                break;
            }
            throw new Exception();
        }
Esempio n. 4
0
 public TryCatchStatementSyntaxNode TryCatchStatementSyntax(SyntaxToken tryKeyword, StatementSyntaxNode tryBody, CatchClauseSyntaxNode?catchClause, SyntaxToken endKeyword)
 {
     return(new TryCatchStatementSyntaxNode(tryKeyword, tryBody, catchClause, endKeyword));
 }
Esempio n. 5
0
 public ForStatementSyntaxNode ForStatementSyntax(SyntaxToken forKeyword, AssignmentExpressionSyntaxNode assignment, SyntaxList <SyntaxToken> optionalCommas, StatementSyntaxNode body, SyntaxToken endKeyword)
 {
     return(new ForStatementSyntaxNode(forKeyword, assignment, optionalCommas, body, endKeyword));
 }
Esempio n. 6
0
 public IfStatementSyntaxNode IfStatementSyntax(SyntaxToken ifKeyword, ExpressionSyntaxNode condition, SyntaxList <SyntaxToken> optionalCommas, StatementSyntaxNode body, SyntaxList <ElseifClause> elseifClauses, ElseClause?elseClause, SyntaxToken endKeyword)
 {
     return(new IfStatementSyntaxNode(ifKeyword, condition, optionalCommas, body, elseifClauses, elseClause, endKeyword));
 }
Esempio n. 7
0
 public ElseClause ElseClause(SyntaxToken elseKeyword, StatementSyntaxNode body)
 {
     return(new ElseClause(elseKeyword, body));
 }
Esempio n. 8
0
 public ElseifClause ElseifClause(SyntaxToken elseifKeyword, ExpressionSyntaxNode condition, SyntaxList <SyntaxToken> optionalCommas, StatementSyntaxNode body)
 {
     return(new ElseifClause(elseifKeyword, condition, optionalCommas, body));
 }
Esempio n. 9
0
 public WhileStatementSyntaxNode WhileStatementSyntax(SyntaxToken whileKeyword, ExpressionSyntaxNode condition, SyntaxList <SyntaxToken> optionalCommas, StatementSyntaxNode body, SyntaxToken endKeyword)
 {
     return(new WhileStatementSyntaxNode(whileKeyword, condition, optionalCommas, body, endKeyword));
 }
Esempio n. 10
0
 public SwitchCaseSyntaxNode SwitchCaseSyntax(SyntaxToken caseKeyword, ExpressionSyntaxNode caseIdentifier, SyntaxList <SyntaxToken> optionalCommas, StatementSyntaxNode body)
 {
     return(new SwitchCaseSyntaxNode(caseKeyword, caseIdentifier, optionalCommas, body));
 }
Esempio n. 11
0
 public ConcreteMethodDeclarationSyntaxNode ConcreteMethodDeclarationSyntax(SyntaxToken functionKeyword, FunctionOutputDescriptionSyntaxNode?outputDescription, CompoundNameExpressionSyntaxNode name, FunctionInputDescriptionSyntaxNode?inputDescription, SyntaxList <SyntaxToken> commas, StatementSyntaxNode body, EndKeywordSyntaxNode?endKeyword)
 {
     return(new ConcreteMethodDeclarationSyntaxNode(functionKeyword, outputDescription, name, inputDescription, commas, body, endKeyword));
 }
Esempio n. 12
0
 public FunctionDeclarationSyntaxNode FunctionDeclarationSyntax(SyntaxToken functionKeyword, FunctionOutputDescriptionSyntaxNode?outputDescription, SyntaxToken name, FunctionInputDescriptionSyntaxNode?inputDescription, SyntaxList <SyntaxToken> commas, StatementSyntaxNode body, EndKeywordSyntaxNode?endKeyword)
 {
     return(new FunctionDeclarationSyntaxNode(functionKeyword, outputDescription, name, inputDescription, commas, body, endKeyword));
 }