Esempio n. 1
0
        public void GetCarriageReturnNewLineAsEndOfLine()
        {
            Lexer lexer = new Lexer("\r\n");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(TokenType.EndOfLine, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Lexer lexer = new Lexer(System.Console.In);
            Context context = new Context();
            context.SetValue("puts", new Puts(System.Console.Out));
            Parser parser = new Parser(lexer);

            for (ICommand cmd = parser.ParseCommand(); cmd != null; cmd = parser.ParseCommand())
                cmd.Execute(context);
        }
Esempio n. 3
0
        public void GetInteger()
        {
            Lexer lexer = new Lexer("123");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("123", token.Value);
            Assert.AreEqual(TokenType.Integer, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 4
0
        public void GetEqualOperator()
        {
            Lexer lexer = new Lexer("==");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("==", token.Value);
            Assert.AreEqual(TokenType.Operator, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 5
0
        public void GetEndOfCommand()
        {
            Lexer lexer = new Lexer(";");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(";", token.Value);
            Assert.AreEqual(TokenType.Separator, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 6
0
        public void GetName()
        {
            Lexer lexer = new Lexer("foo");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("foo", token.Value);
            Assert.AreEqual(TokenType.Name, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 7
0
        public void GetSimpleString()
        {
            Lexer lexer = new Lexer("\"foo\"");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("foo", token.Value);
            Assert.AreEqual(TokenType.String, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 8
0
        public void GetSimpleAssignmentCommand()
        {
            Lexer lexer = new Lexer("a=123");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("a", token.Value);
            Assert.AreEqual(TokenType.Name, token.Type);

            token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("=", token.Value);
            Assert.AreEqual(TokenType.Operator, token.Type);

            token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("123", token.Value);
            Assert.AreEqual(TokenType.Integer, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 9
0
        public void GetParentheses()
        {
            Lexer lexer = new Lexer("()");
            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual("(", token.Value);
            Assert.AreEqual(TokenType.Separator, token.Type);

            token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(")", token.Value);
            Assert.AreEqual(TokenType.Separator, token.Type);

            Assert.IsNull(lexer.NextToken());
        }
Esempio n. 10
0
 public Parser(Lexer lexer)
 {
     this.lexer = lexer;
 }