]> granicus.if.org Git - re2c/commitdiff
- Added implace configuration 're2c:yyfill:parameter'.
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 25 Feb 2007 16:48:19 +0000 (16:48 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 25 Feb 2007 16:48:19 +0000 (16:48 +0000)
re2c/CHANGELOG
re2c/code.cc
re2c/globals.h
re2c/htdocs/manual.html
re2c/main.cc
re2c/re2c.1.in
re2c/test/config10.c [new file with mode: 0755]
re2c/test/config10.re [new file with mode: 0755]

index 8f73b3f94d8e5e892c7d05b34365b162a3deb7f6..2ec11ba7b14f88462784b83337432d5e4f7959f9 100644 (file)
@@ -1,6 +1,7 @@
 Version 0.11.2 (????-??-??)
 ---------------------------
-- Add inplace configuration 're2c:yych:conversion'.
+- Added inplace configuration 're2c:yyfill:parameter'.
+- Added inplace configuration 're2c:yych:conversion'.
 - Fixed -u switch code generation.
 - Added ability to avoid defines and overwrite variable and label names.
 
index 5640ff05f2b4db54f7feb7adc30e3e0b30e1a637..d47d1c6b7c791a9d6926abfd5aa23df3ea626aba 100644 (file)
@@ -327,12 +327,17 @@ static void need(std::ostream &o, uint ind, uint n, bool & readCh, bool bSetMark
        {
                if (n == 1)
                {
-                       o << indent(ind) << "if(" << mapCodeName["YYLIMIT"] << " == " << mapCodeName["YYCURSOR"] << ") " << mapCodeName["YYFILL"] << "(1);\n";
+                       o << indent(ind) << "if(" << mapCodeName["YYLIMIT"] << " == " << mapCodeName["YYCURSOR"] << ") " << mapCodeName["YYFILL"];
                }
                else
                {
-                       o << indent(ind) << "if((" << mapCodeName["YYLIMIT"] << " - " << mapCodeName["YYCURSOR"] << ") < " << n << ") " << mapCodeName["YYFILL"] << "(" << n << ");\n";
+                       o << indent(ind) << "if((" << mapCodeName["YYLIMIT"] << " - " << mapCodeName["YYCURSOR"] << ") < " << n << ") " << mapCodeName["YYFILL"];
                }
+               if (bUseYYFillParam)
+               {
+                       o << "(" << n << ")";
+               }
+               o << ";\n";
        }
 
        if (fFlag)
@@ -1687,6 +1692,10 @@ void Scanner::config(const Str& cfg, int num)
        {
                bUseYYFill = num != 0;
        }
+       else if (cfg.to_string() == "yyfill:parameter")
+       {
+               bUseYYFillParam = num != 0;
+       }
        else if (cfg.to_string() == "cgoto:threshold")
        {
                cGotoThreshold = num;
index f974a9360e628c94ec91cf099af45c9092dd7928..d38dffffca51e02eccfc68d7f52187df4d8a7016 100644 (file)
@@ -49,6 +49,7 @@ extern bool bUseStateAbort;
 extern bool bUseStateNext;
 extern bool bWroteGetState;
 extern bool bUseYYFill;
+extern bool bUseYYFillParam;
 
 extern uint asc2ebc[256];
 extern uint ebc2asc[256];
index 978779109c365d513bee5fcc3913362fcc706ec7..e6fac74bbdd38ddc1ab33ad7387fa06575fbcbcf 100755 (executable)
@@ -360,6 +360,11 @@ will be generated.</dd>
 <dd>Set this to zero to suppress generation of YYFILL(n). When using this be sure
 to verify that the generated scanner does not read behind input. Allowing
 this behavior might introduce sever security issues to you programs.</dd>
+<dt><i>re2c:yyfill:parameter</i> <b>=</b> 1 <b>;</b></dt>
+<dd>Allows to suppress parameter passing to <b>YYFILL</b> calls. If set to zero 
+then no parameter is passed to <b>YYFILL</b>. If set to a non zero value then
+<b>YYFILL</b> usage will be followed by the number of requested characters in
+braces.</dd>
 <dt><i>re2c:startlabel</i> <b>=</b> 0 <b>;</b></dt>
 <dd>If set to a non zero integer then the start label of the next scanner
 blocks will be generated even if not used by the scanner itself. Otherwise the
@@ -385,7 +390,6 @@ placing a "/*!getstate:re2c */" comment.</dd>
 generation of jump tables rather than using nested if's and decision bitfields.
 The threshold is compared against a calculated estimation of if-s needed where 
 every used bitmap divides the threshold by 2.</dd>
-.TP
 <dt><i>re2c:yych:conversion</i> <b>=</b> 0 <b>;</b></dt>
 <dd>When the input uses signed characters and <b>-s</b> or <b>-b</b> switches are
 in effect re2c allows to automatically convert to the unsigned character type
index 3118b9233967a07fc9c8d7bf83313955f6751a6d..a425fb0f2a2fb840577176a64d5874d8d5e29eaa 100644 (file)
@@ -39,9 +39,10 @@ bool bUsedYYAccept  = false;
 bool bUsedYYMaxFill = false;
 bool bUsedYYMarker  = true;
 
-bool bUseStartLabel= false;
-bool bUseStateNext = false;
-bool bUseYYFill    = true;
+bool bUseStartLabel  = false;
+bool bUseStateNext   = false;
+bool bUseYYFill      = true;
+bool bUseYYFillParam = true;
 
 std::string startLabelName;
 std::string labelPrefix("yy");
index 0b5bf4f7acd753672c3fa118d2272f21f3493df8..a718ef3a7d82b04fd1bdca469764817868e98ea2 100644 (file)
@@ -427,6 +427,12 @@ Set this to zero to suppress generation of YYFILL(n). When using this be sure
 to verify that the generated scanner does not read behind input. Allowing
 this behavior might introduce sever security issues to you programs.
 .TP
+\fIre2c:yyfill:parameter\fP \fB=\fP 1 \fB;\fP
+Allows to suppress parameter passing to \fBYYFILL\fP calls. If set to zero 
+then no parameter is passed to \fBYYFILL\fP. If set to a non zero value then
+\fBYYFILL\fP usage will be followed by the number of requested characters in
+braces.
+.TP
 \fIre2c:startlabel\fP \fB=\fP 0 \fB;\fP
 If set to a non zero integer then the start label of the next scanner blocks 
 will be generated even if not used by the scanner itself. Otherwise the normal 
diff --git a/re2c/test/config10.c b/re2c/test/config10.c
new file mode 100755 (executable)
index 0000000..a1226e5
--- /dev/null
@@ -0,0 +1,190 @@
+/* Generated by re2c */
+#line 1 "config10.re"
+#include <cstring>
+#include <iostream>
+
+struct Scanner
+{
+       Scanner(char *txt)
+               : cur(txt), lim(txt + strlen(txt))
+       {
+       }
+       
+       char    *cur;
+       char    *lim;
+       char    *ptr;
+       char    *ctx;
+       char    *tok;
+};
+
+enum What
+{
+       UNEXPECTED,
+       KEYWORD,
+       NUMBER,
+       EOI
+};
+
+char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" };
+
+void fill()
+{
+}
+
+int scan(Scanner &s)
+{
+       char *cursor = s.cur;
+
+       if(cursor == s.lim)
+               return EOI;
+       
+std:
+       s.tok = cursor;
+
+
+#line 46 "<stdout>"
+{
+       char curr;
+
+       if((s.lim - s.cur) < 3) fill();
+       curr = *s.cur;
+       switch(curr) {
+       case 0x09:
+       case ' ':       goto xx6;
+       case 0x0A:      goto xx8;
+       case '0':
+       case '1':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+       case '8':
+       case '9':       goto xx4;
+       case 'a':
+       case 'b':       goto xx2;
+       default:        goto xx9;
+       }
+xx2:
+       s.ctx = s.cur + 1;
+       ++s.cur;
+       switch((curr = *s.cur)) {
+       case '0':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+       case '8':
+       case '9':       goto xx12;
+       case '1':       goto xx15;
+       default:        goto xx3;
+       }
+xx3:
+#line 67 "config10.re"
+       {
+               return UNEXPECTED;
+       }
+#line 91 "<stdout>"
+xx4:
+       ++s.cur;
+       curr = *s.cur;
+       goto xx11;
+xx5:
+#line 57 "config10.re"
+       { return NUMBER;  }
+#line 99 "<stdout>"
+xx6:
+       ++s.cur;
+xx7:
+#line 60 "config10.re"
+       {
+               if(s.cur == s.lim)
+                       return EOI;
+               cursor = s.cur;
+               goto std;
+       }
+#line 110 "<stdout>"
+xx8:
+       curr = *++s.cur;
+       goto xx7;
+xx9:
+       curr = *++s.cur;
+       goto xx3;
+xx10:
+       ++s.cur;
+       if(s.lim == s.cur) fill();
+       curr = *s.cur;
+xx11:
+       switch(curr) {
+       case '0':
+       case '1':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+       case '8':
+       case '9':       goto xx10;
+       default:        goto xx5;
+       }
+xx12:
+       ++s.cur;
+       if(s.lim == s.cur) fill();
+       curr = *s.cur;
+       switch(curr) {
+       case '0':
+       case '1':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+       case '8':
+       case '9':       goto xx12;
+       default:        goto xx14;
+       }
+xx14:
+       s.cur = s.ctx;
+#line 56 "config10.re"
+       { return KEYWORD; }
+#line 156 "<stdout>"
+xx15:
+       ++s.cur;
+       switch((curr = *s.cur)) {
+       case '0':
+       case '1':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+       case '8':
+       case '9':       goto xx12;
+       default:        goto xx16;
+       }
+xx16:
+       s.cur = s.ctx;
+#line 55 "config10.re"
+       { return KEYWORD; }
+#line 176 "<stdout>"
+}
+#line 70 "config10.re"
+
+}
+
+int main(int,char**)
+{
+       Scanner s("a77 a1 b8 b1");
+       
+       int t, n = 0;
+       while ((t = scan(s)) != EOI)
+       {
+               std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl;
+       }
+}
diff --git a/re2c/test/config10.re b/re2c/test/config10.re
new file mode 100755 (executable)
index 0000000..3c3fafc
--- /dev/null
@@ -0,0 +1,82 @@
+#include <cstring>
+#include <iostream>
+
+struct Scanner
+{
+       Scanner(char *txt)
+               : cur(txt), lim(txt + strlen(txt))
+       {
+       }
+       
+       char    *cur;
+       char    *lim;
+       char    *ptr;
+       char    *ctx;
+       char    *tok;
+};
+
+enum What
+{
+       UNEXPECTED,
+       KEYWORD,
+       NUMBER,
+       EOI
+};
+
+char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" };
+
+void fill()
+{
+}
+
+int scan(Scanner &s)
+{
+       char *cursor = s.cur;
+
+       if(cursor == s.lim)
+               return EOI;
+       
+std:
+       s.tok = cursor;
+
+/*!re2c
+
+re2c:define:YYCTYPE            = char;
+re2c:define:YYCURSOR   = s.cur;
+re2c:define:YYLIMIT            = s.lim;
+re2c:define:YYMARKER   = s.ptr;
+re2c:define:YYCTXMARKER        = s.ctx;
+re2c:define:YYFILL      = "fill()";
+
+re2c:yyfill:parameter   = 0;
+re2c:variable:yych      = curr;
+re2c:labelprefix        = xx;
+
+("a"|"b")/[1]    { return KEYWORD; }
+("a"|"b")/[0-9]+ { return KEYWORD; }
+[0-9]+           { return NUMBER;  }
+
+[ \t\n]
+       {
+               if(s.cur == s.lim)
+                       return EOI;
+               cursor = s.cur;
+               goto std;
+       }
+.
+       {
+               return UNEXPECTED;
+       }
+*/
+}
+
+int main(int,char**)
+{
+       Scanner s("a77 a1 b8 b1");
+       
+       int t, n = 0;
+       while ((t = scan(s)) != EOI)
+       {
+               std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl;
+       }
+}