diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-02-03 14:00:03 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-02-03 14:00:03 -0500 |
commit | 6f681178e9d39b66648f2e52db309ca5858e39fb (patch) | |
tree | ef3a9510791ac1eb2b6759562aff821da5dc3ca1 /dimension | |
parent | 6b12181918162cd725cdc4981f5e731eeed4076f (diff) | |
download | dimension-6f681178e9d39b66648f2e52db309ca5858e39fb.tar.xz |
Fix #else handling.
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/tokenize.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/dimension/tokenize.c b/dimension/tokenize.c index bee03b6..f7f9187 100644 --- a/dimension/tokenize.c +++ b/dimension/tokenize.c @@ -262,7 +262,7 @@ dmnsn_if_buffer(int token, dmnsn_token_buffer *prev, dmnsn_undef_symbol(symtable, "__cond__"); - int nesting = 1; + int nesting = 1, else_seen = 0; while (1) { /* Non-recursive call */ buffered.type = dmnsn_yylex_wrapper(&buffered.lval, &buffered.lloc, @@ -297,8 +297,17 @@ dmnsn_if_buffer(int token, dmnsn_token_buffer *prev, if (nesting == 0) { break; } else if (nesting == 1 && buffered.type == DMNSN_T_ELSE) { - cond = !cond; - continue; + if (else_seen || tbuffer->prev && tbuffer->prev->type == DMNSN_T_WHILE) { + dmnsn_diagnostic(filename, buffered.lloc.first_line, + buffered.lloc.first_column, + "syntax error, unexpected #else"); + dmnsn_delete_token_buffer(tbuffer); + return NULL; + } else { + cond = !cond; + else_seen = 1; + continue; + } } if (cond) { |