Computer Science Syntax Definitions Worksheet
=========================================================
CSc 600 – Homework #1.1 - Syntax Dr. Jozo Dujmović
=========================================================
1. Write the syntax definitions of the following objects:
(a) Natural number (1, 2, 3, …)
(b) Unsigned integer (0, 1, 2, 3, …)
(c) Integer (…, -2, -1, 0, 1, 2, …)
(d) Odd number (…, -3, -1, 1, 3, …)
(e) Even number (…, -4, -2, 0, 2, 4, …)
(f) Integer divisible by 5 (…, -10, -5, 0, 5, 10, …)
Solve each problem from (a) to (f) using BNF, EBNF, syntax diagrams, and the
parenthetic notation. At the end compare all solutions and write what is in your opinion the
most suitable metalanguage for solving this type of problems.
2. Following is an example of assignment statement in C++ :
alpha5[i][j] = 12.34*a[5]/rate + 3.14*(x[2*i-1][3 + j] -1);
Based on this example, write a BNF definition of the syntax of arbitrary assignment
statements in C++. Do not expand your definition beyond components shown in the above
example. So, variables can be scalar or can have any number if indexes that can be
expressions. Use only basic arithmetic operations (+, - , * , /) . Do not use functions or
multiple assignments. The goal is to create a basic definition of arbitrary expressions based on
the combinations of variables and basic arithmetic operations.
______________________________________________________________________________
Note #1: Your solution should be submitted as a single pdf file. This file must be prepared
using a text editor (like Notepad) or a word processor (like MS Word) and then converted to pdf.
Graphical components (circles, rectangles, arrows) can be inserted in any readable way including
by hand. You can also use approximations and simplifications such as this example:
.-------.
------>| digit |---.----->
^ ‘-------’ |
| |
‘---------------’
Note #2: Individual solving of homework problems is the best preparation for exam.