]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added 2-char tokens and new versions of comparisons
authorGuido van Rossum <guido@python.org>
Sun, 20 Oct 1991 20:25:03 +0000 (20:25 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 20 Oct 1991 20:25:03 +0000 (20:25 +0000)
Parser/tokenizer.c

index d737e55cbb3fa9dfd6e0e1ae8e53ceefc1901e6a..ccc6d6d94fa7069988aafabcf192483d1313a5ab 100644 (file)
@@ -81,6 +81,11 @@ char *tok_name[] = {
        "BACKQUOTE",
        "LBRACE",
        "RBRACE",
+       "EQEQUAL",
+       "NOTEQUAL",
+       "LESSEQUAL",
+       "GREATEREQUAL",
+       /* This table must match the #defines in token.h! */
        "OP",
        "<ERRORTOKEN>",
        "<N_TOKENS>"
@@ -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. */
 
 int
@@ -531,6 +567,17 @@ tok_get(tok, p_start, p_end)
                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 */
        *p_end = tok->cur;
        return tok_1char(c);