Example #1
0
        //Should it be Func_expr or Func_stmt?
        public override void EnterFunc_expr([NotNull] GrammarParser.Func_exprContext context)
        {
            ScopeNode LocalScope = new ScopeNode();

            Scopes.Add(LocalScope);
            LocalScope.Parent = currentScope;
            currentScope      = LocalScope;
            base.EnterFunc_expr(context);
        }
 /// <summary>
 /// Exit a parse tree produced by <see cref="GrammarParser.func_expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitFunc_expr([NotNull] GrammarParser.Func_exprContext context)
 {
 }
Example #3
0
 public override void ExitFunc_expr([NotNull] GrammarParser.Func_exprContext context)
 {
     currentScope = currentScope.Parent;
     base.ExitFunc_expr(context);
 }
Example #4
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="GrammarParser.func_expr"/>.
 /// <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 VisitFunc_expr([NotNull] GrammarParser.Func_exprContext context)
 {
     return(VisitChildren(context));
 }
Example #5
0
        public override bool VisitFunc_expr([NotNull] GrammarParser.Func_exprContext context)
        {
            Console.WriteLine("Function Expression");

            switch (context.GetChild(0).GetText())
            {
            case "Drive":

                int distance;
                if (Int32.TryParse((context.GetChild(2).GetText()), out distance))
                {
                    ;
                }
                else
                {
                    string variable = LookUp(context.GetChild(2).GetText());
                    Int32.TryParse(variable, out distance);
                }

                int speed;
                if (Int32.TryParse((context.GetChild(4).GetText()), out speed))
                {
                    ;
                }
                else
                {
                    string variable = LookUp(context.GetChild(4).GetText());
                    Int32.TryParse(variable, out speed);
                }
                speed *= 10;



                int pauseTime = Math.Abs(distance / (speed / 10));



                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.Write($"{prefix}self.create.drive_direct({speed}, {speed})" +
                             $"{prefix}self.time.sleep({pauseTime})" +
                             $"{prefix}self.create.drive_direct(0,0)");
                    scopeCount--;
                    if (scopeCount == 0)
                    {
                        prefix = removePrefix(prefix, "\t");
                    }
                    sw.Write($"{prefix}");
                }



                break;

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

            return(base.VisitFunc_expr(context));
        }