httppuushu5n030f0085b610pdf based on the language described

http://puu.sh/u5n03/0f0085b610.pdf based on the language described in this pdf

State whether or not each of the following language constructs is syntactically valid. For each of syntax is rule that is violated. Declaration: CONST mask BITSET {9..11}; divisor = 512; Declaration: PROCEDURE LessThan (addr1, addr2: ADDRESS): BOOLEAN; BEGIN r1:= addr1; r2:= addr2; RETRUN r1

Solution

(a): The declaration is syntactically valid.

(b): 2 violations in lines mentioned below:

Line 2: Pointers cannot be used to directly define variables. PointerTypes have to be created with pointers first, which can then be used to define variables. The correct syntax is:

Line 4, 5: Pointer type variables or designators (r1 and r2) contain the memory addresses of variables assigned to them (addr1 and addr2). In other words, they point to the variables and not the data conatined in the variables.

By dereferencing these designators (by adding ^), they can be used just as a normal variable. Hence, to assign values to them, the syntax should be:

In the sixth line, the designators have been compared after dereferencing them which is the correct way.

(c): 3 violations in the following lines:

Line 3: EXIT should have a semicolon (;).

Line 8, 9: END should always be followed by a semicolon (;).

(d): Line 4,9: Semicolons missing at end of line.

  TYPE      PointerReal = POINTER TO REAL;  VAR      r1, r2 : PointerReal;  
http://puu.sh/u5n03/0f0085b610.pdf based on the language described in this pdf State whether or not each of the following language constructs is syntactically v

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site