Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write the syntax definitions of the following objects: (a) Natural number (1, 2, 3, ) (b) Unsigned integer (0, 1, 2, 3, ) (c)

1. Write the syntax definitions of the following objects: (a) Natural number (1, 2, 3, ) (b) Unsigned integer (0, 1, 2, 3, ) (c) Integer (, -2, -1, 0, 1, 2, ) (d) Odd number (, -3, -1, 1, 3, ) (e) Even number (, -4, -2, 0, 2, 4, ) (f) Integer divisible by 5 (, -10, -5, 0, 5, 10, ) Solve each problem from (a) to (f) using BNF, EBNF, syntax diagrams, and the parenthetic notation. At the end compare all solutions and write what is in your opinion the most suitable metalanguage for solving this type of problems.

2. Following is an example of input statement in C++ : cin >> sclr >> vec[2*i-1] >> mat[f(i,j)][j+k] >> t[i/3][j][k];

Note that subscripts can be expressions, including functions. Based on this example, write a BNF definition of the syntax of (all possible) input statements in C++. Do not in expand your definition beyond components shown in the above example.

3. Following is an example of output statement in C++:

cout << 12.34*a/rate << " " << 43.21 << " " << alpha + x[2*i-1] << " " << (p && q) << " " << pow(t[i][j], 1.2) << " string " << 's' << " " << myfun(x, sin(x+y), third_argument) ; Write a BNF definition of the syntax of C++ output statements. In all cases variables may have any number of indices and indices can be arbitrary arithmetic expressions. Therefore, this part of syntax definition is the same for problems 3 and 4. If you define an expression in problem 3, you can use it without redefining in problem 4 (which is just a list of expressions, expanded with strings and characters).

Theoretically, I/O statements can reach rather high level of complexity. It is not necessary that your solutions include options beyond those presented in the above examples (lists of objects and the use of expressions).

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

Students also viewed these Databases questions

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago