Beispiel #1
0
        public override int VisitCondition([NotNull] CBluntParser.ConditionContext context)
        {
            // Specialized handling for ID hence it is here
            if (context.ID() != null)
            {
                var variableName = context.ID().GetText();

                var variableProperties = GetDeclaredVariable(variableName);

                if (variableProperties == null)
                {
                    SyntaxError(context, "Variable " + variableName + " does not exist");
                    return(1);
                }

                if (!variableProperties.Initialized)
                {
                    SyntaxError(context, "Variable " + variableName + " has not been initialized");
                    return(1);
                }

                if (variableProperties.Type != "bool")
                {
                    SyntaxError(context, "Variable " + variableName + " must be of a type bool");
                    return(1);
                }
            }

            return(base.VisitCondition(context));
        }
Beispiel #2
0
        public override int VisitCondition([NotNull] CBluntParser.ConditionContext context)
        {
#if DEBUG
            Console.WriteLine("VisitCondition");
#endif
            for (int counter = 0; counter < context.children.Count(); ++counter)
            {
                Visit(context.GetChild(counter));
                if (context.GetChild(counter) == context.ID())
                {
                    AddText(context.ID().GetText());
                }
                if (context.GetChild(counter).GetText() == "!")
                {
                    this.AddText("!");
                }
                if (context.GetChild(counter).GetText() == "(")
                {
                    this.AddText("(");
                }
                if (context.GetChild(counter).GetText() == ")")
                {
                    this.AddText(")");
                }
            }

            return(0);
        }
Beispiel #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CBluntParser.condition"/>.
 /// <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 VisitCondition([NotNull] CBluntParser.ConditionContext context)
 {
     return(VisitChildren(context));
 }