Ejemplo n.º 1
0
 @Override
 public boolean applyRules(int[] a) {
   if (a == null || a.length > GRID_SIZE) {
     throw new IllegalArgumentException();
   }
   boolean result = true;
   result &= EQ.apply(PLUS.apply(a[1], a[0]), 6);
   result &= EQ.apply(PLUS.apply(a[4], a[1]), a[2]);
   result &= EQ.apply(PLUS.apply(a[4], PLUS.apply(a[2], a[1])), 8);
   return result;
 }
Ejemplo n.º 2
0
public enum PascalTokenType implements TokenType {
  // Palavras reservadas
  AND,
  ARRAY,
  BEGIN,
  CASE,
  CONST,
  DIV,
  DO,
  DOWNTO,
  ELSE,
  END,
  FILE,
  FOR,
  FUNCTION,
  GOTO,
  IF,
  IN,
  LABEL,
  MOD,
  NIL,
  NOT,
  OF,
  OR,
  PACKED,
  PROCEDURE,
  PROGRAM,
  RECORD,
  REPEAT,
  SET,
  THEN,
  TO,
  TYPE,
  UNTIL,
  VAR,
  WHILE,
  WITH,

  // Símbolos especiais.
  PLUS("+"),
  MINUS("-"),
  STAR("*"),
  SLASH("/"),
  COLON_EQUALS(":="),
  DOT("."),
  COMMA(","),
  SEMICOLON(";"),
  COLON(":"),
  QUOTE("'"),
  EQUALS("="),
  NOT_EQUALS("<>"),
  LESS_THAN("<"),
  LESS_EQUALS("<="),
  GREATER_EQUALS(">="),
  GREATER_THAN(">"),
  LEFT_PAREN("("),
  RIGHT_PAREN(")"),
  LEFT_BRACKET("["),
  RIGHT_BRACKET("]"),
  LEFT_BRACE("{"),
  RIGHT_BRACE("}"),
  UP_ARROW("^"),
  DOT_DOT(".."),

  IDENTIFIER,
  INTEGER,
  REAL,
  STRING,
  ERROR,
  END_OF_FILE;

  private static final int FIRST_RESERVED_INDEX = AND.ordinal();
  private static final int LAST_RESERVED_INDEX = WITH.ordinal();

  private static final int FIRST_SPECIAL_INDEX = PLUS.ordinal();
  private static final int LAST_SPECIAL_INDEX = DOT_DOT.ordinal();

  // Set of lower-cased Pascal reserved word text strings.
  public static Set<String> RESERVED_WORDS = new HashSet<String>();

  static {
    final PascalTokenType values[] = PascalTokenType.values();
    for (int i = FIRST_RESERVED_INDEX; i <= LAST_RESERVED_INDEX; ++i) {
      RESERVED_WORDS.add(values[i].getText().toLowerCase());
    }
  }

  // Hash table of Pascal special symbols.  Each special symbol's text
  // is the key to its Pascal token type.
  public static Map<String, PascalTokenType> SPECIAL_SYMBOLS =
      new HashMap<String, PascalTokenType>();

  static {
    final PascalTokenType values[] = PascalTokenType.values();
    for (int i = FIRST_SPECIAL_INDEX; i <= LAST_SPECIAL_INDEX; ++i) {
      SPECIAL_SYMBOLS.put(values[i].getText(), values[i]);
    }
  }

  private String text; // token text

  /** Constructor. */
  PascalTokenType() {
    this.text = this.toString().toLowerCase();
  }

  PascalTokenType(final String text) {
    this.text = text;
  }

  public String getText() {
    return text;
  }
}
Ejemplo n.º 3
0
 public boolean check() {
   return PLUS.equals(value);
 }