aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/alf.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/alf.c b/src/alf.c
index 27b6d86..7b27861 100644
--- a/src/alf.c
+++ b/src/alf.c
@@ -200,22 +200,19 @@ void store_token(int tok) {
}
}
+/* search backwards, the tokens are stored with longer ones later
+ in the list. */
int match_token(int pos) {
- int i, bestmatch = -1;
+ int i;
- for(i = 0; i < curr_token; i++) {
- if(i == TOK_RESET || i == TOK_END)
- continue;
+ for(i = curr_token - 1; i >= INIT_TOKEN; i--) {
if(memcmp(&input_buf[pos], tokentab[i].start, tokentab[i].length) == 0)
- bestmatch = i;
- }
-
- if(bestmatch == -1) {
- fprintf(stderr, "BUG: bestmatch is -1, this should never happen!\n");
- exit(1);
+ return i;
}
- return bestmatch;
+ /* hard-coded single character tokens map to their values, no need
+ to search. */
+ return input_buf[pos];
}
void make_token(int start, int end) {