Original Little Quilt
Little Quilt is a very small language for designing quilts. It is based on
ML syntax. The language definition can be found in the book Programming
Languages: Concepts and Constructs. Ravi Sethi. Addison-Wesley, 1996.
(An Indian edition of the book is available locally and is strongly recommended
if you are interested in understanding different programming paradigms.)
Enhancements in Little Quilt
The original Little Quilt does not support assignment statements, conditionals, iterative
construct, or self-recursion.
For the purpose of CS394, they have to be supported.
- Now comments can be included in quilt programs. They begin with a %
character and end with a new line (or end of file) character.
- A quilt expression can be
- One of the usual quilt expressions defined in the Original Little Quilt.
- A special empty quilt EQ.
- A quilt obtained by the head and tail operations.
These operations view a quilt as
rectangular matrix
where each element can be one of the following
- a0, b0 : quilt a or b.
- a1, b1 : quilt a or b turned 90 degrees clockwise.
- a2, b2 : quilt a or b turned 180 degrees clockwise.
- a3, b3 : quilt a or b turned 270 degrees clockwise.
The actual operations are
- hdRow(q) : compute the quilt represented by
the first row of the matrix
corresponding to quilt q.
- tlRow(q) : compute the quilt represented by the
rows remaining after removing the
first row of the matrix
corresponding to quilt q.
- hdCol(q) : compute the quilt represented by the
the first column of the matrix
corresponding to quilt q.
- tlCol(q) : compute the quilt represented by the
columns remaining after removing the
first column of the matrix
corresponding to quilt q.
- A sequence of statements ending in a result statement. The value of the
expression is the quilt appearing in the result statement.
- Each statement is terminated by a semi-colon and can be one of the following kind
- Assignment Statement.
Variable = QuiltExpression ;
The left hand side is an undeclared variable representing
a quilt. The right hand side is a quilt expression.
- Conditional Statement.
if (QuiltExpression RelOp QuiltExpression) then StatementList fi ;
The relational operator can be test of equality (
==
) or test of inequalty
(
!=
).
An alternative version of the conditional statement is
if (QuiltExpression RelOp QuiltExpression) then StatementList else
StatementList fi ;
- Looping Statement.
while (QuiltExpression RelOp QuiltExpression) do StatementList od ;
- Result Statement.
result QuiltExpression ;
Examples of Valid Programs
- This is my first program nq0 in the New Quilt.
- Some programs in original quilt, which are also valid programs in New quilt are
-
q0,
matrix version, and its
picture.
-
q1,
matrix version, and its
picture.
-
q2,
matrix version, and its
picture.
-
q3,
matrix version, and its
picture.
-
q4,
matrix version, and its
picture.
-
q5,
matrix version, and its
picture.
-
q6,
matrix version, and its
picture.
-
q7,
matrix version, and its
picture.
-
q12,
matrix version, and its
picture.
The following programs are syntactically valid but
semantically invalid :
q8,
q9,
q10, and
q11.
- Here is the binary executable of a reference implementation of a
parser for the New Quilt.
Semantic checks have not been inserted in this implementation and it is a pure
parser which checks only for syntax and quits with a terse "syntax error" if the
input is not valid syntactically.
This has been compiled on a
Fedora Core 1 running on P4. I expect it to work on common versions of Linux
running on a pentium processor.
Back to top of the page
Back to the course page
Last updated on 3 Jan 2005.