Beispiel #1
0
        public void TestMultAltLoop() /*throws Exception*/
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "A : ('0'..'9'|'a'|'b')+ ;\n");
            int         Atype  = g.GetTokenType("A");
            Interpreter engine = new Interpreter(g, new ANTLRStringStream("a"));
            IToken      result = engine.Scan("A");

            engine = new Interpreter(g, new ANTLRStringStream("a"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
            engine = new Interpreter(g, new ANTLRStringStream("1234"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
            engine = new Interpreter(g, new ANTLRStringStream("aaa"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
            engine = new Interpreter(g, new ANTLRStringStream("aaaa9"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
            engine = new Interpreter(g, new ANTLRStringStream("b"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
            engine = new Interpreter(g, new ANTLRStringStream("baa"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
        }
Beispiel #2
0
        public void TestSimpleLoops() /*throws Exception*/
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "A : ('0'..'9')+ '.' ('0'..'9')* | ('0'..'9')+ ;\n");
            int         Atype  = g.GetTokenType("A");
            ICharStream input  = new ANTLRStringStream("1234.5");
            Interpreter engine = new Interpreter(g, input);
            IToken      result = engine.Scan("A");

            Assert.AreEqual(Atype, result.Type);
        }
Beispiel #3
0
        public void TestSingleRuleRef() /*throws Exception*/
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "A : 'a' B 'c' ;\n" +
                "B : 'b' ;\n");
            int         Atype  = g.GetTokenType("A");
            Interpreter engine = new Interpreter(g, new ANTLRStringStream("abc"));     // should ignore the x
            IToken      result = engine.Scan("A");

            Assert.AreEqual(result.Type, Atype);
        }
Beispiel #4
0
        public void TestSimpleLoop() /*throws Exception*/
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "INT : (DIGIT)+ ;\n" +
                "fragment DIGIT : '0'..'9';\n");
            int         INTtype = g.GetTokenType("INT");
            Interpreter engine  = new Interpreter(g, new ANTLRStringStream("12x"));    // should ignore the x
            IToken      result  = engine.Scan("INT");

            Assert.AreEqual(result.Type, INTtype);
            engine = new Interpreter(g, new ANTLRStringStream("1234"));
            result = engine.Scan("INT");
            Assert.AreEqual(result.Type, INTtype);
        }
Beispiel #5
0
        public void TestSimpleAltCharTest() /*throws Exception*/
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "A : 'a' | 'b' | 'c';");
            int         Atype  = g.GetTokenType("A");
            Interpreter engine = new Interpreter(g, new ANTLRStringStream("a"));

            engine = new Interpreter(g, new ANTLRStringStream("b"));
            IToken result = engine.Scan("A");

            Assert.AreEqual(result.Type, Atype);
            engine = new Interpreter(g, new ANTLRStringStream("c"));
            result = engine.Scan("A");
            Assert.AreEqual(result.Type, Atype);
        }
 public void TestMultAltLoop()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : ('0'..'9'|'a'|'b')+ ;\n" );
     int Atype = g.GetTokenType( "A" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "a" ) );
     IToken result = engine.Scan( "A" );
     engine = new Interpreter( g, new ANTLRStringStream( "a" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "1234" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "aaa" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "aaaa9" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "b" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "baa" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
 }
 public void TestSingleRuleRef()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : 'a' B 'c' ;\n" +
             "B : 'b' ;\n" );
     int Atype = g.GetTokenType( "A" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "abc" ) ); // should ignore the x
     IToken result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
 }
 public void TestSimpleLoops()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : ('0'..'9')+ '.' ('0'..'9')* | ('0'..'9')+ ;\n" );
     int Atype = g.GetTokenType( "A" );
     ICharStream input = new ANTLRStringStream( "1234.5" );
     Interpreter engine = new Interpreter( g, input );
     IToken result = engine.Scan( "A" );
     Assert.AreEqual( Atype, result.Type );
 }
 public void TestSimpleLoop()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "INT : (DIGIT)+ ;\n" +
             "fragment DIGIT : '0'..'9';\n" );
     int INTtype = g.GetTokenType( "INT" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "12x" ) ); // should ignore the x
     IToken result = engine.Scan( "INT" );
     Assert.AreEqual( result.Type, INTtype );
     engine = new Interpreter( g, new ANTLRStringStream( "1234" ) );
     result = engine.Scan( "INT" );
     Assert.AreEqual( result.Type, INTtype );
 }
 public void TestSimpleAltCharTest()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : 'a' | 'b' | 'c';" );
     int Atype = g.GetTokenType( "A" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "a" ) );
     engine = new Interpreter( g, new ANTLRStringStream( "b" ) );
     IToken result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "c" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
 }