예제 #1
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="OALParser.ifCommnad"/>.
 /// <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 VisitIfCommnad([NotNull] OALParser.IfCommnadContext context)
 {
     return(VisitChildren(context));
 }
예제 #2
0
        public override object VisitIfCommnad([NotNull] OALParser.IfCommnadContext context)
        {
            Visit(context.GetChild(2));

            EXEScopeCondition EXEScopeCondition = new EXEScopeCondition(stackEXEASTNode.Peek());

            stackEXEASTNode.Clear();
            stackEXEScope.Push(EXEScopeCondition);

            Boolean els  = false;
            Boolean elif = false;

            for (int i = 4; i < context.ChildCount; i++)
            {
                if (context.GetChild(i).GetType().Name.Contains("LineContext"))
                {
                    Console.WriteLine(i + " -> " + context.GetChild(i).GetText());
                    Visit(context.GetChild(i));
                }
                else if (context.GetChild(i).GetText().Equals("else"))
                {
                    if (elif)
                    {
                        EXEScopeCondition temp3 = ((EXEScopeCondition)stackEXEScope.Pop());
                        ((EXEScopeCondition)stackEXEScope.Peek()).AddElifScope(temp3);
                    }

                    els = true;
                    EXEScope temp2 = new EXEScope();
                    ((EXEScopeCondition)stackEXEScope.Peek()).ElseScope = temp2;

                    EXEScope temp = stackEXEScope.Pop();
                    stackEXEScope.Peek().AddCommand(temp);
                    stackEXEScope.Push(temp2);
                }
                else if (context.GetChild(i).GetText().Contains("elif"))
                {
                    if (elif)
                    {
                        EXEScopeCondition temp = ((EXEScopeCondition)stackEXEScope.Pop());
                        ((EXEScopeCondition)stackEXEScope.Peek()).AddElifScope(temp);
                    }

                    elif = true;
                    Console.WriteLine(i + " -> " + context.GetChild(i).GetText());
                    Console.WriteLine(i + "+ 2 -> " + context.GetChild(i + 2).GetText());
                    Visit(context.GetChild(i + 2));

                    EXEScopeCondition EXEScopeConditionELIF = new EXEScopeCondition(stackEXEASTNode.Peek());
                    stackEXEASTNode.Clear();
                    stackEXEScope.Push(EXEScopeConditionELIF);
                }
                else if (context.GetChild(i).GetText().Contains("end if;"))
                {
                    Console.WriteLine(i + "-> " + context.GetChild(i).GetText());
                    EXEScope temp = stackEXEScope.Pop();

                    if (!els && !elif)//TODO ako toto funguje? - napisal tvorca
                    {
                        stackEXEScope.Peek().AddCommand(temp);
                    }

                    if (elif && !els)
                    {
                        ((EXEScopeCondition)stackEXEScope.Peek()).AddElifScope((EXEScopeCondition)temp);
                        EXEScopeCondition temp2 = ((EXEScopeCondition)stackEXEScope.Pop());
                        stackEXEScope.Peek().AddCommand(temp2);
                    }
                }
            }
            return(null);
            //return base.VisitIfCommnad(context);
        }
예제 #3
0
 /// <summary>
 /// Enter a parse tree produced by <see cref="OALParser.ifCommnad"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void EnterIfCommnad([NotNull] OALParser.IfCommnadContext context)
 {
 }