No, not
Jison . A full-fledged generator javascript parsers with full support for the bison.
Let's start with the main question.
What for?
')
It became necessary to port a large syshny parser to JavaScript without losing small details of the original. Very lucky that the original parser is written in terms of yacc / bison, and not with your hands on hardcore C.
When it is time to port this parser, the first thing that came to mind is to google “javascript bison parser”. Of course, the very first result was Jison. Here is a joy, it was thought then. However, the very first experiment showed that Jison does not know how to do a large piece of work with intermediate states. These are such cabinets, when hit on which you have to execute a piece of your code, for example, to prompt the lexer in what context he is now. A brief correspondence
in the githaba project did not bring consolation. Instead, the author
responded very savvy dude . He wrote there, in my opinion, a whole book with a bunch of details! I had to re-read and understand three times: yes, alas, you have to pick the original bison.
Bison
I must say that the bison is very well designed. Instead of hard-coding some constructions inside the generator, the bison uses a template language with which it nicely decomposes the necessary variables and labels into the resulting parser. Each of the three languages ​​has its own pattern, called the skeleton. And everything would be fine, but the
GNU m4 template language is just awful there. Because of this anachronism, instead of quietly porting the skeleton for Java, I had to deal only with patterned garbage of the day.
lalr1.js
This is the name of the skeleton for javascript -
lalr1.js . They are all
brothers lalry there :)
The result was very personal. We take some grammar.y in one hand, lalr1.js - in another, and bang:
bison -S ./lalr1.js grammar.y
we get grammar.js, which, after sticking the lexer to it, can even parse something.
Oh yes. It is important not to forget to replace all C code in this very grammar.y with javascript. Well, lecturer gash. Well, and still potestit well, comparing the logs of the parser C and the parser in javascript.
Epilogue
As usual, everything was done because it was creepy as interesting. But at the same time managed to bring the result to the beta. If there are people among you who are interested in generating javascript parsers (well, there for a cofescript, or directly at once javascript), then I will be very glad to help with running it all in. You can play by taking the source from
github.com/bison-lalr1.js and setting yourself bison and v8 / d8.
Two weeks later (06/28/2013) : The parser still does its job well with a hefty gammatics intertwined with a complex lexer. Only 10 times slower than sishnogo parser. Looks like you can release soon :)