Question

In: Computer Science

1. For this question, assume a simple programming language (SPL) has been designed to write a...

1. For this question, assume a simple programming language (SPL) has been designed to write a straight-line program (SLP). Programs written in this simple programming language, such as the sample program P1 shown below, allow the implementation of only statements and expressions, but no loops or if-statements. Note the print function will take an expression list as its arguments.


       Program P1:
           a := 2 + 5; b := (print (a, a-1), 7 * a) ; print (b)
      

Execution of this program will yield output
                       7 6

49


a.) What is the grammar being used to specify the syntax of this language?

b.) What is a concrete syntax of the program? (Hint: parse tree)

Solutions

Expert Solution

As according to the question asked here, the answer can be divided into two main parts with two sub-parts. But before getting started lets recall some basic understanding first,

The output part of a program or generally programming language is structurized as

datatype variable_name = value or expression

Lets understand it better with Javascript as example in hand, as according to the syntax definition of JS

  • identifier variable_name "is equal to" the value to be assigned to the variable.

i.e let a = 5 or let a = 5+5 or let a = return [expression] (expression = operations on numbers or variables being used in the program)

As far as the concern about js,  the concrete syntax tree(CST) of the langauge can be understand by the given picture

  • Blue text — CST Tokens.
  • White text in blue blocks — CST Nodes (their structure is equal to an AST).
  • Blue lines — CST Structure.
  • Red lined — AST Links.

Source:- Github (https://raw.githubusercontent.com/cst/cst/master/docs/cst-example.png)

Explaination of CST:-

Where every element of the program contains body(that can be variable with value, function with several variables and values or expressions) as defined in the image. The CST of the language defines the set of rules which should be followed by the programmer in order to make the program run, if not followed the CST rules the program will not be able to run, as the compiler assigned to the language will not be able to recognise what the "Statement is meant for" hence will result in error or mis interpretation of the program"

For Example :- " Punctuator or Terminator in js( ; )" represents the end of line in JS, if not applied the compiler will not be able to recognise the line ending, and will result in error... (as per the previous formats of JS, not with ES6)

[*Note :- CST is the outline of the programming language in general terms ]

Explaination Of Grammar:-

  • "A grammar is a formal description of a language that can be used to recognize its structure."

In simple terms is a list of rules that define how each construct can be composed. For example, a rule for an for statement could specify that it must starts with the “for” keyword, followed by a left parenthesis, an expression(initialization;counter;condition), a right parenthesis and a statement under its block starting with { and ending with }

Answer Summar:- As per the concern about the answer to the question:-

BNF(Backus-Naur Form)

  • Notation technique for context free grammer (CFG)
  • specify the syntax of the language
  • <symbol>; = Expression 1/express2/eXPRESS3 , where <symbol> is non terminals & Expressions are sequence of symbols & this can be a combination of terminals as well as non terminals
  • Representing Grammer as S-> aBA B->bB/^ C->a/b

So, Answer to (A) The Grammer being used is Context Free Grammer(CFG) & the concrete syntax to the language will be definite or approximate to the image defined above.

i.e Program->Body->Expression(Value & Operation)->Loop->Identifier->Literal->Terminator


Related Solutions

Write a simple Calculator program using Scheme programming language. It should be able to do following...
Write a simple Calculator program using Scheme programming language. It should be able to do following operations: "+", "-", " * *, "/". the format when using the calculator function should be (calculator(operand1 operation operand2)) -> (calculator(2 + 5)) should give the output of 7.
Using C as the programming language, Write a concurrent connection-oriented server that can do something simple...
Using C as the programming language, Write a concurrent connection-oriented server that can do something simple for connected clients. It should be able to carry out such processing for the client as many times as the client wants until the client indicates it wishes to end the session. The server should support multiple clients (use telnet as the client in this task). Compile and run the server program. Try and connect to it from multiple other hosts using telnet as...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
In this question, you are asked to write a simple java program to understand natural language....
In this question, you are asked to write a simple java program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Robin came to Montreal, Canada in 2009. Assume a perfect user will follow the exactly above formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay...
1. To understand the value of records in a programming language, write a small program in...
1. To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen, junior, senior” etc.). Also, write the same program in the same language without using structs. Note: Code and with output screenshots
Assisted Instruction: Has to be in PERL SCRIPTING LANGUAGE with NO SUBROUTINES Programming Exercise: Write a...
Assisted Instruction: Has to be in PERL SCRIPTING LANGUAGE with NO SUBROUTINES Programming Exercise: Write a program in PERL with NO SUBROUTINES to allow the user to pick a type of arithmetic problem to study. An option of 1 means addition problems only, 2 means subtraction problems only, 3 means multiplication problems only, 4 means division problems only and 5 means random mixture of all these types. (Computer- Assisted Instruction) The use of computers in education is referred to as...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement for a salesperson at a rate of $0.35 per mile. Your program should interact (ask the user to enter the data) with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading > 13505.2 Enter ending odometer reading > 13810.6 You traveled 305.4 miles. At $0.35 per mile, your reimbursement is $106.89. ** Extra credit 6 points: Format the answer (2 points),...
GPA calculator in C language To understand the value of records in a programming language, write...
GPA calculator in C language To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,” etc.). Note:Code and Output Screenshots
**C programming language The following description has been adopted from Deitel & Deitel. One of the...
**C programming language The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the...
1. Assume that a simple random sample has been selected from a normally distributed population and...
1. Assume that a simple random sample has been selected from a normally distributed population and test the given claim. Identify the null and alternative​ hypotheses, test​ statistic, P-value, and state the final conclusion that addresses the original claim. A safety administration conducted crash tests of child booster seats for cars. Listed below are results from those​ tests, with the measurements given in hic​ (standard head injury condition​ units). The safety requirement is that the hic measurement should be less...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT