Based on parsing expression grammars (PEGs). Part of eXTensible Compiler (xtc) project: http://cs.nyu.edu/rgrimm/xtc/ http://cs.nyu.edu/rgrimm/xtc/rats-intro.html Particular focus on modularity and extensibility of grammars.
with ordered choice. Ambiguity is avoided at the cost of having to be aware of the order of alternatives. Stm = "if" ’(’ Exp ’)’ Stm | "if" ’(’ Exp ’)’ Stm "else" Stm
repository. Add .rats specification to project. Plugin uses Rats! to generate a parser implemented in Java. Optional Scala-specific customisation: use Scala lists instead of Rats! pairs use Scala positions instead of Rats! locations use Scala options instead of null
abstract class Stm case class Decl (tipe : Tipe, loc : Loc) extends Stm case class EmptyStm () extends Stm case class AsgnStm (assign : Exp) extends Stm case class LabStm (lab : String, stm : Stm) extends Stm case class Break (lab : String) extends Stm case class Continue (lab : String) extends Stm case class If (exp : Exp, stm1 : Stm, stm2 : Stm) extends Stm case class While (exp : Exp, stm : Stm) extends Stm case class Block (optStms : List[Stm]) extends Stm
components in order of definition literals either get a space after them (when double quoted) or don’t (when single quoted) Directives to customise defaults: sp: space \n: possible newline nest(s): indent s relative to its parent
comments. Standard definition of identifiers. Automatic handling of keywords. Override or escape to Rats! specification if needed. Drawbacks: Currently only one syntax description per project. No direct support for modularity yet.