Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started