From acb298c7f864f9862859320555b416c97632d2fa Mon Sep 17 00:00:00 2001 From: Teddy Date: Sun, 4 Aug 2013 17:18:20 +0800 Subject: added comment support --- parser.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/parser.cpp b/parser.cpp index ecfafab..8de812f 100644 --- a/parser.cpp +++ b/parser.cpp @@ -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; -- cgit v1.2.3-70-g09d2