Package org.antlr.tool

Examples of org.antlr.tool.Interpreter$LexerActionGetTokenType


    Grammar g = new Grammar(
        "lexer grammar t;\n"+
        "A : ('0'..'9')+ '.' ('0'..'9')* | ('0'..'9')+ ;\n");
    final int Atype = g.getTokenType("A");
    CharStream input = new ANTLRStringStream("1234.5");
    Interpreter engine = new Interpreter(g, input);
    Token result = engine.scan("A");
    assertEquals(Atype, result.getType());
  }
View Full Code Here


      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ {channel=99;};\n");
    CharStream input = new ANTLRStringStream("123 139.52");
    Interpreter lexEngine = new Interpreter(g, input);

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
        tokens.LT(5); // make sure it grabs all tokens
    String result = tokens.toString();
    //System.out.println(result);
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=1; y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    FilteringTokenStream tokens = new FilteringTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr 1) ;) (assign y = (expr 3.42) ;) (assign z = (expr y) ;) } <EOF>))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=1 y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    FilteringTokenStream tokens = new FilteringTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr 1) MismatchedTokenException(6!=10))))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=; y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    FilteringTokenStream tokens = new FilteringTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr MismatchedSetException(10!={5,6,7})))))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=; y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    FilteringTokenStream tokens = new FilteringTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr NoViableAltException(10@[4:1: expr : ( INT | FLOAT | ID );])))))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=1; y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr 1) ;) (assign y = (expr 3.42) ;) (assign z = (expr y) ;) } <EOF>))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=1 y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr 1) MismatchedTokenException(5!=9))))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=; y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr MismatchedSetException(9!={5,10,11})))))";
    assertEquals(expecting, result);
  }
View Full Code Here

      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ ;\n");
    CharStream input = new ANTLRStringStream("while x { i=; y=3.42; z=y; }");
    Interpreter lexEngine = new Interpreter(g, input);

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    tokens.setTokenTypeChannel(g.getTokenType("WS"), 99);
    //System.out.println("tokens="+tokens.toString());
    Interpreter parseEngine = new Interpreter(pg, tokens);
    ParseTree t = parseEngine.parse("prog");
    String result = t.toStringTree();
    String expecting =
      "(<grammar p> (prog while x { (assign i = (expr NoViableAltException(9@[4:1: expr : ( INT | FLOAT | ID );])))))";
    assertEquals(expecting, result);
  }
View Full Code Here

TOP

Related Classes of org.antlr.tool.Interpreter$LexerActionGetTokenType

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.