Exemple #1
0
 public static Let Parse(Input input, TextWriter output)
 {
     return(input.RewindOnNull(() =>
     {
         if (input.Pop(Keyword) == null)
         {
             return null;
         }
         var var = Var.Parse(input, output);
         if (var == null)
         {
             output.WriteLine(MessageFormatter.Expected("var"));
             return null;
         }
         if (input.Pop("=") == null)
         {
             output.WriteLine(MessageFormatter.Expected("="));
             return null;
         }
         var expr = Expr.Parse(input, output);
         if (expr == null)
         {
             output.WriteLine(MessageFormatter.Expected("expression"));
             return null;
         }
         return new Let(var, expr);
     }));
 }
Exemple #2
0
        public static ExprListItem Parse(Input input, TextWriter output)
        {
            var str = Str.Parse(input);

            if (str != null)
            {
                return(new ExprListItem(str));
            }

            var expr = Expr.Parse(input, output);

            return(expr != null ? new ExprListItem(expr) : null);
        }
Exemple #3
0
 public static Goto Parse(Input input, TextWriter output)
 {
     return(input.RewindOnNull(() =>
     {
         var cmd = input.Pop(Keyword);
         if (cmd == null)
         {
             return null;
         }
         var expr = Expr.Parse(input, output);
         if (expr == null)
         {
             output.WriteLine(MessageFormatter.Expected("expression"));
             return null;
         }
         return new Goto(expr);
     }));
 }
Exemple #4
0
        public static Factor Parse(Input input, TextWriter output)
        {
            if (Dejavu(input.Index))
            {
                return(null);
            }

            indexOnPreviousVisit = input.Index;

            var var = Var.Parse(input, output);

            if (var != null)
            {
                indexOnPreviousVisit = null;
                return(new Factor(var));
            }

            var number = Number.Parse(input);

            if (number != null)
            {
                indexOnPreviousVisit = null;
                return(new Factor(number));
            }

            var expr = Expr.Parse(input, output);

            if (expr != null)
            {
                indexOnPreviousVisit = null;
                return(new Factor(expr));
            }

            var rnd = Rnd.Parse(input, output);

            if (rnd != null)
            {
                indexOnPreviousVisit = null;
                return(new Factor(rnd));
            }

            return(null);
        }
Exemple #5
0
 public static If Parse(Input input, TextWriter output)
 {
     return(input.RewindOnNull(() =>
     {
         var cmd = input.Pop(KeywordIf);
         if (cmd == null)
         {
             return null;
         }
         var lhExpr = Expr.Parse(input, output);
         if (lhExpr == null)
         {
             output.WriteLine(MessageFormatter.Expected("expression"));
             return null;
         }
         var relop = Relop.Parse(input);
         if (relop == null)
         {
             output.WriteLine(MessageFormatter.Expected(Relop.Strings));
             return null;
         }
         var rhExpr = Expr.Parse(input, output);
         if (rhExpr == null)
         {
             output.WriteLine(MessageFormatter.Expected("expression"));
             return null;
         }
         var then = input.Pop(KeywordThen);
         if (then == null)
         {
             output.WriteLine(MessageFormatter.Expected(KeywordThen));
             return null;
         }
         var statement = Statement.Parse(input, output);
         if (statement == null)
         {
             output.WriteLine(MessageFormatter.Expected("statement"));
             return null;
         }
         return new If(lhExpr, relop, rhExpr, statement);
     }));
 }