-/* Generated by re2c 0.13.4.dev on Mon Mar 24 16:50:42 2008 */
+/* Generated by re2c 0.13.4.dev on Mon Mar 24 18:41:16 2008 */
/* $Id$ */
#include <stdlib.h>
#include <string.h>
namespace re2c
{
-ScannerState::ScannerState()
- : bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
- , top(NULL), eof(NULL), ctx(NULL), tchar(0), tline(0), cline(1), iscfg(0)
- , in_parse(false)
-{
-}
-
-Scanner::Scanner(std::istream& i, std::ostream& o)
- : in(i), out(o)
-{
-}
-
-char *Scanner::fill(char *cursor, uint need)
-{
- if(!eof)
- {
- uint cnt;
- /* Do not get rid of anything when rFlag is active. Otherwise
- * get rid of everything that was already handedout. */
- if (!rFlag)
- {
- cnt = tok - bot;
- if (cnt)
- {
- memmove(bot, tok, top - tok);
- tok = bot;
- ptr -= cnt;
- cursor -= cnt;
- pos -= cnt;
- lim -= cnt;
- }
- }
- /* In crease buffer size. */
- need = MAX(need, BSIZE);
- if (static_cast<uint>(top - lim) < need)
- {
- char *buf = new char[(lim - bot) + need];
- if (!buf)
- {
- fatal("Out of memory");
- }
- memcpy(buf, tok, lim - tok);
- tok = buf;
- ptr = &buf[ptr - bot];
- cursor = &buf[cursor - bot];
- pos = &buf[pos - bot];
- lim = &buf[lim - bot];
- top = &lim[need];
- delete [] bot;
- bot = buf;
- }
- /* Append to buffer. */
- in.read(lim, need);
- if ((cnt = in.gcount()) != need)
- {
- eof = &lim[cnt];
- *eof++ = '\0';
- }
- lim += cnt;
- }
- return cursor;
-}
-
-
-
Scanner::ParseMode Scanner::echo()
{
char *cursor = cur;
}
-void Scanner::set_in_parse(bool new_in_parse)
-{
- in_parse = new_in_parse;
-}
-
-void Scanner::fatal_at(uint line, uint ofs, const char *msg) const
-{
- out.flush();
- std::cerr << "re2c: error: "
- << "line " << line << ", column " << (tchar + ofs + 1) << ": "
- << msg << std::endl;
- exit(1);
-}
-
-void Scanner::fatal(uint ofs, const char *msg) const
-{
- fatal_at(in_parse ? tline : cline, ofs, msg);
-}
-
-void Scanner::fatalf_at(uint line, const char* fmt, ...) const
-{
- char szBuf[4096];
-
- va_list args;
-
- va_start(args, fmt);
- vsnprintf(szBuf, sizeof(szBuf), fmt, args);
- va_end(args);
-
- szBuf[sizeof(szBuf)-1] = '0';
-
- fatal_at(line, 0, szBuf);
-}
-
-void Scanner::fatalf(const char *fmt, ...) const
-{
- char szBuf[4096];
-
- va_list args;
-
- va_start(args, fmt);
- vsnprintf(szBuf, sizeof(szBuf), fmt, args);
- va_end(args);
-
- szBuf[sizeof(szBuf)-1] = '0';
-
- fatal(szBuf);
-}
-
-Scanner::~Scanner()
-{
- if (bot)
- {
- delete [] bot;
- }
-}
-
-void Scanner::check_token_length(char *pos, uint len) const
-{
- if (pos < bot || pos + len >= top)
- {
- fatal("Token exceeds limit");
- }
-}
-
-SubStr Scanner::raw_token(std::string enclosure) const
-{
- return SubStr(std::string(enclosure + token().to_string() + enclosure).c_str());
-}
-
-void Scanner::reuse()
-{
- next_label = 0;
- next_fill_index = 0;
- bWroteGetState = false;
- bWroteCondCheck = false;
- mapCodeName.clear();
-}
-
} // end namespace re2c
/* $Id$ */
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
}
}
+ScannerState::ScannerState()
+ : tok(NULL), ptr(NULL), cur(NULL), pos(NULL), ctx(NULL)
+ , bot(NULL), lim(NULL), top(NULL), eof(NULL)
+ , tchar(0), tline(0), cline(1), iscfg(0)
+ , in_parse(false)
+{
+}
+
+Scanner::Scanner(std::istream& i, std::ostream& o)
+ : ScannerState(), in(i), out(o)
+{
+}
+
+char *Scanner::fill(char *cursor, uint need)
+{
+ if(!eof)
+ {
+ uint cnt;
+ /* Do not get rid of anything when rFlag is active. Otherwise
+ * get rid of everything that was already handedout. */
+ if (!rFlag)
+ {
+ cnt = tok - bot;
+ if (cnt)
+ {
+ memmove(bot, tok, top - tok);
+ tok = bot;
+ ptr -= cnt;
+ cursor -= cnt;
+ pos -= cnt;
+ lim -= cnt;
+ }
+ }
+ /* In crease buffer size. */
+ if (BSIZE > need)
+ {
+ need = BSIZE;
+ }
+ if (static_cast<uint>(top - lim) < need)
+ {
+ char *buf = new char[(lim - bot) + need];
+ if (!buf)
+ {
+ fatal("Out of memory");
+ }
+ memcpy(buf, bot, lim - bot);
+ tok = &buf[tok - bot];
+ ptr = &buf[ptr - bot];
+ cur = &buf[cur - bot];
+ pos = &buf[pos - bot];
+ lim = &buf[lim - bot];
+ top = &lim[need];
+ ctx = &buf[ctx - bot];
+ cursor = &buf[cursor - bot];
+ delete [] bot;
+ bot = buf;
+ }
+ /* Append to buffer. */
+ in.read(lim, need);
+ if ((cnt = in.gcount()) != need)
+ {
+ eof = &lim[cnt];
+ *eof++ = '\0';
+ }
+ lim += cnt;
+ }
+ return cursor;
+}
+
+void Scanner::set_in_parse(bool new_in_parse)
+{
+ in_parse = new_in_parse;
+}
+
+void Scanner::fatal_at(uint line, uint ofs, const char *msg) const
+{
+ out.flush();
+ std::cerr << "re2c: error: "
+ << "line " << line << ", column " << (tchar + ofs + 1) << ": "
+ << msg << std::endl;
+ exit(1);
+}
+
+void Scanner::fatal(uint ofs, const char *msg) const
+{
+ fatal_at(in_parse ? tline : cline, ofs, msg);
+}
+
+void Scanner::fatalf_at(uint line, const char* fmt, ...) const
+{
+ char szBuf[4096];
+
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(szBuf, sizeof(szBuf), fmt, args);
+ va_end(args);
+
+ szBuf[sizeof(szBuf)-1] = '0';
+
+ fatal_at(line, 0, szBuf);
+}
+
+void Scanner::fatalf(const char *fmt, ...) const
+{
+ char szBuf[4096];
+
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(szBuf, sizeof(szBuf), fmt, args);
+ va_end(args);
+
+ szBuf[sizeof(szBuf)-1] = '0';
+
+ fatal(szBuf);
+}
+
+Scanner::~Scanner()
+{
+ if (bot)
+ {
+ delete [] bot;
+ }
+}
+
+void Scanner::check_token_length(char *pos, uint len) const
+{
+ if (pos < bot || pos + len >= top)
+ {
+ fatal("Token exceeds limit");
+ }
+}
+
+SubStr Scanner::raw_token(std::string enclosure) const
+{
+ return SubStr(std::string(enclosure + token().to_string() + enclosure).c_str());
+}
+
+void Scanner::reuse()
+{
+ next_label = 0;
+ next_fill_index = 0;
+ bWroteGetState = false;
+ bWroteCondCheck = false;
+ mapCodeName.clear();
+}
+
+void Scanner::restore_state(const ScannerState& state)
+{
+ int diff = bot - state.bot;
+ char *old_bot = bot;
+ char *old_lim = lim;
+ char *old_top = top;
+ char *old_eof = eof;
+ *(ScannerState*)this = state;
+ if (diff)
+ {
+ tok -= diff;
+ ptr -= diff;
+ cur -= diff;
+ pos -= diff;
+ ctx -= diff;
+ bot = old_bot;
+ lim = old_lim;
+ top = old_top;
+ eof = old_eof;
+ }
+}
+
} // end namespace re2c
namespace re2c
{
+enum { BSIZE = 8192};
+
extern file_info sourceFileInfo;
extern file_info outputFileInfo;
extern file_info headerFileInfo;
{
ScannerState();
- char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof, *ctx;
+ char *tok, *ptr, *cur, *pos, *ctx; // positioning
+ char *bot, *lim, *top, *eof; // buffer
uint tchar, tline, cline, iscfg, buf_size;
bool in_parse;
};
state = *this;
}
-inline void Scanner::restore_state(const ScannerState& state)
-{
- if (bot != state.bot)
- {
- fatal("illegal internal restore operation");
- }
- *(ScannerState*)this = state;
-}
-
inline void Scanner::fatal(const char *msg) const
{
fatal(0, msg);
#include <string.h>
#include <iostream>
#include <sstream>
-#include <stdarg.h>
#include "scanner.h"
#include "parser.h"
#include "y.tab.h"
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
-#define BSIZE 8192
#define YYCTYPE unsigned char
#define YYCURSOR cursor
#define YYLIMIT lim
namespace re2c
{
-ScannerState::ScannerState()
- : bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
- , top(NULL), eof(NULL), ctx(NULL), tchar(0), tline(0), cline(1), iscfg(0)
- , in_parse(false)
-{
-}
-
-Scanner::Scanner(std::istream& i, std::ostream& o)
- : in(i), out(o)
-{
-}
-
-char *Scanner::fill(char *cursor, uint need)
-{
- if(!eof)
- {
- uint cnt;
- /* Do not get rid of anything when rFlag is active. Otherwise
- * get rid of everything that was already handedout. */
- if (!rFlag)
- {
- cnt = tok - bot;
- if (cnt)
- {
- memmove(bot, tok, top - tok);
- tok = bot;
- ptr -= cnt;
- cursor -= cnt;
- pos -= cnt;
- lim -= cnt;
- }
- }
- /* In crease buffer size. */
- need = MAX(need, BSIZE);
- if (static_cast<uint>(top - lim) < need)
- {
- char *buf = new char[(lim - bot) + need];
- if (!buf)
- {
- fatal("Out of memory");
- }
- memcpy(buf, tok, lim - tok);
- tok = buf;
- ptr = &buf[ptr - bot];
- cursor = &buf[cursor - bot];
- pos = &buf[pos - bot];
- lim = &buf[lim - bot];
- top = &lim[need];
- delete [] bot;
- bot = buf;
- }
- /* Append to buffer. */
- in.read(lim, need);
- if ((cnt = in.gcount()) != need)
- {
- eof = &lim[cnt];
- *eof++ = '\0';
- }
- lim += cnt;
- }
- return cursor;
-}
-
/*!re2c
zero = "\000";
any = [\000-\377];
*/
}
-void Scanner::set_in_parse(bool new_in_parse)
-{
- in_parse = new_in_parse;
-}
-
-void Scanner::fatal_at(uint line, uint ofs, const char *msg) const
-{
- out.flush();
- std::cerr << "re2c: error: "
- << "line " << line << ", column " << (tchar + ofs + 1) << ": "
- << msg << std::endl;
- exit(1);
-}
-
-void Scanner::fatal(uint ofs, const char *msg) const
-{
- fatal_at(in_parse ? tline : cline, ofs, msg);
-}
-
-void Scanner::fatalf_at(uint line, const char* fmt, ...) const
-{
- char szBuf[4096];
-
- va_list args;
-
- va_start(args, fmt);
- vsnprintf(szBuf, sizeof(szBuf), fmt, args);
- va_end(args);
-
- szBuf[sizeof(szBuf)-1] = '0';
-
- fatal_at(line, 0, szBuf);
-}
-
-void Scanner::fatalf(const char *fmt, ...) const
-{
- char szBuf[4096];
-
- va_list args;
-
- va_start(args, fmt);
- vsnprintf(szBuf, sizeof(szBuf), fmt, args);
- va_end(args);
-
- szBuf[sizeof(szBuf)-1] = '0';
-
- fatal(szBuf);
-}
-
-Scanner::~Scanner()
-{
- if (bot)
- {
- delete [] bot;
- }
-}
-
-void Scanner::check_token_length(char *pos, uint len) const
-{
- if (pos < bot || pos + len >= top)
- {
- fatal("Token exceeds limit");
- }
-}
-
-SubStr Scanner::raw_token(std::string enclosure) const
-{
- return SubStr(std::string(enclosure + token().to_string() + enclosure).c_str());
-}
-
-void Scanner::reuse()
-{
- next_label = 0;
- next_fill_index = 0;
- bWroteGetState = false;
- bWroteCondCheck = false;
- mapCodeName.clear();
-}
-
} // end namespace re2c