Re: [Q]? Wrong $1 Value with Roskind grammer

Jim Roskind <jar@iapp201.mcom.com>
Fri, 28 Apr 1995 19:38:43 GMT

          From comp.compilers

Related articles
[Q]? Wrong $1 Value with Roskind grammer pbaechle@itr.ch (Patrick Baechler) (1995-04-18)
Re: [Q]? Wrong $1 Value with Roskind grammer jar@iapp201.mcom.com (Jim Roskind) (1995-04-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Jim Roskind <jar@iapp201.mcom.com>
Keywords: C++, parse
Organization: Compilers Central
References: 95-04-094
Date: Fri, 28 Apr 1995 19:38:43 GMT

First off, you should get the newer release of my distribution, dated
7/91, with file names like cpp5*. Alas it does not included templates
and exception handling, but it has several enhancements (not the least
of which is the inclusion of a good FLEX input file).


A quick glance at your problem suggests that you are having trouble
with your lexer, (assuming you haven't tried to simplify the
situation) you have problems with your lexer, as IDENTIFIER should
*never* return a YYTEXT of "=". My *guess* is that you have not
giving the *exact* example, and you are *probably* falling prey to a
common error. My guess is that the "printf ..." action was actually
put on some other reduction, and you are probably *not* bothering to
copy the "char* buffer" provided in YYTEXT when you do a reduction
(and instead are simply saving the pointer into the flex scanner
buffer). As a result, the underlying buffer in FLEX *can* change (once
a new lexeme is identified) and there is no guarantee that what used
to point to a "b" in the middle of a flex buffer will still have the
same value (i.e., the underlying flex buffer changes constantly). The
exact symptom is a little different than is common (I'd have expected
something like "IDENTIFIER = 'b ='") but it seems possible.


Alternatively, if you simplified the example and *actually* did a
"printf("...", YYTEXT)" rather than $1, that would perfectly explain
the problem, as YACC probably did a look-ahead lex at the indicated
point. This sort of occurrence is why it is good to move the YYTEXT
value into a safe-haven in the lexer, rather than waiting for the YACC
grammar to perform the motion.


... but IF you really did supply an exact example, then the easiest
way to debug is to turn on the verbose mode of the FLEX scanner, which
will cause it to print the type/name and value for each token as it is
identified. If the scanner is really identifying "=" as an
identifier, then either the reg-ex you provided is in error, or else
flex is misbuilt. Note that I supply a FLEX input file in the cpp5*
distribution, so that will give you a head start.


See the end of this message if you don't know where to get copies of
my distribution.


Jim


> Article 4950 of comp.compilers:
> Newsgroups: comp.compilers,comp.lang.c++
> From: Patrick Baechler <pbaechle@itr.ch>
> Subject: [Q]? Wrong $1 Value with Roskind grammer
> Keywords: C++, parse, question
> Organization: ITR (Interkantonales Technikum Rapperswil)
> Date: Tue, 18 Apr 1995 05:14:00 GMT
>
> I tried to get the IDENTIFIER names from a C/C++ File like follow ...
>
> main()
> {
> int a,b;
> a = 5;
> }
>
> .. so I put an action after the concerned reduction like this ...
>
> rescoped.identifier:
> IDENTIFIER { printf("IDENTIFIER = '%s'\n", $1); }
>
> | operator.function.name
>
> | class.rescoped.identifier
> ;
>
> .. after that the output looked like this ...
>
> IDENTIFIER = 'a'
> IDENTIFIER = 'b'
> IDENTIFIER = '='
>
> Please note: - the cutting is a part from the Roskind cpp4.y grammer.
> - I didn't want to get the names from all IDENTIFIER's,
> only the simple-ones like above.
> - the program is originated from cpp4.l (LEXFILE ROSKIND)
> cpp4.y (YACCFILE ROSKIND)
> - I had the same problem with: YACC/LEX, YACC/FLEX, BYACC/LEX
>


Doug Lea and Doug Schmidt have graciously offered to provide anonymous
ftp sites for the 8 files, as well as the Berkeley YACC source (if you
need it). I've also put up the files on my local site. In all cases,
log into ftp as "anonymous" and give your email address as your
password.


ics.uci.edu (128.195.1.1) in the ftp/gnu directory (even though
neither of the archives are FSF related) as:


                c++grammar2.0.tar.Z
                byacc1.8.tar.Z


mach1.npac.syr.edu (128.230.7.14) in the ftp/pub/C++ directory as:


                c++grammar2.0.tar.Z
                byacc1.8.tar.Z


ftp.infoseek.com (198.5.208.1) in the ftp/pub/c++grammar directory as:


                c++grammar2.0.tar.Z
                byacc1.8.tar.Z


or:


                c++grammar2.0.tar.gz
                byacc1.8.tar.gz




p.s., note the new email address




Jim Roskind voice: 415.528.2546
jar@netscape.com fax: 415.528.4133
----------------------------------------------------------------------------
PGP 2.6.2 Key fingerprint = 0E 2A B2 35 01 9B 5C 58 2D 52 05 9A 3D 9B 84 DB
To get my PGP 2.6 Public Key, "finger -l jar@infoseek.com | pgp -kaf"
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.