EBNF description of the Modula 2 language Use this descripti

EBNF description of the Modula- 2 language. Use this description to answer the question

State whether or not each of the following language constructs is syntactically valid. For each invalid construct, give the number of the syntax rule that is violated.

(a) Declaration:

CONST mask = BITSET{9..11}; divisor = 512;

(b) Declaration:

PROCEDURE LessThan(addr1, addr2: ADDRESS): BOOLEAN;

VAR r1, r2: POINTER TO REAL;

BEGIN

r1 := addr1;

r2 := addr2;

RETURN r1^ < r2^

END;

(c) Statement:

LOOP

Position(pattern, source, index, found);

IF NOT found THEN EXIT END;

Delete(source, index, Length(pattern), success);

Insert(replacement, source, index, success);

IF NOT success THEN Error(\"Buffer overflow in Replace\");

END

END

(d)

IF queue = NIL THEN

temp^.next := temp;

temp^.previous := temp;

queue := temp

ELSE

temp^.next := queue;

temp^.previous := queue^.previous;

queue^.previous^.next := temp;

queue^.previous := temp

END

Solution

There are three invalid statements found mentioned in comment section

(a) Declaration:
CONST mask = BITSET{9..11}; divisor = 512;
Comment 1: BITSET is invalid keyword


(b) Declaration:
PROCEDURE LessThan(addr1, addr2: ADDRESS): BOOLEAN;
VAR r1, r2: POINTER TO REAL;
BEGIN
r1 := addr1;
r2 := addr2;
RETURN r1^ < r2^
END;
Comment 2: LessThan is invalid

(c) Statement:
LOOP
Position(pattern, source, index, found);
IF NOT found THEN EXIT END;
Delete(source, index, Length(pattern), success);
Insert(replacement, source, index, success);
IF NOT success THEN Error(\"Buffer overflow in Replace\");
END
END
Comment 3: Only one END required to stop one LOOP
(d)
IF queue = NIL THEN
temp^.next := temp;
temp^.previous := temp;
queue := temp
ELSE
temp^.next := queue;
temp^.previous := queue^.previous;
queue^.previous^.next := temp;
queue^.previous := temp
END

EBNF description of the Modula- 2 language. Use this description to answer the question State whether or not each of the following language constructs is syntac
EBNF description of the Modula- 2 language. Use this description to answer the question State whether or not each of the following language constructs is syntac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site