On the class web site you will find an EBNF description of the Modula-2 language
ID: 3596157 • Letter: O
Question
On the class web site you will find an EBNF description of the Modula-2 language. Use this description to answer questions 1 and 2.
1. Given an example of the shortest IF statement in Modula-2. (“Shortest” means fewest number of lexemes.)
2. 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
3. Using the grammar in Example 3.4, show a parse tree and a leftmost derivation for the following statement:
A = A * (B + C)
Explanation / Answer
I am trying to write the shortest if statement in term of number of lexemes, Based on the description above, will this work?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.