コード例 #1
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetArithmeticOperators()
        {
            Lexer lexer = new Lexer("+-*/");

            Token token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #2
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetAtom()
        {
            Lexer lexer = new Lexer("ok");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #3
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetAtomAndSkipComment()
        {
            Lexer lexer = new Lexer("ok % this is a comment");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #4
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetAtomWithAt()
        {
            Lexer lexer = new Lexer("joe@somehost");

            Token token = lexer.NextToken();

            Assert.IsNotNull(token);
            Assert.AreEqual(TokenType.Atom, token.Type);
            Assert.AreEqual("joe@somehost", token.Value);

            Assert.IsNull(lexer.NextToken());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ajlopez/AjErl
        public static void Main(string[] args)
        {
            Console.WriteLine("AjErl alfa 0.0.1");

            Lexer lexer = new Lexer(Console.In);
            Parser parser = new Parser(lexer);
            Machine machine = new Machine();

            while (true)
                try
                {
                    ProcessExpression(parser, machine.RootContext);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.Message);
                    Console.Error.WriteLine(ex.StackTrace);
                }
        }
コード例 #6
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetIntegerWithSpaces()
        {
            Lexer lexer = new Lexer("  123   ");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #7
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetStrictEqualAsOperator()
        {
            Lexer lexer = new Lexer("=:=");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #8
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetNumeralBracketAsSeparator()
        {
            Lexer lexer = new Lexer("#{");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #9
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void UnexpectedSign()
        {
            Lexer lexer = new Lexer("?");

            try
            {
                lexer.NextToken();
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ParserException));
                Assert.AreEqual("Unexpected '?'", ex.Message);
            }
        }
コード例 #10
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetVerticalBarAsSeparator()
        {
            Lexer lexer = new Lexer("|");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #11
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void UnclosedString()
        {
            Lexer lexer = new Lexer("\"foo");

            try
            {
                lexer.NextToken();
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ParserException));
                Assert.AreEqual("unclosed string", ex.Message);
            }
        }
コード例 #12
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetUnderscoreNameAsVariable()
        {
            Lexer lexer = new Lexer("_ok");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #13
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetVariable()
        {
            Lexer lexer = new Lexer("X");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #14
0
ファイル: Parser.cs プロジェクト: ajlopez/AjErl
 public Parser(Lexer lexer)
 {
     this.lexer = lexer;
 }
コード例 #15
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetParenthesisAsSeparators()
        {
            Lexer lexer = new Lexer("()");

            Token token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #16
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetSimpleMatch()
        {
            Lexer lexer = new Lexer("X=ok.");

            Token token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #17
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetSemiColonAsSeparator()
        {
            Lexer lexer = new Lexer(";");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #18
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetRightArrowAsOperator()
        {
            Lexer lexer = new Lexer("->");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #19
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetReal()
        {
            Lexer lexer = new Lexer("123.45");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #20
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetPointAsOperator()
        {
            Lexer lexer = new Lexer(".");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #21
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetString()
        {
            Lexer lexer = new Lexer("\"foo\"");

            Token token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }
コード例 #22
0
ファイル: LexerTests.cs プロジェクト: ajlopez/AjErl
        public void GetBracketsAsSeparators()
        {
            Lexer lexer = new Lexer("[]");

            Token token = lexer.NextToken();

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

            token = lexer.NextToken();

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

            Assert.IsNull(lexer.NextToken());
        }