Пример #1
0
Файл: Let.cs Проект: jmcd/WeeBas
 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);
     }));
 }
Пример #2
0
        private static Let NewMethod(Input input)
        {
            if (input.Pop(new List <string> {
                Keyword
            }) == null)
            {
                return(null);
            }
            var var = Var.Parse(input);

            if (var == null)
            {
                Console.WriteLine(MessageFormatter.Expected("var"));
                return(null);
            }
            if (input.Pop(new List <string> {
                "="
            }) == null)
            {
                Console.WriteLine(MessageFormatter.Expected("="));
                return(null);
            }
            var expr = Expr.Parse(input);

            if (expr == null)
            {
                Console.WriteLine(MessageFormatter.Expected("expression"));
                return(null);
            }
            return(new Let(var, expr));
        }
Пример #3
0
 public static Statement Parse(Input input, TextWriter output)
 {
     foreach (var commandParser in Parsers)
     {
         var command = commandParser(input, output);
         if (command != null)
         {
             return(new Statement(command));
         }
     }
     output.WriteLine(MessageFormatter.Expected(Print.Keyword, If.KeywordIf, Goto.Keyword, InputCmd.Keyword, Let.Keyword, Gosub.Keyword,
                                                Return.Keyword, Clear.Keyword, ListCmd.Keyword, Run.Keyword, End.Keyword, Save.Keyword, Load.Keyword, Rem.Keyword));
     return(null);
 }
Пример #4
0
        private static If NewMethod(Input input)
        {
            var cmd = input.Pop(new List <string> {
                KeywordIf
            });

            if (cmd == null)
            {
                return(null);
            }
            var lhExpr = Expr.Parse(input);

            if (lhExpr == null)
            {
                Console.WriteLine(MessageFormatter.Expected("expression"));
                return(null);
            }
            var relop = Relop.Parse(input);

            if (relop == null)
            {
                Console.WriteLine(string.Join("", MessageFormatter.Expected(Relop.Strings)));
                return(null);
            }
            var rhExpr = Expr.Parse(input);

            if (rhExpr == null)
            {
                Console.WriteLine(MessageFormatter.Expected("expression"));
                return(null);
            }
            var then = input.Pop(new List <string> {
                KeywordThen
            });

            if (then == null)
            {
                Console.WriteLine(MessageFormatter.Expected(KeywordThen));
                return(null);
            }
            var statement = Statement.Parse(input);

            if (statement == null)
            {
                Console.WriteLine(MessageFormatter.Expected("statement"));
                return(null);
            }
            return(new If(lhExpr, relop, rhExpr, statement));
        }
Пример #5
0
        private static Gosub NewMethod(Input input)
        {
            if (input.Pop(new List <string> {
                Keyword
            }) == null)
            {
                return(null);
            }
            var expr = Expr.Parse(input);

            if (expr == null)
            {
                Console.WriteLine(MessageFormatter.Expected("expression"));
                return(null);
            }
            return(new Gosub(expr));
        }
Пример #6
0
 public static Statement Parse(Input input)
 {
     foreach (var commandParser in Parsers)
     {
         var command = commandParser.Parse(input);
         if (command != null)
         {
             return(new Statement(command));
         }
     }
     Console.WriteLine("Input: " + input.Body + " " + input.Index);
     Console.WriteLine(MessageFormatter.Expected(new List <string> {
         Print.Keyword, If.KeywordIf, Goto.Keyword, InputCmd.Keyword, Let.Keyword, Gosub.Keyword,
         Return.Keyword, Clear.Keyword, ListCmd.Keyword, Run.Keyword, End.Keyword, Save.Keyword, Load.Keyword, Rem.Keyword
     }));
     return(null);
 }
Пример #7
0
 public static InputCmd Parse(Input input, TextWriter output)
 {
     return(input.RewindOnNull(() =>
     {
         var cmd = input.Pop(Keyword);
         if (cmd == null)
         {
             return null;
         }
         var varList = VarList.Parse(input, output);
         if (varList == null)
         {
             output.WriteLine(MessageFormatter.Expected("var-list"));
             return null;
         }
         return new InputCmd(varList);
     }));
 }
Пример #8
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);
     }));
 }
Пример #9
0
        private static InputCmd NewMethod(Input input)
        {
            var cmd = input.Pop(new List <string> {
                Keyword
            });

            if (cmd == null)
            {
                return(null);
            }
            var varList = VarList.Parse(input);

            if (varList == null)
            {
                Console.WriteLine(MessageFormatter.Expected("var-list"));
                return(null);
            }
            return(new InputCmd(varList));
        }
Пример #10
0
        private static Line NewMethod(Input input)
        {
            var number    = Number.Parse(input);
            var statement = Statement.Parse(input);

            if (statement == null)
            {
                Console.WriteLine(MessageFormatter.Expected("statement"));
                return(null);
            }
            var remainder = input.Pop(length: Int32.MaxValue).Trim();

            if (remainder.Length != 0)
            {
                Console.WriteLine(MessageFormatter.Expected($"eol (line was \"{input.Body}\")"));
                return(null);
            }
            return(new Line(number, statement, input.Body));
        }
Пример #11
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);
     }));
 }
Пример #12
0
        public static Line Parse(Input input, TextWriter output)
        {
            return(input.RewindOnNull(() =>
            {
                var number = Number.Parse(input);
                var statement = Statement.Parse(input, output);
                if (statement == null)
                {
                    output.WriteLine(MessageFormatter.Expected("statement"));
                    return null;
                }
                var remainder = input.Pop(length: Int32.MaxValue).Trim();

                if (remainder.Length != 0)
                {
                    output.WriteLine(MessageFormatter.Expected($"eol (line was \"{input.Body}\")"));
                    return null;
                }
                return new Line(number, statement, input.Body);
            }));
        }