Reputation: 527
I am trying to write a parser for the Lilypond language of music notation in JavaScript. My first manual attempts work, but can only deal with a very small subset of the language. As Lilypond uses bison files to define its grammar[1] and JISON claims to be able to work from bison files, my idea was to perhaps use these definitions to generate a parser in JavaScript.
I cannot find any examples of this anywhere, and trying to feed these files directly into JISON just throws errors.
What would be the best way to approach this?
[1]: see https://github.com/lilypond/lilypond/blob/master/lily/lexer.ll and https://github.com/lilypond/lilypond/blob/master/lily/parser.yy),
Upvotes: 0
Views: 730
Reputation: 5525
The parser is relatively(!) easy: strip the C code (you should keep the AST construction at first to see how they did it), keep the precedences as they are (JISON understands the Bison syntax to some wide extend) and fill in the code to fill the AST. The Lexer is quite complicated in contrast and I don't know if all of the flex-specialities are supported by JISON but otherwise: go as described above for the parser part.
But it still will be a lot of work, that's for sure ;-)
EDIT: After some twiddling with Lilypond's grammar and searching the web for more information I stumbled over the following quote:
The LilyPond grammar does a lot of weird things…
By the Lilypond developer named "dakas" in https://lwn.net/Articles/561990/
I concur.
Upvotes: 1