Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fbab905

Browse files
committed
Added 2-char tokens and new versions of comparisons
1 parent 8883aaa commit fbab905

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Parser/tokenizer.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ char *tok_name[] = {
8181
"BACKQUOTE",
8282
"LBRACE",
8383
"RBRACE",
84+
"EQEQUAL",
85+
"NOTEQUAL",
86+
"LESSEQUAL",
87+
"GREATEREQUAL",
88+
/* This table must match the #defines in token.h! */
8489
"OP",
8590
"<ERRORTOKEN>",
8691
"<N_TOKENS>"
@@ -301,6 +306,37 @@ tok_1char(c)
301306
}
302307

303308

309+
int
310+
tok_2char(c1, c2)
311+
int c1, c2;
312+
{
313+
switch (c1) {
314+
case '=':
315+
switch (c2) {
316+
case '=': return EQEQUAL;
317+
}
318+
break;
319+
case '!':
320+
switch (c2) {
321+
case '=': return NOTEQUAL;
322+
}
323+
break;
324+
case '<':
325+
switch (c2) {
326+
case '>': return NOTEQUAL;
327+
case '=': return LESSEQUAL;
328+
}
329+
break;
330+
case '>':
331+
switch (c2) {
332+
case '=': return GREATEREQUAL;
333+
}
334+
break;
335+
}
336+
return OP;
337+
}
338+
339+
304340
/* Get next token, after space stripping etc. */
305341

306342
int
@@ -531,6 +567,17 @@ tok_get(tok, p_start, p_end)
531567
goto again; /* Read next line */
532568
}
533569

570+
/* Check for two-character token */
571+
{
572+
int c2 = tok_nextc(tok);
573+
int token = tok_2char(c, c2);
574+
if (token != OP) {
575+
*p_end = tok->cur;
576+
return token;
577+
}
578+
tok_backup(tok, c2);
579+
}
580+
534581
/* Punctuation character */
535582
*p_end = tok->cur;
536583
return tok_1char(c);

0 commit comments

Comments
 (0)