The Micro Language
Abstract
This document presents the de nition of a very simple language
called Micro. The purpose is for writing a very simple compiler for it.
This work is inspired by a book \Crafting a compiler".
1 Informal description of Micro
A program of the Micro language has only integer data. The possible actions
are the following:
Input values of a list of variables (read).
Output/print the values of a list of expressions (write).
Assign (the value of) an expression to a variable.
Each expression is a sequence of the common arithmetic operations of
integers: addition, minus, multiplication, integer division (result is an
integer).
The grammar of a Micro programming language has the following fea-
tures:
Comment starts with two dashes ({) and ends at the end of the line.
Each program starts with the word \begin" and ends with the word
\end".
Each statement ends with a \;".
Each statement is either a read, or a write, or an assignment statement.
2 A sample program
-- a simple micro program
-- good luck. It is a comment
begin
read(x, y, z); -- input three integers
a := x+y;
b := 314;
c := 1 + a * (b - 1) / 2;
write(a, b, c, (a+b+c)/(x+y) ) ;
end
3 Grammar
Each variable is surrounded by . Other items are terminals, which
are tokens. A phrase of {some} means 0 or more copies of some. Equivalent
to some* using regular expression. For example, the following 2 production
rules are the same:Another pair of equivalent production rules:
Usingfgis ne since in Micro these characters do not normally appear.
For a grammar of C, we may need to use other notations.
3.1 A grammar of Micro
begin end
The production rule of the variable should respect the prece-
dence and association of the operators and parenthesis, which has been dis-
cussed in classroom.