Question: (1) You can, with minor changes to syntax, take a program in C and compile it under C++ (there you have to add a namespace

(1) You can, with minor changes to syntax, take a program in C and compile it under C++ (there you have to add a "namespace using" statement, the names of the include files are different - there may be some other syntax differences depending on which versions of C and C++ you are using). Why do they still fall in different language classes (C++ is object-oriented, C is imperative)? Do you think that every object oriented language can be programmed in an imperative style? Can an imperative language like C be programmed in object-oriented style? (2) Consider a language that has INT, FLOAT and CHAR types; and in which you can declare multiple variables in a single statement, separating names by commas: INT A, B, C You can declare any name as a one-dimensional array: FLOAT A, B[40] You may use non-terminals {D,VL,TY} - declaration, variable list, type and terminals {id, num, ",", INT, FLOAT, CHAR}. Write a grammar for D. (3) Let E be an expression, A be an assignment statement following the grammar we have discussed in class (using factor F and term T) with T={id, num, +, *, (, ), =} and N={A, E, T, F}. Recall that the vertical | means "or". A => id = E E => E + T | T T => T * F | F F => id | num | ( E ) We can build on this grammar to define an IF statement as follows: let I be a non-terminal standing for IF statement and S be non-terminal for statement. Add terminals "if", "then" and "else". Then we can havea grammar for both assign and if statements as follows: S => A | I I => if E then S else S | if E then S However, the rule for I is ambiguous (although the grammar for A is not). Explain what we mean by ambiguous in this case, and find an example that shows the ambiguity.

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!