Composition of Languages Embedded in Scala
Seyed Hossein Haeri, Paul Keir · Annals of Computer Science and Information Systems · 2019
Composition is amongst the major challenges faced in language engineering.Erdweg et al. offered a taxonomy for language composition.Mernik catalogued the use of the Language Definitional Framework LISA for composition sorts in that taxonomy.We produce a similar catalogue for embedded language engineering in Scala.We begin with techniques that are not specific to Scala.They are applicable in any host language with a module system and support for higher order functions.We, then, present two more techniques to examine Scala-specific language engineering.Interestingly enough, even though dealing with embedded languages, in terms of lines of code, our material is of comparable length to its LISA counterpart.Our work lends insight into Scala's serviceability for composition, as a host for embedded language engineering. 1 object syntax {//robot 2 class Command 3 case object Left extends Command 4 case object Right extends Command 5 case object Up extends Command 6 case object Down extends Command 7 case class Commands(s: Seq[Command])} 8 object semantics {import syntax._//robot9 class Position(var x: Int, var y: Int) 10 object position extends Position(0, 0) 11 def locate: Command => Unit = { 12 case Left => position.x-= 1 13 case Right => position.x+= 1 14 case Up => position.y+= 1 15 case Down => position.y-= 1} 16 def locate(cs: Commands) = cs.s.foreach(locate) 17 } Robot is extended to RobotTime (the robot_time package) by adding to the semantics, i.e., Robot ⊳ RobotTime: 1 package robot_time 2