Class Symbol
java.lang.Object
Symbol
Symbol objects represent a terminal or non-terminal symbol in the grammar.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe position of the symbol in the parsed file.private final intThe position of the symbol in the parsed file.private static final ObjectNo value attached to symbol, for terminals without value.private final LexicalUnitThe LexicalUnit (terminal) attached to this token.private static final intUndefined line/column position of symbol.private final ObjectThe value attached to the token. -
Constructor Summary
ConstructorsConstructorDescriptionSymbol(LexicalUnit unit) Creates a Symbol using the provided attributes, without position or value.Symbol(LexicalUnit unit, int line) Creates a Symbol using the provided attributes, without column nor value.Symbol(LexicalUnit unit, int line, int column) Creates a Symbol using the provided attributes and no value.Symbol(LexicalUnit unit, int line, int column, Object value) Creates a Symbol using the provided attributes.Symbol(LexicalUnit unit, Object value) Creates a Symbol using the provided attributes, without position. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this symbol to another object for equality.private static StringEscape LaTeX special characters in a string.intReturns the column where the symbol appeared.intgetLine()Returns the line where the symbol appeared.getType()Returns the type of the symbol.getValue()Returns the value of the symbol.inthashCode()Returns a hash code value for the object.booleanReturns whether the symbol represents a non-terminal.booleanReturns whether the symbol represents a terminal.toString()Returns a string representation of the symbol.Returns a LaTeX-formatted string representation of the symbol.
-
Field Details
-
UNDEFINED_POSITION
private static final int UNDEFINED_POSITIONUndefined line/column position of symbol.- See Also:
-
NO_VALUE
No value attached to symbol, for terminals without value. -
type
The LexicalUnit (terminal) attached to this token. -
value
The value attached to the token. May be any Object. In fact, for terminals with value it is indeed the value attached to the terminal. -
line
private final int lineThe position of the symbol in the parsed file. -
column
private final int columnThe position of the symbol in the parsed file.
-
-
Constructor Details
-
Symbol
Creates a Symbol using the provided attributes.- Parameters:
unit- the LexicalUnit (terminal) associated with the symbol.line- the line where the symbol appears in the file.column- the column where the symbol appears in the file.value- the value of the symbol.
-
Symbol
Creates a Symbol using the provided attributes and no value.- Parameters:
unit- the LexicalUnit (terminal) associated with the symbol.line- the line where the symbol appears in the file.column- the column where the symbol appears in the file.
-
Symbol
Creates a Symbol using the provided attributes, without column nor value.- Parameters:
unit- the LexicalUnit (terminal) associated with the symbol.line- the line where the symbol appears in the file.
-
Symbol
Creates a Symbol using the provided attributes, without position or value.- Parameters:
unit- the LexicalUnit (terminal) associated with the symbol.
-
Symbol
Creates a Symbol using the provided attributes, without position.- Parameters:
unit- the LexicalUnit (terminal) associated with the symbol.value- the value of the symbol.
-
-
Method Details
-
isTerminal
public boolean isTerminal()Returns whether the symbol represents a terminal. A terminal symbol must have a non-null LexicalUnit type.- Returns:
- a boolean which is true iff the Symbol represents a terminal.
-
isNonTerminal
public boolean isNonTerminal()Returns whether the symbol represents a non-terminal. A non-terminal symbol has no type.- Returns:
- a boolean which is true iff the Symbol represents a non-terminal.
-
getType
Returns the type of the symbol. The type of a non-terminal is null.- Returns:
- the value of attribute
type.
-
getValue
Returns the value of the symbol.- Returns:
- the value of attribute
value.
-
getLine
public int getLine()Returns the line where the symbol appeared.- Returns:
- the value of attribute
line.
-
getColumn
public int getColumn()Returns the column where the symbol appeared.- Returns:
- the value of attribute
column.
-
hashCode
public int hashCode()Returns a hash code value for the object. -
equals
Compares this symbol to another object for equality. Two symbols are equal if they have the same type and value. -
toString
Returns a string representation of the symbol. This method has been modified from the provided class to provide the value of the non-terminal symbols. -
escapeLaTeX
Escape LaTeX special characters in a string. If the input string is null, returns an empty string.- Parameters:
s- the input string.- Returns:
- the escaped string.
-
toTexString
Returns a LaTeX-formatted string representation of the symbol.- Returns:
- a LaTeX-formatted string representation of the symbol.
-