Question: I need this python code Plans -> (Floor)+ Complex Floor -> 'floor' Name 'has' ('rooms'|'room') RoomList Complex -> 'complex' (Building)+ Building -> 'building' Name 'with'

I need this python code Plans -> (Floor)+ Complex Floor -> 'floor' Name 'has' ('rooms'|'room') RoomList Complex -> 'complex' (Building)+ Building -> 'building' Name 'with' ('floors'|'floor') FloorList FloorList -> '{' FloorReference (',' FloorReference)* '}' FloorReference -> Name RoomList -> '[' Room (',' Room)* ']' Room -> Number 'by' Number Name -> [A-Z_]+ Number -> [0-9]+ For example, a sample complex is floor DINING has rooms [80 by 40, 10 by 20, 10 by 20] floor CUBICALS has rooms [20 by 20, 20 by 20, 20 by 20, 20 by 20] floor GRAND_OFFICE has rooms [40 by 30, 20 by 20, 15 by 15, 30 by 30] floor HALL has room [500 by 500] complex building A with floors {DINING, CUBICALS, CUBICALS} building B with floors {DINING, GRAND_OFFICE} building C with floor {DINING, HALL} Note the indentation and use of whitespace is immaterial. A simple way to break this input into tokens is to use string substitution to put spaces around commas, brackets, and braces (for example, convert "," to " , "), then use the PYTHON string split operation to split on whitespace. You could also use regular expressions with split operations to break the input into tokens.

from btl_syntax import * def eval(expr: Expr) -> int: if type(expr) == True: return 1 elif type(expr) == False: return 0 elif type(expr) == Zero: return 0 elif type(expr) == Succ: return eval(expr.subexpr) + 1 elif type(expr) == Pred: result = eval(expr.subexpr) - 1 if result < 0: result = 0 return result elif type(expr) == IsZero: if eval(expr.subexpr) == 0: return 1 else: return 0 elif type(expr) == If: if eval(expr.test) != 0: return eval(expr.truepart) else: return eval(expr.falsepart) else: raise RuntimeError("Illegal expression: " + str(expr)) 
import math num = int(input("Enter number: ")) fact = math.prod(range(1, num + 1)) print("Factorial: " + str(fact)) 
from btl_syntax import * # using all of the module on purpose import btl_interpreter def test_constructor(): sample = Pred(If(IsZero(Zero()), Succ(Succ(Zero())), Zero())) assert(sample.to_string() == "Pred(If(IsZero(Zero), Succ(Succ(Zero)), Zero))") sample = If(IsZero(Zero()), Succ(Succ(Zero())), Zero()) assert(sample.to_string() == "If(IsZero(Zero), Succ(Succ(Zero)), Zero)") def test_number_interpretation(): x = Succ(Succ(Succ(Zero()))) assert(btl_interpreter.eval(x) == 3) x = Pred(Succ(Succ(Zero()))) assert(btl_interpreter.eval(x) == 1) x = If(IsZero(Zero()), Succ(Succ(Zero())), Zero()) assert(btl_interpreter.eval(x) == 2) x = If(IsZero(Succ(Zero())), Succ(Succ(Zero())), Zero()) assert(btl_interpreter.eval(x) == 0) x = Pred(Pred(Zero())) assert(btl_interpreter.eval(x) == 0) test_constructor() test_number_interpretation() print("all tests pass") You are to write a recursive descent parser for this language and augment it with code to compute (and display) the total area of the complex. Assume all units are measurements in feet. For example, the program would print Area for building A: 6800 square feet. Area for building B: 6325 square feet. Area for building C: 253600 square feet. Total area: 266725 square feet. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!