#include <cstring>
#include <stdexcept>
#include <iostream>
+#include <stdio.h>
#include "lexer.hpp"
}
}
c = *bufpos++;
+ if(c == '\n')
+ ++linenumber;
+}
+
+void
+Lexer::addChar()
+{
+ if(token_length < MAX_TOKEN_LENGTH)
+ token_string[token_length++] = c;
+ nextChar();
}
Lexer::TokenType
static const char* delims = "\"();";
while(isspace(c)) {
- if(c == '\n')
- ++linenumber;
nextChar();
- };
+ }
token_length = 0;
switch(c) {
case ';': // comment
- while(true) {
+ while(c != '\n') {
nextChar();
- if(c == '\n') {
- ++linenumber;
- break;
- }
}
return getNextToken(); // and again
case '(':
case '\r':
continue;
case '\n':
- linenumber++;
break;
case '\\':
nextChar();
nextChar();
while(isalnum(c) || c == '_') {
- if(token_length < MAX_TOKEN_LENGTH)
- token_string[token_length++] = c;
- nextChar();
+ addChar();
}
token_string[token_length] = 0;
else if(isalnum(c) || c == '_')
have_nondigits = true;
- if(token_length < MAX_TOKEN_LENGTH)
- token_string[token_length++] = c;
-
- nextChar();
+ addChar();
} while(!isspace(c) && !strchr(delims, c));
token_string[token_length] = 0;
return TOKEN_INTEGER;
} else {
do {
- if(token_length < MAX_TOKEN_LENGTH)
- token_string[token_length++] = c;
- nextChar();
+ addChar();
} while(!isspace(c) && !strchr(delims, c));
token_string[token_length] = 0;