Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED THESE Code in python or c++ A group of architects have devised a domain-specific language for describing buildings with multiple floors where each

I NEED THESE Code in python or c++ A group of architects have devised a domain-specific language for describing buildings with multiple floors where each floor has one or more rooms. They have asked you to build a system which reads plans for complexes (one or more buildings) and displays the total area and the area for each building. The grammar the use is described as follows, where non-terminals are capitalized and terminals are between quotes: 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. 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. If the input file has a syntax error, display a message indicating which token is missing; for example, if the input has four lines of floors (and no complex keyword), you would display Syntax error in plan: no more tokens, but expected complex and terminate without computing the area. Similarly for other syntax errors such as missing "with" after a building name, not having commas between floor names, etc. For example, missing a '{' after a floors keyword (and having "CAFETERIA" in the same place) would result in the message Syntax error in plan: Expected {, received CAFETERIA The other errors you must catch are references to unknown floor names. For example: floor X has rooms [5 by 5] complex building Y with floors {BAD} In this case, the error message would be Reference to missing floor BAD Again, followed by terminating the program without printing any information. In general, the specifics of the error messages are up to you other than having to match the output in esubmit.

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

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

Discuss the importance of workforce planning.

Answered: 1 week ago

Question

Differentiate between a mission statement and a vision statement.

Answered: 1 week ago