Commit fbab905a authored by Guido van Rossum's avatar Guido van Rossum

Added 2-char tokens and new versions of comparisons

parent 8883aaa5
...@@ -81,6 +81,11 @@ char *tok_name[] = { ...@@ -81,6 +81,11 @@ char *tok_name[] = {
"BACKQUOTE", "BACKQUOTE",
"LBRACE", "LBRACE",
"RBRACE", "RBRACE",
"EQEQUAL",
"NOTEQUAL",
"LESSEQUAL",
"GREATEREQUAL",
/* This table must match the #defines in token.h! */
"OP", "OP",
"<ERRORTOKEN>", "<ERRORTOKEN>",
"<N_TOKENS>" "<N_TOKENS>"
...@@ -301,6 +306,37 @@ tok_1char(c) ...@@ -301,6 +306,37 @@ tok_1char(c)
} }
int
tok_2char(c1, c2)
int c1, c2;
{
switch (c1) {
case '=':
switch (c2) {
case '=': return EQEQUAL;
}
break;
case '!':
switch (c2) {
case '=': return NOTEQUAL;
}
break;
case '<':
switch (c2) {
case '>': return NOTEQUAL;
case '=': return LESSEQUAL;
}
break;
case '>':
switch (c2) {
case '=': return GREATEREQUAL;
}
break;
}
return OP;
}
/* Get next token, after space stripping etc. */ /* Get next token, after space stripping etc. */
int int
...@@ -531,6 +567,17 @@ tok_get(tok, p_start, p_end) ...@@ -531,6 +567,17 @@ tok_get(tok, p_start, p_end)
goto again; /* Read next line */ goto again; /* Read next line */
} }
/* Check for two-character token */
{
int c2 = tok_nextc(tok);
int token = tok_2char(c, c2);
if (token != OP) {
*p_end = tok->cur;
return token;
}
tok_backup(tok, c2);
}
/* Punctuation character */ /* Punctuation character */
*p_end = tok->cur; *p_end = tok->cur;
return tok_1char(c); return tok_1char(c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment