Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stop yyparse() at <<EOF>>

148 views
Skip to first unread message

Jens Kallup

unread,
Dec 22, 2015, 11:22:13 AM12/22/15
to
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

Kaz Kylheku

unread,
Dec 27, 2015, 10:59:51 AM12/27/15
to
On 2015-12-22, Jens Kallup <jka...@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]
0 new messages