-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.java
63 lines (53 loc) · 1.61 KB
/
Token.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package lexer;
/** <pre>
* The Token class records the information for a token:
* 1. The Symbol that describes the characters in the token
* 2. The starting column in the source file of the token and
* 3. The ending column in the source file of the token
* </pre>
*/
public class Token {
private int leftPosition,rightPosition,linenum;
private Symbol symbol;
/**
* Create a new Token based on the given Symbol
* @param leftPosition is the source file column where the Token begins
* @param rightPosition is the source file column where the Token ends
* @param lineNumber is the line number where the Token can be found in the source
*/
public Token(int leftPosition, int rightPosition, int lineNumber, Symbol sym) {
this.leftPosition = leftPosition;
this.rightPosition = rightPosition;
this.linenum = lineNumber;
this.symbol = sym;
}
public Symbol getSymbol() {
return symbol;
}
public void print() {
System.out.println(" " + symbol.toString() +
" left: " + leftPosition +
" right: " + rightPosition +
"line no.: " + linenum);
return;
}
public String toString() {
return symbol.toString();
}
public int getLeftPosition() {
return leftPosition;
}
public int getRightPosition() {
return rightPosition;
}
public int getLineNumber() {
return linenum;
}
/**
* @return the integer that represents the kind of symbol we have which
* is actually the type of token associated with the symbol
*/
public Tokens getKind() {
return symbol.getKind();
}
}