From: helly Date: Fri, 22 Apr 2005 22:03:08 +0000 (+0000) Subject: - Added -d flag which outputs a debugable parser. X-Git-Tag: 0.13.6~648 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c8de1e6e46a06d1b4249270025942d4b1e50d20;p=re2c - Added -d flag which outputs a debugable parser. --- diff --git a/CHANGELOG b/CHANGELOG index f224b770..c1095b95 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Version 0.9.7 (200?-??-??) -------------------------- - Applied #1181535 storable state patch. +- Added -d flag which outputs a debugable parser. - Fixed bug #1187785 Re2c fails to generate valid code. - Fixed bug #1187452 unused variable `yyaccept'. diff --git a/code.cc b/code.cc index 897551c0..1d6072a2 100644 --- a/code.cc +++ b/code.cc @@ -564,6 +564,11 @@ void Go::genSwitch(std::ostream &o, State *from, State *next, bool &readCh) } } + if (dFlag) + { + o << "\tfprintf(stderr, \"[%c]\\n\", yych);\n"; + } + if (readCh) { o << "\tswitch((yych = *YYCURSOR)) {\n"; @@ -742,7 +747,10 @@ void State::emit(std::ostream &o, bool &readCh) { o << "yy" << label << ":"; } - /* o << "\nfprintf(stderr, \"<" << label << ">\");\n";*/ + if (dFlag) + { + o << "\nfprintf(stderr, \"<" << label << ">[%c]\\n\", *YYCURSOR);\n"; + } action->emit(o, readCh); } diff --git a/globals.h b/globals.h index 240ba7d2..b868b1b7 100644 --- a/globals.h +++ b/globals.h @@ -35,6 +35,7 @@ extern char *fileName; extern char *outputFileName; extern bool sFlag; extern bool bFlag; +extern bool dFlag; extern bool bUsedYYAccept; extern unsigned int oline; extern uint maxFill; diff --git a/main.cc b/main.cc index 90c9694f..142c90fb 100644 --- a/main.cc +++ b/main.cc @@ -20,6 +20,7 @@ char *fileName = 0; char *outputFileName = 0; bool sFlag = false; bool bFlag = false; +bool dFlag = false; bool bUsedYYAccept = false; unsigned int oline = 1; uint maxFill = 1; @@ -40,6 +41,7 @@ static const mbo_opt_struct OPTIONS[] = mbo_opt_struct('h', 0, "help"), mbo_opt_struct('s', 0, "nested-ifs"), mbo_opt_struct('f', 0, "storable-state"), + mbo_opt_struct('d', 0, "debug-output"), mbo_opt_struct('o', 1, "output"), mbo_opt_struct('v', 0, "version"), mbo_opt_struct('V', 0, "vernum"), @@ -48,7 +50,7 @@ static const mbo_opt_struct OPTIONS[] = static void usage() { - cerr << "usage: re2c [-esbvh] file\n" + cerr << "usage: re2c [-esbvhd] file\n" "\n" "-? -h --help Display this info.\n" "\n" @@ -67,6 +69,10 @@ static void usage() "\n" "-o --output=output Specify the output file instead of stdout\n" "\n" + "-d --debug-output Creates a parser that dumps information during\n" + " about the current position and in which state the\n" + " parser is.\n" + "\n" "-v --version Show version information.\n" "-V --vernum Show version as one number.\n" ; @@ -106,6 +112,10 @@ int main(int argc, char *argv[]) sFlag = true; break; + case 'd': + dFlag = true; + break; + case 'f': vFillIndexes = 0; break; diff --git a/re2c.1.in b/re2c.1.in index fd9a552f..df27847e 100644 --- a/re2c.1.in +++ b/re2c.1.in @@ -7,6 +7,9 @@ .ds rx regular expression .ds lx \fIl\fP-expression \"$Log$ +\"Revision 1.14 2005/04/22 22:03:08 helly +\"- Added -d flag which outputs a debugable parser. +\" \"Revision 1.13 2005/04/22 21:50:33 helly \"- Update date \" @@ -56,7 +59,7 @@ re2c \- convert regular expressions to C/C++ .SH SYNOPSIS -\*(re [\fB-efsbvh\fP] [\fB-o output\fP] file\fP +\*(re [\fB-efsbvhd\fP] [\fB-o output\fP] file\fP .SH DESCRIPTION \*(re is a preprocessor that generates C-based recognizers from regular @@ -156,6 +159,11 @@ Implies \fB-s\fP. Use bit vectors as well in the attempt to coax better code out of the compiler. Most useful for specifications with more than a few keywords (e.g. for most programming languages). .TP +\fB-d\fP +Creates a parser that dumps information about the current position and in +which state the parser is while parsing the input. This is useful to debug +parser issues and states. +.TP \fB-h\fP \fB-?\fP Invoke a short help.