diff options
author | Teddy <[email protected]> | 2013-08-04 17:18:20 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-04 17:18:20 +0800 |
commit | acb298c7f864f9862859320555b416c97632d2fa (patch) | |
tree | 667922093cf5066fbbf5fbc989f07cf19f4457e3 | |
parent | 5ab1a4462b1df413a54dc1befc68961c81be69bf (diff) |
added comment support
-rw-r--r-- | parser.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -17,12 +17,17 @@ void Tokenizor::set_stream(FILE *_stream) { stream = _stream; } +#define IS_NEWLINE(ch) \ + ((ch) == '\n') #define IS_BRACKET(ch) \ ((ch) == '(' || (ch) == ')') #define IS_SPACE(ch) \ - ((ch) == ' ' || (ch) == '\t' || (ch) == '\n') + ((ch) == ' ' || (ch) == '\t' || IS_NEWLINE(ch)) #define IS_DELIMITER(ch) \ (IS_BRACKET(ch) || IS_SPACE(ch)) +#define IS_COMMENT(ch) \ + ((ch) == ';') + #define POP \ do { \ *buff_ptr = 0; \ @@ -36,10 +41,20 @@ bool Tokenizor::get_token(string &ret) { while (fread(&ch, 1, 1, stream)) { if (buff_ptr != buff && - (IS_BRACKET(*buff) || IS_DELIMITER(ch))) + (IS_BRACKET(*buff) || + IS_DELIMITER(ch) || + IS_COMMENT(ch))) { - POP; - flag = true; + if (IS_COMMENT(*buff)) + { + if (IS_NEWLINE(ch)) buff_ptr = buff; + else buff_ptr = buff + 1; + } + else + { + POP; + flag = true; + } } if (!IS_SPACE(ch)) *buff_ptr++ = ch; if (flag) return true; |