Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build and validate a parser for the WML language within Scala. Your code should follow a pure functional programming style, and using Scala . All

image text in transcribedBuild 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

::= (OUTERTEXT | | )* ::= TSTART TEND ::= (PIPE ?)* ::= (INNERITEXT | | | )* ::= VSTART VNAME (PIPE )? VEND

::= DSTART PIPES DEND ::= (INNERDTEXT | | | )* ::= (PIPE )* ::= (INNERDTEXT | | | )+ ::= (BODYTEXT | | | )*

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions