Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SCALA Continued Fraction Grammar . We will define continued fractions inductively by the grammar: OneByNumber() | NumPlusContFrac(, ) Here represents the Scala integer number type

SCALA

Continued Fraction Grammar. We will define continued fractions inductively by the grammar:

OneByNumber()

| NumPlusContFrac(, )

Here represents the Scala integer number type (positive/negative whole numbers).

Example 1:

The number g1 = 1/5 will be represented in our grammar by OneByNumber(5).

Example 2:

The number

g2= 12 + 13 + 14

will be represented in our grammar by

NumPlusContFrac(2,NumPlusContFrac(3,OneByNumber(4)))

(10 points) Write down an inductive definition of the grammar above in Scala. Use the same names for terminals/nonterminals as in the grammar. Map the nonterminal to the built-in type in Scala.

Your program should pass the following tests:

val g1 = NumPlusContFrac(2,NumPlusContFrac(3,NumPlusContFrac(4,OneByNumber(5))))

val g2 = OneByNumber(2)

val g3 = NumPlusContFrac(3, NumPlusContFrac(-1, OneByNumber(4)))

val g4 = NumPlusContFrac(1, OneByNumber(-2))

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

Step: 3

blur-text-image

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions