コード例 #1
0
        public override ASTNode VisitFunctionCall([NotNull] DaedalusParser.FunctionCallContext context)
        {
            DaedalusParser.NameNodeContext nameNodeContext = context.nameNode();
            ReferenceNode referenceNode = new ReferenceNode(nameNodeContext.GetText(), GetLocation(nameNodeContext));

            ReferenceNodes.Add(referenceNode);
            List <ExpressionNode> expressionNodes = new List <ExpressionNode>();

            foreach (DaedalusParser.ExpressionContext expressionContext in context.expression())
            {
                expressionNodes.Add((ExpressionNode)Visit(expressionContext));
            }

            return(new FunctionCallNode(GetLocation(context), referenceNode, expressionNodes));
        }
コード例 #2
0
        private VarDeclarationsTemporaryNode GetVarDeclarationsTemporaryNode(DaedalusParser.VarDeclContext varDeclContext)
        {
            NameNode typeNameNode = new NameNode(GetLocation(varDeclContext.dataType()), varDeclContext.dataType().GetText());

            List <DeclarationNode> varDeclarationNodes = new List <DeclarationNode>();

            foreach (IParseTree childContext in varDeclContext.children)
            {
                if (childContext is DaedalusParser.VarValueDeclContext varValueDeclContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = varValueDeclContext.nameNode();
                    NameNode nameNode = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());

                    ExpressionNode rightSideNode = null;
                    if (varValueDeclContext.varValueAssignment() != null)
                    {
                        rightSideNode = (ExpressionNode)Visit(varValueDeclContext.varValueAssignment().expression());                          // TODO check if null
                    }

                    varDeclarationNodes.Add(new VarDeclarationNode(GetLocation(varValueDeclContext), typeNameNode, nameNode, rightSideNode));
                }
                else if (childContext is DaedalusParser.VarArrayDeclContext varArrayDeclContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = varArrayDeclContext.nameNode();
                    NameNode       nameNode      = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                    ExpressionNode arraySizeNode = (ExpressionNode)VisitArraySize(varArrayDeclContext.arraySize());


                    List <ExpressionNode> elementNodes = null;
                    if (varArrayDeclContext.varArrayAssignment() != null)
                    {
                        elementNodes = new List <ExpressionNode>();
                        foreach (DaedalusParser.ExpressionContext expressionContext in varArrayDeclContext.varArrayAssignment().expression())
                        {
                            elementNodes.Add((ExpressionNode)Visit(expressionContext));
                        }
                    }

                    VarArrayDeclarationNode varArrayDeclarationNode =
                        new VarArrayDeclarationNode(GetLocation(nameNodeContext), typeNameNode, nameNode, arraySizeNode, elementNodes);                         // TODO check if null
                    _arrayDeclarationNodes.Add(varArrayDeclarationNode);
                    varDeclarationNodes.Add(varArrayDeclarationNode);
                }
            }
            return(new VarDeclarationsTemporaryNode(GetLocation(varDeclContext), varDeclarationNodes));
        }
コード例 #3
0
        private ConstDefinitionsTemporaryNode GetConstDefinitionsTemporaryNode(DaedalusParser.ConstDefContext constDefContext)
        {
            NameNode typeNameNode = new NameNode(GetLocation(constDefContext.dataType()), constDefContext.dataType().GetText());

            List <DeclarationNode> constDefinitionNodes = new List <DeclarationNode>();

            foreach (IParseTree childContext in constDefContext.children)
            {
                if (childContext is DaedalusParser.ConstValueDefContext constValueDefContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = constValueDefContext.nameNode();
                    NameNode            nameNode            = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                    ExpressionNode      rightSideNode       = (ExpressionNode)Visit(constValueDefContext.constValueAssignment().expression());
                    ConstDefinitionNode constDefinitionNode = new ConstDefinitionNode(GetLocation(constValueDefContext),
                                                                                      typeNameNode, nameNode, rightSideNode);
                    _constDefinitionNodes.Add(constDefinitionNode);
                    constDefinitionNodes.Add(constDefinitionNode);
                }
                else if (childContext is DaedalusParser.ConstArrayDefContext constArrayDefContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = constArrayDefContext.nameNode();
                    NameNode       nameNode      = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                    ExpressionNode arraySizeNode = (ExpressionNode)VisitArraySize(constArrayDefContext.arraySize());

                    List <ExpressionNode> elementNodes = new List <ExpressionNode>();
                    foreach (DaedalusParser.ExpressionContext expressionContext in constArrayDefContext.constArrayAssignment().expression())
                    {
                        elementNodes.Add((ExpressionNode)Visit(expressionContext));
                    }

                    ConstArrayDefinitionNode constArrayDefinitionNode =
                        new ConstArrayDefinitionNode(GetLocation(nameNodeContext), typeNameNode, nameNode, arraySizeNode,
                                                     elementNodes);
                    _arrayDeclarationNodes.Add(constArrayDefinitionNode);
                    constDefinitionNodes.Add(constArrayDefinitionNode);
                }
            }
            return(new ConstDefinitionsTemporaryNode(GetLocation(constDefContext), constDefinitionNodes));
        }
コード例 #4
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DaedalusParser.nameNode"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitNameNode([NotNull] DaedalusParser.NameNodeContext context)
 {
     return(VisitChildren(context));
 }
コード例 #5
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="DaedalusParser.nameNode"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitNameNode([NotNull] DaedalusParser.NameNodeContext context)
 {
 }