Ejemplo n.º 1
0
        public override bool VisitIter_stmt([NotNull] GrammarParser.Iter_stmtContext context)
        {
            Console.WriteLine("Iterative statement");

            /*
             * realScopeCount = MainScopeClass.Scopes.Count + 1;
             * Dictionary<string, object> localScope = new Dictionary<string, object>();
             * Console.WriteLine("REAL scope count: " + realScopeCount);
             * MainScopeClass.Scopes.Add(realScopeCount, localScope);
             *
             * //Almost..IndexChecker needs a bit of work.
             *
             * if (scopeCount > 0)
             * {
             *  scopeCount--;
             * }
             * if (!GrammarParser.ruleNames[context.Parent.Parent.Parent.RuleIndex].Equals("program"))
             * {
             *  foreach (var child in MainScopeClass.Scopes[realScopeCount - IndexChecker])
             *  {
             *      MainScopeClass.Scopes[realScopeCount].Add(child.Key, child.Value);
             *  }
             *  IndexChecker++;
             *  //scopeCount += context.ChildCount;
             *
             * }
             */

            switch (context.GetChild(0).GetText())
            {
            case "for":
                scopeCount += context.GetChild(7).ChildCount;
                prefix     += "\t";
                Console.WriteLine("Scopecount = " + scopeCount);
                //Get the inital and end value of i
                int Start = Convert.ToInt32(context.GetChild(3).GetText());
                int End   = Convert.ToInt32(context.GetChild(5).GetText());
                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.Write($"for i in range({Start},{End}):");
                }
                break;

            case "while":
                //To do
                break;

            default:
                Console.WriteLine("Wrong!");
                break;
            }



            return(base.VisitIter_stmt(context));
        }
Ejemplo n.º 2
0
        public override void EnterIter_stmt([NotNull] GrammarParser.Iter_stmtContext context)
        {
            ScopeNode LocalScope = new ScopeNode();

            Scopes.Add(LocalScope);
            LocalScope.Parent = currentScope;
            currentScope      = LocalScope;

            base.EnterIter_stmt(context);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="GrammarParser.iter_stmt"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitIter_stmt([NotNull] GrammarParser.Iter_stmtContext context)
 {
 }
Ejemplo n.º 4
0
 public override void ExitIter_stmt([NotNull] GrammarParser.Iter_stmtContext context)
 {
     currentScope = currentScope.Parent;
     base.ExitIter_stmt(context);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="GrammarParser.iter_stmt"/>.
 /// <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 VisitIter_stmt([NotNull] GrammarParser.Iter_stmtContext context)
 {
     return(VisitChildren(context));
 }