Example #1
0
  public static void main(String args[]) {
    Token tok;
    try {

      // Read from the command line for the filename
      Lexer lex = new Lexer(args[0]);

      while (true) {
        tok = lex.nextToken();

        // if token returns error token we print the line for error and exit
        if (tok.getKind() == Tokens.Error) {
          System.out.println(
              "Error in Line " + lex.source.getLineno() + " ErrorValue: " + tok.toString());
          System.exit(0);
        }
        // Printing the information about the line and the token
        String p =
            "Left: "
                + tok.getLeftPosition()
                + "| Right: "
                + tok.getRightPosition()
                + "| Type: "
                + TokenType.tokens.get(tok.getKind())
                + "| Value: ";
        // if ((tok.getKind() == Tokens.Identifier) || (tok.getKind() == Tokens.INTeger))
        p += tok.toString();
        System.out.println(p + "| Line: " + lex.source.getLineno());
      }
    } catch (Exception e) {
    }
  }
Example #2
0
 public void D() throws IOException {
   Type b = B();
   N(b);
   lexer.setCurrentType(null);
   match(';');
   D1();
 }
Example #3
0
 public static void main(String args[]) {
   System.out.println("start.");
   Lexer l = new Lexer();
   while (true) {
     try {
       Token t = l.scan();
       if (t.tag == Tag.NUM) {
         System.out.println(
             "Token : " + t.toString() + " , Tag:" + t.tag + " , value:" + ((Num) t).value);
       } else if (t.tag == Tag.ID) {
         System.out.println(
             "Token : " + t.toString() + " , Tag:" + t.tag + " , lexeme:" + ((Word) t).lexeme);
       } else {
         System.out.println("Token : " + t.toString() + " , Tag:" + t.tag);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Example #4
0
 void move() throws IOException {
   look = lexer.scan();
 }