コード例 #1
0
ファイル: ASTBuilder.cs プロジェクト: Deaxz/ML4D
        public override Node VisitFuncDecl(ML4DParser.FuncDeclContext context)
        {
            FunctionDCLNode functionDclNode;

            switch (context.type.type.Type)
            {
            case ML4DLexer.INT:
                functionDclNode = new FunctionDCLNode("int", context.id.Text);
                break;

            case ML4DLexer.DOUBLE:
                functionDclNode = new FunctionDCLNode("double", context.id.Text);
                break;

            case ML4DLexer.BOOL:
                functionDclNode = new FunctionDCLNode("bool", context.id.Text);
                break;

            case ML4DLexer.VOID:
                functionDclNode = new FunctionDCLNode("void", context.id.Text);
                break;

            default:
                throw new NotSupportedException(
                          $"The function {context.id.Text}, was declared with an illegal type.");
            }

            for (int i = 0; i < context._argid.Count; i++)
            {
                functionDclNode.Arguments.Add(new FunctionArgumentNode(
                                                  context._argtype[i].type.Text, context._argid[i].Text));
            }

            functionDclNode.Body = VisitLines(context.body);
            return(functionDclNode);
        }
コード例 #2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>funcDecl</c>
 /// labeled alternative in <see cref="ML4DParser.dcl"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitFuncDecl([NotNull] ML4DParser.FuncDeclContext context)
 {
 }
コード例 #3
0
ファイル: ML4DBaseVisitor.cs プロジェクト: Deaxz/ML4D
 /// <summary>
 /// Visit a parse tree produced by the <c>funcDecl</c>
 /// labeled alternative in <see cref="ML4DParser.dcl"/>.
 /// <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 VisitFuncDecl([NotNull] ML4DParser.FuncDeclContext context)
 {
     return(VisitChildren(context));
 }