fix put_back in lexer
authorMatthias Braun <matze@braunis.de>
Fri, 28 Sep 2007 18:37:42 +0000 (18:37 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 28 Sep 2007 18:37:42 +0000 (18:37 +0000)
[r18363]

lexer.c
parser.c

diff --git a/lexer.c b/lexer.c
index ed0bab1..7dbaaab 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -12,7 +12,7 @@
 #include <string.h>
 #include <ctype.h>
 
-#define DEBUG_CHARS
+//#define DEBUG_CHARS
 #define MAX_PUTBACK 3
 
 static int         c;
@@ -58,11 +58,16 @@ static inline void next_real_char(void)
 
 static inline void put_back(int pc)
 {
-       char *p = (char*) bufpos - 1;
-       bufpos--;
-       assert(p >= buf);
+       assert(bufpos >= buf);
+       assert(bufpos < buf+MAX_PUTBACK || *bufpos == pc);
+
+       char *p = buf + (bufpos - buf);
        *p = pc;
 
+       /* going backwards in the buffer is legal as long as it's not more often
+        * than MAX_PUTBACK */
+       bufpos--;
+
 #ifdef DEBUG_CHARS
        printf("putback '%c'\n", pc);
 #endif
index 879b620..b97339a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -14,7 +14,7 @@
 #include "adt/error.h"
 #include "adt/array.h"
 
-#define PRINT_TOKENS
+//#define PRINT_TOKENS
 //#define ABORT_ON_ERROR
 #define MAX_LOOKAHEAD 2
 //#define STRICT_C99