parse.y (was Ripper and 1.8)

J

Jonathan Maasland

Hi all,

I've been poking around Ripper for the last couple a days and during
that process I started to look at parse.y as it's currently in CVS (Ruby
1.9 that is).
I'm not very knowledgeable about yacc and parsers in general but I just
wanted to ask a quick question.

In parse.y I see alot of /*%%%*/ and /*% --code-- %*/"constructs" for
example:
-----
primary : literal
| strings
| xstring
| regexp
| words
| qwords
| var_ref
| backref
| tFID
{
/*%%%*/
$$ = NEW_FCALL($1, 0);
/*%
$$ = method_arg(dispatch1(fcall, $1), arg_new());
%*/
}
-------

I've started reading the bison manual but I can't find any reference to
this construct.
My question: Are these lines just comments or are they instructing bison?

Again, any help is greatly appreciated.

With kind regards,
Jonathan
 
T

ts

J> In parse.y I see alot of /*%%%*/ and /*% --code-- %*/"constructs" for

Look at the file

ruby/ext/ripper/tools/preproc.rb


Guy Decoux
 
R

Robin Stocker

Jonathan said:
/*%%%*/
$$ = NEW_FCALL($1, 0);
/*%
$$ = method_arg(dispatch1(fcall, $1), arg_new());
%*/

It's a construct needed for Ripper.

For Bison, the code of the first line is normal code, the second is
comment. So the relevant part for Bison is:

$$ = NEW_FCALL($1, 0);

In Ripper, there needs to be different code, so a script preprocesses
the whole parse.y, removes the text from /*%%% to /*% and removes the
%*/, so the second code line is relevant:

$$ = method_arg(dispatch1(fcall, $1), arg_new());

Have a look at ext/ripper/tools/preproc.rb to see how the preprocessing
works in detail.

Robin Stocker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top