<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML
2.0//EN"><!--Converted with LaTeX2HTML 96.1-beta (Jan 15, 1996) by
Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->CS471 Programming
Language
Structure I, Spring 2000
Homework 1: Answers
Answer:
There are many correct answers, but the important points are:
<program> ::= ON OFF | ON <calc_list> OFF ; program may be empty
<calc_list> ::= <calc> | <calc> <calc_list> ; any number of calculations
<calc> ::= <expr> = ; a calculation is an expression
; followed by =
<expr> ::= <operand> <op> <expr> | <operand> ; any number of infix operations
; with no precedence
<operand> ::= <num> | <num> +/- | ( <expr> ) ; a number followed optioanlly by
; +/-
<num> ::= <int> | <real> ; numbers can be integer or real
<int> ::= <digit> | <digit> <int> ; any sequence of digits
<real> ::= <int> . | <int> . <int> ; the fractional part may be absent
<op> ::= + | - | ´ | ¸ ; four functions
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ; no comment!
The EBNF form must remove all recursion to be correct. If a BNF rule in part 1 had two recursive non-terminals (probably ambiguous), then it should be replaced by an unambiguous form with only one recursion before conversion to ENBF. It is OK to use a superscript 1 (at least one) or 0 (zero or more) on braces for repetition.
program ::= 'ON' {expr '='} 'OFF' ; program may be empty
expr ::= operand {('+' | '-' | '´' | '¸') operand} ; any number of infix operations
; with no precedence
operand ::= num [+/-] | '(' expr ')' ; a number followed optionally by
; +/- or a parenthsized expression
num ::= digit {digit} ['.' {digit}] ; numbers can be integer or real
digit ::=' '0 | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'