Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #1654 > unrolled thread
| Started by | Jens Kallup <jkallup@web.de> |
|---|---|
| First post | 2015-12-22 16:29 +0100 |
| Last post | 2015-12-27 10:59 -0500 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.compilers
stop yyparse() at <<EOF>> Jens Kallup <jkallup@web.de> - 2015-12-22 16:29 +0100
Re: stop yyparse() at <<EOF>> Kaz Kylheku <kaz@kylheku.com> - 2015-12-27 10:59 -0500
| From | Jens Kallup <jkallup@web.de> |
|---|---|
| Date | 2015-12-22 16:29 +0100 |
| Subject | stop yyparse() at <<EOF>> |
| Message-ID | <15-12-007@comp.compilers> |
Hello,
I work on multiple parser's in a GUI. When I start 1st, the code
generation is fine. But, when I start 2nd start, the code generator
produce some junk. I have used "yyterminate();" but this seems to not
help.
The source:
? "Ploppers" + "ppp" + "huhu"
The pre-processed text file:
#output asm, cli
? "Ploppers" + "ppp" + "huhu"
The first pass (flex):
1: "Ploppers"
plus
2: "ppp"
plus
2: "huhu"
The second pass:
#output asm, cli? 2: "Ploppers"
plus
2: "ppp"
plus
2: "huhu"
Segmentation fault
\#"output cpp" { outype = 0; return _CPP_PARSER_; }
\#"output asm" { outype = 1; return _ASM_PARSER_; }
\#"output asm, cli" { outype = 1; return _ASM_PARSER_; }
(\"([a-zA-Z0-9_])*\")* {
printf("1: %s\n",yytext); strcpy(yytext,"");
BEGIN(STRINGER);
strcpy(yytext,"");
}
<STRINGER>{
(\"([a-zA-Z0-9_])*\")* { printf("2: %s\n",yytext);
strcpy(yytext,""); BEGIN(STRINGER); strcpy(yytext,"");
}
\+ { printf("plus\n"); BEGIN(STRINGER); }
\n
}
I would like use it in gnu "bison" so:
string_expr
: _STRING_ { printf("---> %s\n",yylval.text); }
;
Is that a Bug, or my mistakes?
TIA
Jens
[toc] | [next] | [standalone]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Date | 2015-12-27 10:59 -0500 |
| Message-ID | <15-12-008@comp.compilers> |
| In reply to | #1654 |
On 2015-12-22, Jens Kallup <jkallup@web.de> wrote:
> (\"([a-zA-Z0-9_])*\")* {
> printf("1: %s\n",yytext); strcpy(yytext,"");
> BEGIN(STRINGER);
> strcpy(yytext,"");
[ snip ]
>
> Is that a Bug, or my mistakes?
Not saying this is the crash, but do not modify yytext; it is (or may
be) a pointer directly into the lexical analyzer's buffer, and not a
copy.
You might be confusing the flex scanner somehow by putting a null in
there.
> string_expr
> : _STRING_ { printf("---> %s\n",yylval.text); }
> ;
You haven't shown any lexer code which sets up yylval.text and returns
the _STRING_ token.
The lex rules you have surrounding your STRINGER state don't return
anything.
[Good points. In recent versoins of flex, yytext points into the
input buffer and chaning what it points to is asking for trouble.
If you need to change it, make a copy.
Also, there's no BEGIN(INITIAL) to reset the start states. -John]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.compilers
csiph-web