package rebelsky.compiler.pascal; import rebelsky.compiler.lexer.Token; /** * Unsigned integers for a simple Pascal tokenizer. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002 */ public class PascalInteger extends Token { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The value of the integer. */ int value; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new integer token with specified value. */ public PascalInteger(int value) { super(PascalTokens.PINT); this.value = value; } // PascalInteger(int) /** * Create a new integer by parsing a string. * * @exception NumberFormatException * If the string cannot be parsed as an integer. */ public PascalInteger(String original) throws NumberFormatException { super(PascalTokens.PINT); this.value = Integer.parseInt(original); } // PascalInteger(String) // +-----------+--------------------------------------------------------- // | Observers | // +-----------+ /** * Get the value of this integer. */ public int getValue() { return this.value; } // getValue() /** * Convert to a string for printing. */ public String toString() { return "INT[" + this.value + "]"; } // toString() /** * Compare to another Pascal integer. */ public boolean equals(PascalInteger other) { return this.value == other.value; } // equals(PascalInteger) } // class PascalInteger