Example #1
0
 /**
  * Get all tokes in the give category.
  *
  * @param category The category to get.
  * @return A collection of kinds in this category.
  */
 public static Collection<Token.Kind> getCategory(Token.Category category) {
   LinkedList<Token.Kind> kinds = new LinkedList<Token.Kind>();
   for (Token.Kind kind : Token.Kind.values()) {
     if (kind.category == null) {
       System.out.println(kind.name());
     }
     if (kind.category.equals(category)) {
       kinds.add(kind);
     }
   }
   return kinds;
 }
Example #2
0
 /**
  * Try to find a token that matches the lexeme in a give category.
  *
  * @param category The category of tokens to consider.
  * @param lexeme The lexeme to look for for.
  * @return A matching Kind or null.
  */
 public static Token.Kind matchingKind(Token.Category category, String lexeme) {
   boolean found = false;
   Collection<Token.Kind> catKinds = Token.Kind.getCategory(category);
   Iterator<Token.Kind> iterator = catKinds.iterator();
   Token.Kind curKind = null;
   while (!found && iterator.hasNext()) {
     curKind = iterator.next();
     if (curKind.matches(lexeme)) {
       found = true;
     }
   }
   return found ? curKind : null;
 }
Example #3
0
 private String reportSyntaxError(Token.Kind kind) {
   String message =
       "SyntaxError("
           + lineNumber()
           + ","
           + charPosition()
           + ")[Expected "
           + kind.name()
           + " but got "
           + currentToken.getKind().name()
           + ".]";
   errorBuffer.append(message + "\n");
   return message;
 }