From d18b0db7a28adf53e0debf85b26c49019b8626d0 Mon Sep 17 00:00:00 2001 From: helly Date: Sun, 25 Feb 2007 16:48:19 +0000 Subject: [PATCH] - Added implace configuration 're2c:yyfill:parameter'. --- re2c/CHANGELOG | 3 +- re2c/code.cc | 13 ++- re2c/globals.h | 1 + re2c/htdocs/manual.html | 6 +- re2c/main.cc | 7 +- re2c/re2c.1.in | 6 ++ re2c/test/config10.c | 190 ++++++++++++++++++++++++++++++++++++++++ re2c/test/config10.re | 82 +++++++++++++++++ 8 files changed, 301 insertions(+), 7 deletions(-) create mode 100755 re2c/test/config10.c create mode 100755 re2c/test/config10.re diff --git a/re2c/CHANGELOG b/re2c/CHANGELOG index 8f73b3f9..2ec11ba7 100644 --- a/re2c/CHANGELOG +++ b/re2c/CHANGELOG @@ -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. diff --git a/re2c/code.cc b/re2c/code.cc index 5640ff05..d47d1c6b 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -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; diff --git a/re2c/globals.h b/re2c/globals.h index f974a936..d38dffff 100644 --- a/re2c/globals.h +++ b/re2c/globals.h @@ -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]; diff --git a/re2c/htdocs/manual.html b/re2c/htdocs/manual.html index 97877910..e6fac74b 100755 --- a/re2c/htdocs/manual.html +++ b/re2c/htdocs/manual.html @@ -360,6 +360,11 @@ will be generated.
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.
+
re2c:yyfill:parameter = 1 ;
+
Allows to suppress parameter passing to YYFILL calls. If set to zero +then no parameter is passed to YYFILL. If set to a non zero value then +YYFILL usage will be followed by the number of requested characters in +braces.
re2c:startlabel = 0 ;
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.
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. -.TP
re2c:yych:conversion = 0 ;
When the input uses signed characters and -s or -b switches are in effect re2c allows to automatically convert to the unsigned character type diff --git a/re2c/main.cc b/re2c/main.cc index 3118b923..a425fb0f 100644 --- a/re2c/main.cc +++ b/re2c/main.cc @@ -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"); diff --git a/re2c/re2c.1.in b/re2c/re2c.1.in index 0b5bf4f7..a718ef3a 100644 --- a/re2c/re2c.1.in +++ b/re2c/re2c.1.in @@ -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 index 00000000..a1226e54 --- /dev/null +++ b/re2c/test/config10.c @@ -0,0 +1,190 @@ +/* Generated by re2c */ +#line 1 "config10.re" +#include +#include + +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 "" +{ + 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 "" +xx4: + ++s.cur; + curr = *s.cur; + goto xx11; +xx5: +#line 57 "config10.re" + { return NUMBER; } +#line 99 "" +xx6: + ++s.cur; +xx7: +#line 60 "config10.re" + { + if(s.cur == s.lim) + return EOI; + cursor = s.cur; + goto std; + } +#line 110 "" +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 "" +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 "" +} +#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 index 00000000..3c3fafcb --- /dev/null +++ b/re2c/test/config10.re @@ -0,0 +1,82 @@ +#include +#include + +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; + } +} -- 2.40.0