/// <summary>
 /// Exit a parse tree produced by <see cref="DDD_layout_scriptParser.variable_decl"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitVariable_decl([NotNull] DDD_layout_scriptParser.Variable_declContext context)
 {
 }
コード例 #2
0
        /* Váltózó inicializálását nézi meg.
         * TODO: nameshadowing warningok
         */
        public override object VisitVariable_decl([NotNull] DDD_layout_scriptParser.Variable_declContext context)
        {
            var    op    = context.operation();
            string idStr = context.ID().GetText();

            // nincsen kiírva explicit a típus
            // type inference
            if (context.TYPE() == null)
            {
                // nincsen jobb oldal sem
                if (op == null)
                {
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Unknown", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                }
                // jobb oldalon egy float van
                else if (Regex.IsMatch(op.GetText(), @"^([0-9]*)?\.[0-9]+f?$"))
                {
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Float", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                }
                // jobb oldalon egy int van
                else if (Regex.IsMatch(op.GetText(), @"^[0-9]+$"))
                {
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Int", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                }
                // jobb oldalon egy vec3 van
                else if (Regex.IsMatch(op.GetText(), @"^\[[^,]+,[^,]+,[^,]+\]$"))
                {
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Vec3", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                }
                // jobb oldalon valami kifejezés van
                else
                {
                    // vektor jöhet ki végeredményül, int, float már tuti nem
                    if (op.GetText().Contains("["))
                    {
                        ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Vec3", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                    }
                    // bármi kijöhet
                    else
                    {
                        dynamic result = VisitOperation(op);
                        ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, Extensions.Extensions.ToString(result), idStr), result, new Stack <Scope>(new Stack <Scope>(symbolTable))));
                    }
                }
            }
            else
            {
                switch (context.TYPE().GetText())
                {
                case "Float":
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Float", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                    break;

                case "Int":
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Int", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                    break;

                case "Vec3":
                    ErrorHandlingOrCommit(context, currentScope.Add(new Symbol(context.CONST() != null, "Vec3", idStr), VisitOperation(op), new Stack <Scope>(new Stack <Scope>(symbolTable))));
                    break;
                }
            }

            return(null);
        }
コード例 #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DDD_layout_scriptParser.variable_decl"/>.
 /// <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 VisitVariable_decl([NotNull] DDD_layout_scriptParser.Variable_declContext context)
 {
     return(VisitChildren(context));
 }