Question: Build and validate a parser for the WML language within Scala. Your code should follow a pure functional programming style, and using Scala . All
Build and validate a parser for the WML language within Scala. Your code should follow a pure functional programming style, and using Scala. All data types must be immutable, and data may not be modified once assigned.
The goal is to be able to successfully parse the WML language, and presented as an explicit grammar in the accompanying grammar.txt file.
Below is the content of grammar.txt file:
TSTART = "{{" TEND = "}}" VSTART = "{{{" VEND = "}}}" DSTART = "{'" DEND = "'}" PIPE = "|" PIPES = "||" OUTERTEXT = anything, except for TSTART, or DSTART INNERITEXT = anything, except for TSTART, DSTART, VSTART, PIPE(s), TEND INNERDTEXT = anything, except for TSTART, DSTART, VSTART, PIPE(s), DEND BODYTEXT = anything, except TSTART, DSTART, VSTART, DEND VNAME = anything, except for PIPE(s), VEND
(a) For each of the non-constant tokens in the WML. grammar define a regular expression (Regex object) that would match it precisely at the start of a string. Bind your regular expressions to val's, named as per the token name, with a capital starting letter and all other letters lowercase Note that "anything" in some of the token descriptions includes whitespace (and newlines too!). Answer this question by providing a file qla.scala that contains only the requested val defini- tions (as something you could cut-and-paste into the REPL), without any outer wrappers. (b) Using Scala's RegexParsers framework, define a WMLParser. Define all tokens in the WML grammar, making use of your regular expressions from the above question. Provide a file qlb.scala with the class definition. (a) For each of the non-constant tokens in the WML. grammar define a regular expression (Regex object) that would match it precisely at the start of a string. Bind your regular expressions to val's, named as per the token name, with a capital starting letter and all other letters lowercase Note that "anything" in some of the token descriptions includes whitespace (and newlines too!). Answer this question by providing a file qla.scala that contains only the requested val defini- tions (as something you could cut-and-paste into the REPL), without any outer wrappers. (b) Using Scala's RegexParsers framework, define a WMLParser. Define all tokens in the WML grammar, making use of your regular expressions from the above question. Provide a file qlb.scala with the class definition
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
