forked from darius/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.java
More file actions
53 lines (44 loc) · 1.49 KB
/
Copy pathToken.java
File metadata and controls
53 lines (44 loc) · 1.49 KB
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
// A lexical token from an input string.
package com.expr;
class Token {
public static final int TT_ERROR = -1;
public static final int TT_EOF = -2;
public static final int TT_NUMBER = -3;
public static final int TT_WORD = -4;
public static final int TT_LE = -5;
public static final int TT_NE = -6;
public static final int TT_GE = -7;
public Token(int ttype, double nval, String input, int start, int end) {
this.ttype = ttype;
this.sval = input.substring(start, end);
this.nval = nval;
this.location = start;
int count = 0;
for (int i = start - 1; 0 <= i; --i) {
if (!Character.isWhitespace(input.charAt(i)))
break;
++count;
}
this.leadingWhitespace = count;
count = 0;
for (int i = end; i < input.length(); ++i) {
if (!Character.isWhitespace(input.charAt(i)))
break;
++count;
}
this.trailingWhitespace = count;
}
Token(int ttype, double nval, String sval, Token token) {
this.ttype = ttype;
this.sval = sval;
this.nval = nval;
this.location = token.location;
this.leadingWhitespace = token.leadingWhitespace;
this.trailingWhitespace = token.trailingWhitespace;
}
public final int ttype;
public final String sval;
public final double nval;
public final int location;
public final int leadingWhitespace, trailingWhitespace;
}