Ejemplo n.º 1
0
        public void NonDelimitedStringThrowsException()
        {
            var str = "{'no ending quote}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.Throws <Exception>(() => lexer.GetNextToken());
        }
Ejemplo n.º 2
0
        public void TestStringLiteral()
        {
            var str = "stringw1thnumb3rs and no digits";

            var lexer = new StandardLexer(str);

            Assert.True(lexer.GetNextToken() == new Token("stringw1thnumb3rs and no digits", TokenType.TEXT_LITERAL));
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 3
0
        public void TestStringEscaping()
        {
            var str = "\\{";

            var lexer = new StandardLexer(str);

            Assert.True(lexer.GetNextToken() == new Token("{", TokenType.TEXT_LITERAL));
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 4
0
        public void TestBraces()
        {
            var str = "{}";

            var lexer = new StandardLexer(str);

            Assert.True(lexer.GetNextToken() == new Token("{", TokenType.LBRACE));
            Assert.True(lexer.GetNextToken() == new Token("}", TokenType.RBRACE));
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 5
0
        public void TestQuotedString()
        {
            var str = "{'testing <= {} () 1 > 2 and 2 != 1'}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("testing <= {} () 1 > 2 and 2 != 1", TokenType.TEXT_LITERAL));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 6
0
        public void TestSquareBrackets()
        {
            var str = "{[]}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("[", TokenType.LSQUARE));
            Assert.True(lexer.GetNextToken() == new Token("]", TokenType.RSQUARE));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 7
0
        public void TestParentheses()
        {
            var str = "{()}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("(", TokenType.LPAREN));
            Assert.True(lexer.GetNextToken() == new Token(")", TokenType.RPAREN));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 8
0
        public void TestBranchOperators()
        {
            var str = "{?:}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("?", TokenType.QM));
            Assert.True(lexer.GetNextToken() == new Token(":", TokenType.COLON));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 9
0
        public void TestMathOperators()
        {
            var str = "{+-*/}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("+", TokenType.PLUS));
            Assert.True(lexer.GetNextToken() == new Token("-", TokenType.MINUS));
            Assert.True(lexer.GetNextToken() == new Token("*", TokenType.MUL));
            Assert.True(lexer.GetNextToken() == new Token("/", TokenType.DIV));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 10
0
        public void TestMathExpression()
        {
            var str = "{(23+40.503)}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("(", TokenType.LPAREN));
            Assert.True(lexer.GetNextToken() == new Token("23", TokenType.INTEGER_CONST));
            Assert.True(lexer.GetNextToken() == new Token("+", TokenType.PLUS));
            Assert.True(lexer.GetNextToken() == new Token("40.503", TokenType.REAL_CONST));
            Assert.True(lexer.GetNextToken() == new Token(")", TokenType.RPAREN));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 11
0
        public void TestNullIdentifier()
        {
            var str = "{identifier1 + null}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("identifier1", TokenType.IDENTIFIER));
            lexer.GetNextToken();             // whitespace
            Assert.True(lexer.GetNextToken() == new Token("+", TokenType.PLUS));
            lexer.GetNextToken();             // whitespace
            Assert.True(lexer.GetNextToken() == new Token("null", TokenType.NULL));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 12
0
        public void TestComparisonOperators()
        {
            var str = "{= != < > <= >=}";

            var lexer = new StandardLexer(str);

            lexer.GetNextToken();             // {
            Assert.True(lexer.GetNextToken() == new Token("=", TokenType.EQ));
            lexer.GetNextToken();             // Whitespace
            Assert.True(lexer.GetNextToken() == new Token("!=", TokenType.NEQ));
            lexer.GetNextToken();             // Whitespace
            Assert.True(lexer.GetNextToken() == new Token("<", TokenType.LT));
            lexer.GetNextToken();             // Whitespace
            Assert.True(lexer.GetNextToken() == new Token(">", TokenType.GT));
            lexer.GetNextToken();             // Whitespace
            Assert.True(lexer.GetNextToken() == new Token("<=", TokenType.LTE));
            lexer.GetNextToken();             // Whitespace
            Assert.True(lexer.GetNextToken() == new Token(">=", TokenType.GTE));
            lexer.GetNextToken();             // }
            Assert.True(lexer.GetNextToken().Type == TokenType.EOF);
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var lexer     = StandardLexer.Build();
            var astParser = ASTParserBuilder.Build(lexer);

            while (true)
            {
                Console.Write("SnesC> ");
                string line = Console.ReadLine();

                if (line == "exit")
                {
                    break;
                }
                else if (line == "switch token")
                {
                    DoDisplayToken = !DoDisplayToken;
                    continue;
                }
                else if (line == "switch ast")
                {
                    DoDisplayAST = !DoDisplayAST;
                    continue;
                }

                if (DoDisplayToken)
                {
                    DisplayToken(lexer, line);
                }
                if (DoDisplayAST)
                {
                    DisplayAST(astParser, line);
                }


                Console.WriteLine();
            }
        }