]> granicus.if.org Git - re2c/commitdiff
- Added -d flag which outputs a debugable parser.
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Fri, 22 Apr 2005 22:03:08 +0000 (22:03 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Fri, 22 Apr 2005 22:03:08 +0000 (22:03 +0000)
CHANGELOG
code.cc
globals.h
main.cc
re2c.1.in

index f224b770367426d9d00867592232c82351ce6584..c1095b955c7e68e401eecdb4da1d8176d012863a 100644 (file)
--- 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 897551c0c9356325f30b29234abed444b8f5d06f..1d6072a2d3079e04d28c7a43d419f61a392ecf31 100644 (file)
--- 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);
 }
 
index 240ba7d2e0fd00f6307f09bbcfcb85cdc792beef..b868b1b7920d0cbb799513e14b34a915b60a66df 100644 (file)
--- 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 90c9694f4075923ae31431396614bd8535c865be..142c90fb1de5f587a463164b448a1446d849671a 100644 (file)
--- 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;
index fd9a552f6fe44e825dfc4f0aa662ca8073df82be..df27847ee54d4cd3dc02edea3719dc6b0bf5629c 100644 (file)
--- 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.