I'm doing a homework assignment in which I have been provided a snippet of text titled "EBNF Description of Modula-2's Syntax" and the question asks:
"Give an example of the shortest REPEAT
statement in Modula-2. ('Shortest' means fewest number of lexemes.)"
I apologies for not being able to provide the text, it is on a page that is password protected, however the text is as the title says. Basically this is what I came up with and I want to know if this works.
The EBNF description of REPEAT
and it's following statements is as such:
RepeatStatement = `REPEAT` StatementSequence `UNTIL` Expression.
StatementSequence = Statement {“;” Statement}.
Statement = [Assignment | ProcedureCall | IfStatement | CaseStatement |
WhileStatement | RepeatStatement | LoopStatement |
ForStatement | WithStatement | `EXIT`
So by this description could I simply say:
REPEAT EXIT.
and be done? or do I absolutely have to use the UNTIL
and/or the full StatementSequence
EBNF description?
TL;DR is the rest of the EBNF statement void if I just say EXIT
?
Well, the EBNF is pretty clear:
RepeatStatement = `REPEAT` StatementSequence `UNTIL` Expression.
So you must have a REPEAT
keyword, a statement sequence (which can be just EXIT
), the UNTIL
keyword and an expression. Only those four parts together make up a valid repeat statement ...
So I guess something like this would be the shortest you can be:
REPEAT EXIT UNTIL TRUE