Package org.antlr.tool

Examples of org.antlr.tool.Interpreter


      "lexer grammar t;\n"+
      "A : 'a';\n" +
      "B : 'b';\n" +
      "C : 'c';\n");
    CharStream input = new ANTLRStringStream("abc");
    Interpreter lexEngine = new Interpreter(g, input);
    TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
    tokens.fill();
    tokens.insertBefore(2, "y");
    tokens.delete(2);
    String result = tokens.toString();
View Full Code Here


            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
        Interpreter lexEngine = new Interpreter(g, input);
        BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

        String result = tokens.LT(1).getText();
        String expecting = "x";
        assertEquals(expecting, result);
View Full Code Here

            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
        Interpreter lexEngine = new Interpreter(g, input);
        BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

        String result = tokens.LT(2).getText();
        String expecting = " ";
        assertEquals(expecting, result);
View Full Code Here

            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
        Interpreter lexEngine = new Interpreter(g, input);
        BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

        int i = 1;
        Token t = tokens.LT(i);
        while ( t.getType()!=Token.EOF ) {
View Full Code Here

            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
        Interpreter lexEngine = new Interpreter(g, input);
        BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

        Token t = tokens.LT(1);
        while ( t.getType()!=Token.EOF ) {
            tokens.consume();
View Full Code Here

            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
        Interpreter lexEngine = new Interpreter(g, input);
        BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

        tokens.consume(); // get x into buffer
        Token t = tokens.LT(-1);
        assertEquals("x", t.getText());
View Full Code Here

  @Test public void testSimpleAltCharTest() throws Exception {
        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : 'a' | 'b' | 'c';");
    final int Atype = g.getTokenType("A");
        Interpreter engine = new Interpreter(g, new ANTLRStringStream("a"));
        engine = new Interpreter(g, new ANTLRStringStream("b"));
    Token result = engine.scan("A");
    assertEquals(result.getType(), Atype);
        engine = new Interpreter(g, new ANTLRStringStream("c"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    }
View Full Code Here

        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : 'a' B 'c' ;\n" +
                "B : 'b' ;\n");
    final int Atype = g.getTokenType("A");
    Interpreter engine = new Interpreter(g, new ANTLRStringStream("abc")); // should ignore the x
    Token result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    }
View Full Code Here

        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "INT : (DIGIT)+ ;\n"+
        "fragment DIGIT : '0'..'9';\n");
    final int INTtype = g.getTokenType("INT");
    Interpreter engine = new Interpreter(g, new ANTLRStringStream("12x")); // should ignore the x
    Token result = engine.scan("INT");
    assertEquals(result.getType(), INTtype);
    engine = new Interpreter(g, new ANTLRStringStream("1234"));
    result = engine.scan("INT");
    assertEquals(result.getType(), INTtype);
    }
View Full Code Here

    @Test public void testMultAltLoop() throws Exception {
    Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : ('0'..'9'|'a'|'b')+ ;\n");
    final int Atype = g.getTokenType("A");
    Interpreter engine = new Interpreter(g, new ANTLRStringStream("a"));
    Token result = engine.scan("A");
        engine = new Interpreter(g, new ANTLRStringStream("a"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    engine = new Interpreter(g, new ANTLRStringStream("1234"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
        engine = new Interpreter(g, new ANTLRStringStream("aaa"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
        engine = new Interpreter(g, new ANTLRStringStream("aaaa9"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
        engine = new Interpreter(g, new ANTLRStringStream("b"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
        engine = new Interpreter(g, new ANTLRStringStream("baa"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    }
View Full Code Here

TOP

Related Classes of org.antlr.tool.Interpreter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.