Sat, 18 Jan 2014 02:11:45 +0200
- further lexer corrections
src/events.cc | file | annotate | diff | comparison | revisions | |
src/format.cc | file | annotate | diff | comparison | revisions | |
src/lexer.cc | file | annotate | diff | comparison | revisions | |
src/lexer.h | file | annotate | diff | comparison | revisions | |
src/stringtable.cc | file | annotate | diff | comparison | revisions | |
src/types.h | file | annotate | diff | comparison | revisions |
--- a/src/events.cc Fri Jan 17 22:57:40 2014 +0200 +++ b/src/events.cc Sat Jan 18 02:11:45 2014 +0200 @@ -47,8 +47,9 @@ lx.process_file ("events.def"); int num_events = 0; - while (lx.get_next (tk_symbol)) + while (lx.get_next()) { + lx.must_be (tk_symbol); event_info* e = new event_info; e->name = lx.get_token()->text; e->number = num_events++;
--- a/src/format.cc Fri Jan 17 22:57:40 2014 +0200 +++ b/src/format.cc Sat Jan 18 02:11:45 2014 +0200 @@ -74,14 +74,14 @@ // handle modifiers if (fmt[pos + ofs] == 's' || fmt[pos + ofs] == 'x') { - mod = fmt[ pos + ofs ]; + mod = fmt[pos + ofs]; ofs++; } if (!isdigit (fmt[pos + ofs])) { fprintf (stderr, "bad format string, expected digit with optional " - "modifier after '%%':\n"); + "modifier after '%%':\n"); draw_pos (fmt, pos); return fmt; } @@ -96,19 +96,12 @@ string repl = args[i].as_string(); - if (mod == 's') - { - repl = (repl == "1") ? "" : "s"; - } - - elif (mod == 'd') + switch (mod) { - repl.sprintf ("%d", repl[0]); - } - elif (mod == 'x') - { - // modifier x: reinterpret the argument as hex - repl.sprintf ("0x%X", strtol (repl.chars(), null, 10)); + case 's': repl = (repl == "1") ? "" : "s"; break; + case 'd': repl.sprintf ("%d", repl[0]); break; + case 'x': repl.sprintf ("0x%X", repl.to_long()); break; + default: break; } fmt.replace (pos, 1 + ofs, repl);
--- a/src/lexer.cc Fri Jan 17 22:57:40 2014 +0200 +++ b/src/lexer.cc Sat Jan 18 02:11:45 2014 +0200 @@ -82,6 +82,8 @@ tok.column = sc.get_column(); tok.type = sc.get_token_type(); tok.text = sc.get_token_text(); + // devf ("Token #%1: %2:%3:%4: %5 (%6)\n", m_tokens.size(), + // tok.file, tok.line, tok.column, describe_token (&tok), describe_token_type (tok.type)); m_tokens << tok; } } @@ -100,10 +102,7 @@ m_token_position++; - if (is_at_end()) - return false; - - if (req != tk_any && get_token_type() != req) + if (is_at_end() || (req != tk_any && get_token_type() != req)) { m_token_position = pos; return false; @@ -114,12 +113,13 @@ // ============================================================================= // -void lexer::must_get_next (e_token tok) +void lexer::must_get_next (e_token tt) { if (!get_next()) error ("unexpected EOF"); - must_be (tok); + if (tt != tk_any) + must_be (tt); } // =============================================================================
--- a/src/lexer.h Fri Jan 17 22:57:40 2014 +0200 +++ b/src/lexer.h Sat Jan 18 02:11:45 2014 +0200 @@ -63,7 +63,7 @@ inline bool has_valid_token() const { - return (is_at_end() == false && m_token_position != m_tokens.begin() - 1); + return (m_token_position < m_tokens.end() && m_token_position >= m_tokens.begin()); } inline token* get_token() const
--- a/src/stringtable.cc Fri Jan 17 22:57:40 2014 +0200 +++ b/src/stringtable.cc Sat Jan 18 02:11:45 2014 +0200 @@ -67,9 +67,8 @@ error ("too many strings!\n"); // Now, dump the string into the slot - g_string_table[idx] = a; - - return idx; + g_string_table.push_back (a); + return (g_string_table.size() - 1); } // ============================================================================