4
votes

I know that it's possible to use, for example, bison-generated Java files in scala project, but is there any native "grammar to scala" LALR(1) generators?

2
Does anyone actually read generated LALR parser code? I haven't seen anything like this, and am not sure there'd be much of a market for it, given that there are mature Java solutions and the generated Scala would probably be just as inscrutable.Travis Brown
@TravisBrown advantage here is not to read java code, but ability to write semantic actions in Scala.John Rivers
But with a little bit of wrapping it should be possible to do that with a Bison-generated Java parser.Travis Brown
@TravisBrown it is OK for me (if this wrapping doesn't mean using external Scala file), but can you give an example of such wrapping?John Rivers

2 Answers

1
votes

Another plug here: ScalaBison is close to LALR(1) and lets you use Scala in the actions.

0
votes

I'm not really answering the original question, and please excuse the plug, but you may be interested in our sbt-rats plugin for the sbt tool. It uses the Rats! parser generator for Java, but makes it easier to use from Scala.

Rats! uses parsing expression grammars as its syntax description formalism, not context-free grammars and definitely not LALR(1) grammars. sbt-rats also has a high-level syntax definition language that in most cases means you do not need to write semantic actions to get a syntax tree that represents your input. The plugin will optionally generate case classes for the tree representation and a pretty-printer for the tree structure.