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

Skip to content

Commit baf0ebf

Browse files
committed
Added shift and mask ops.
Allow numbers starting with a period.
1 parent 7928cd7 commit baf0ebf

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

Parser/tokenizer.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ char *tok_name[] = {
8585
"NOTEQUAL",
8686
"LESSEQUAL",
8787
"GREATEREQUAL",
88+
"TILDE",
89+
"CIRCUMFLEX",
90+
"LEFTSHIFT",
91+
"RIGHTSHIFT",
8892
/* This table must match the #defines in token.h! */
8993
"OP",
9094
"<ERRORTOKEN>",
@@ -301,6 +305,8 @@ tok_1char(c)
301305
case '`': return BACKQUOTE;
302306
case '{': return LBRACE;
303307
case '}': return RBRACE;
308+
case '^': return CIRCUMFLEX;
309+
case '~': return TILDE;
304310
default: return OP;
305311
}
306312
}
@@ -325,11 +331,13 @@ tok_2char(c1, c2)
325331
switch (c2) {
326332
case '>': return NOTEQUAL;
327333
case '=': return LESSEQUAL;
334+
case '<': return LEFTSHIFT;
328335
}
329336
break;
330337
case '>':
331338
switch (c2) {
332339
case '=': return GREATEREQUAL;
340+
case '>': return RIGHTSHIFT;
333341
}
334342
break;
335343
}
@@ -438,7 +446,7 @@ tok_get(tok, p_start, p_end)
438446
beginning or end of the file. (Will vi never die...?)
439447
For Python it must be at the beginning of the file! */
440448
int x;
441-
/* XXX The case to (unsigned char *) is needed by THINK C 3.0 */
449+
/* XXX The cast to (unsigned char *) is needed by THINK C 3.0 */
442450
if (sscanf(/*(unsigned char *)*/tok->cur,
443451
" vi:set tabsize=%d:", &x) == 1 &&
444452
x >= 1 && x <= 40) {
@@ -451,8 +459,10 @@ tok_get(tok, p_start, p_end)
451459
}
452460

453461
/* Check for EOF and errors now */
454-
if (c == EOF)
462+
if (c == EOF) {
463+
*p_start = *p_end = tok->cur;
455464
return tok->done == E_EOF ? ENDMARKER : ERRORTOKEN;
465+
}
456466

457467
/* Identifier (most frequent token!) */
458468
if (isalpha(c) || c == '_') {
@@ -473,6 +483,19 @@ tok_get(tok, p_start, p_end)
473483
return NEWLINE;
474484
}
475485

486+
/* Period or number starting with period? */
487+
if (c == '.') {
488+
c = tok_nextc(tok);
489+
if (isdigit(c)) {
490+
goto fraction;
491+
}
492+
else {
493+
tok_backup(tok, c);
494+
*p_end = tok->cur;
495+
return DOT;
496+
}
497+
}
498+
476499
/* Number */
477500
if (isdigit(c)) {
478501
if (c == '0') {

0 commit comments

Comments
 (0)