Consider this straight line programming language without any support for loops or conditional statements. A typical...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider this straight line programming language without any support for loops or conditional statements. A typical straight line program consists of several sentences separated by semicolon (;). Three different kinds of sen- tences are supported: 1. Variable definitions: using keyword var we can define a variable, for example: var abc defines a variable with name abc. Only letters a...z and A... Z are allowed in variable names. 2. Assignments: using symbol := we can assign value of some expres- sion to a variable. Left hand side of this symbol is always a variable name and right hand side is always an expression. An expression is composition of variable names and natural numbers using arithmetic operations +,-, * and /. A single natural number or a single variable name is also an expression. Some samples: abc = -23 a: 2 v = 12 * v/abc- 4 v := uvy 3. Output statements: using keyword print we can print a variable value to the output. For example: print abc prints the value of variable abc to the output. The language is case sensitive and the only allowed characters are +, -, *, /, , , , a,... z, A,... Z, 0...9. Note that a program is valid if and only if it conforms to the previous defined rules for this language. Be careful not to add any rules by your intuition, for example we never required a variable name to be declared by the keyword var before being used, so for example this is a valid program: abc : =5; var Acd ; Acd=abc * 6* pqr; print fg Checking those kind of restrictions that are usually needed for serious programming languages requires more machinery. Design a context free grammar for this language (that is, construct a grammar G such that L(G) is the set of all valid programs in this language.) Do not worry about spaces or newlines for this grammar, you may assume keywords such as var and print are not variable names. PS5, Page 3 1. Define the rules digits (0 through 9), letters (lower case and up- percase alphabet), and operations op (-, +, * , /). 2. Define the rule for variable names varName using the definition letters (Note this is not variable declaration.) 3. Define the rule for numbers number using digits. 4. Define the rule for variable declaration varDec using varName. 5. Define the rule for expressions expression using op, number, and varName (remember an expression can just be a number or variable). 6. Define the rule for print statements print using varName 7. Define the rule for expressions assignment using varName and expression. 8. Define the rule for sentences sentence using varDec, assignment, and print. 9. Define the rule for programs prog using sentence. Consider this straight line programming language without any support for loops or conditional statements. A typical straight line program consists of several sentences separated by semicolon (;). Three different kinds of sen- tences are supported: 1. Variable definitions: using keyword var we can define a variable, for example: var abc defines a variable with name abc. Only letters a...z and A... Z are allowed in variable names. 2. Assignments: using symbol := we can assign value of some expres- sion to a variable. Left hand side of this symbol is always a variable name and right hand side is always an expression. An expression is composition of variable names and natural numbers using arithmetic operations +,-, * and /. A single natural number or a single variable name is also an expression. Some samples: abc = -23 a: 2 v = 12 * v/abc- 4 v := uvy 3. Output statements: using keyword print we can print a variable value to the output. For example: print abc prints the value of variable abc to the output. The language is case sensitive and the only allowed characters are +, -, *, /, , , , a,... z, A,... Z, 0...9. Note that a program is valid if and only if it conforms to the previous defined rules for this language. Be careful not to add any rules by your intuition, for example we never required a variable name to be declared by the keyword var before being used, so for example this is a valid program: abc : =5; var Acd ; Acd=abc * 6* pqr; print fg Checking those kind of restrictions that are usually needed for serious programming languages requires more machinery. Design a context free grammar for this language (that is, construct a grammar G such that L(G) is the set of all valid programs in this language.) Do not worry about spaces or newlines for this grammar, you may assume keywords such as var and print are not variable names. PS5, Page 3 1. Define the rules digits (0 through 9), letters (lower case and up- percase alphabet), and operations op (-, +, * , /). 2. Define the rule for variable names varName using the definition letters (Note this is not variable declaration.) 3. Define the rule for numbers number using digits. 4. Define the rule for variable declaration varDec using varName. 5. Define the rule for expressions expression using op, number, and varName (remember an expression can just be a number or variable). 6. Define the rule for print statements print using varName 7. Define the rule for expressions assignment using varName and expression. 8. Define the rule for sentences sentence using varDec, assignment, and print. 9. Define the rule for programs prog using sentence.
Expert Answer:
Answer rating: 100% (QA)
For the given straightline programming languages we are defining a contextfree grammerCFG 1Define the rules for digits 0 through 9 letters lower case ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Select the necessary words from the list of possibilities to complete the following statements. Statements 1. The of SEC registrants selects the company's audit firm. 2. The auditors must assess the...
-
Glenn was recently promoted to be the manager of a new store being opened by a large department store chain. He wants to start out right by making sure that communications are always good between...
-
Evaluate the following integrals. dy (y + 1)(y + 2)
-
What are the different types of schemes associated with complex frauds?
-
Dorothy Koehl recently leased space in the Southside Mall and opened a new business, Koehl's Doll Shop. Business has been good, but Koehl has frequently run out of cash. This has necessitated late...
-
A trebuchet is a mighty siege engine capable of flinging 90-kg projectiles a distance of 300 meters. Assuming a perfect launch angle of 45, calculate the speed with which one of these projectiles...
-
Alice has invented a new card game to play with Bob. Alice made a deck of cards with random values between 1 and 52. Bob picks 5 cards. Then, he has to rearrange the cards so that by utilizing the...
-
Write a short paragraph on the article Ethics and Education
-
A 8.55 eV barrier of width 0.300 nm is in the path of an electron moving with a speed of 1.60 x 106 m/s. What are the chances the electron will penetrate the barrier? Determine the probability of...
-
A vacation resort has both an amusement park and water park facilities for families staying at the resort. The resort sells ticket plans to the families based on which type of park that they would...
-
Change the Pokemon class so that it can store images for Pokemon. First, add an instance variable to the Pokemon class to store an image. Then, add a new Constructor, still keeping the old one. This...
-
When rumors of potential outsourcing plans surface in an organization, what is the main area that managers and HR should focus on? productivity losses since employees, not knowing what to expect,...
-
APPLY THE CONCEPTS: Prepare a contribution margin income statement Assume that you are part of the accounting team for Martin Computing. The company has only one product that sells for $20 per unit....
-
You overheard two students discussing after a class on the difference between the financial statements of limited liability companies and sole traders. Below is what each student said: Student 1:...
-
An access route is being constructed across a field (Figure Q8). Apart from a relatively firm strip of ground alongside the field's longer side AB, the ground is generally marshy. The route can...
-
A gourmet coffee shop in downtown San Francisco is open 200 days a year and sells an average of 75 pounds of Kona coffee beans a day. (Demand can be assumed to be distributed normally with a standard...
-
If a plant has an effective capacity of 6,500 and an efficiency of 88%, what is the actual (planned) output?
-
Kenneth Boyer is considering opening a bicycle shop in North Chicago. Boyer enjoys biking, but this is to be a business endeavor from which he expects to make a living. He can open a small shop, a...
-
a. Show that the mean-squared forecast error \(E\left[\left(\hat{y}_{T+1}-y_{T+1} ight)^{2} \mid I_{T} ight]\) for a forecast \(\hat{y}_{T+1}\), that depends only on past information \(I_{T}\), can...
-
Consider the AR(1) model \(y_{t}=\delta+\theta y_{t-1}+e_{t}\) where \(|\theta|)=0\) and \(\operatorname{var}\left(e_{t} \mid I_{t-1} ight)=\sigma^{2}\). Let \(\bar{y}_{-1}=\sum_{t=2}^{T} y_{t}...
-
Consider a stationary model that combines the \(\operatorname{AR}(2)\) model \(y_{t}=\delta+\theta_{1} y_{t-1}+\theta_{2} y_{t-2}+e_{t}\) with an \(\mathrm{AR}(1)\) error model \(e_{t}=ho...
Study smarter with the SolutionInn App