[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Getting involved in Bison
From: |
Akim Demaille |
Subject: |
Re: Getting involved in Bison |
Date: |
Mon, 13 Apr 2020 18:20:27 +0200 |
[Restricted to bison-patches only]
Hi Victor!
Good to hear from you!
> Le 13 avr. 2020 à 12:54, Morales Cayuela, Victor (NSB - CN/Hangzhou)
> <address@hidden> a écrit :
>
> Hello!
>
> First of all, I hope that all you and your relatives/friends are healthy,
> this coronavirus is wreaking havoc.
As far as I'm concerned, everybody around me is safe. Best of luck to
everybody!
> I have started working on the push parser in C++. Since I feel a bit
> unconfident about how it should be done, I would like you to double-check
> first if all this is going the correct direction.
Sure!
> I have just added a few things to transform it slowly from C to C++.
I don't think this is the easiest path. It is good that you have a look at how
push parsers are implemented in C, but do not try to morph the C push parsers
into C++. Rather, once you understood what needs to be done, do it directly in
lalr1.cc. Do not start a nice skeleton, just enhance the current one to
support push parsers.
I strongly recommend that you start from examples/c++/calc++, or whatever
example you like, but in C++, using lalr1.cc. Do not start with something
generated by yacc.c.
I also recommend that you use git to follow your experiments. You could do
that in your Bison repo for instance.
The path should be roughly:
- find what are the local variables of yyparse that should become member of the
parser object
- do it in your C++ parser. In C++ we don't need an equivalent for yypstate,
because we already have it: that the parser object itself.
- have your pull-parser (i.e., the good old yy::parser::parse()) work properly
this way. Run tests. That's one of the reason I suggest using
examples/c++/calc++ as a starting point: it already has tests, you can add more.
That was step 1.
- when this is done, look again at how push parsers are implemented in C to see
what needs to change in yyparse so that the control is inverted: parse() will
be *given* the tokens, instead of having to call yylex itself. When I say
"look at C", I think your best option are (i) yacc.c (look for b4_push_if) and
(ii) examples/c/bistromathic which is a push parser.
- rename parse() as push_parse(symbol_type yyla) that takes the symbol as
argument. That's the push parser we are looking for.
- define a new parse() function which has the same signature as the usual
pull-parser, that repeatedly calls the push_parse function. Something like
this:
int parse ()
{
int status = 0;
do {
status = this->push_parse (yylex());
} while (status == YYPUSH_MORE);
return status;
}
That's the end of step 2.
When we agree on step 2, step 3 will start: implement these changes in
lalr1.cc. I will help on this.
> I have added namespace::yy and wrapped the public functions in a class. I
> substituted "static const" for "constexpr. All that was easy and worked.
Using constexpr in lalr1.cc would be nice, independently of push-parsers, but
make sure to use #defines to be portable and fall back to static const for
older versions of C++.
Also, please, make sure to start from the latest version of master. There were
quite a few changes in C++ too. You shall find it easier than before.
Cheers!
PS/ Please, send unified diffs (diff -u), not contextual ones. And always
"old new", not "new old": old is the part with - line, new that with + lines.