A pretty printer for Lotus
Check user's program if there is any syntax error
and help user print his program in a pretty form.
This project will use the lexical analyzer and the parser .
Description
This pretty printer can reprint user's programs by using the option "-t" or
just perform syntax analyzing actions without "-t".
Yet, no syntax error recovery is performed. Each syntax
error message will include the line number where the error is detected.
The parser reads input from stdin, writes output to stdout,
and writes errors to stderr.
The frame of this program is shown in the following figure.
A sample for input the Lotus program
-- A program to sum 1 to n
int main( ) { int n; int s; int t;
read n; if ((n < 0)&&(s<0)||(t>0)) {
write -1;
if (n>s) {read s ;
exit; } else { s = sum(n); }
} write s; return 0;}
int sum(int n, int s) {
int s;
s = 0;
while
(n > 0) { s=s+n; n = n - 1;}
return s;}
The output for this sample
int main()
{
int n;
int s;
int t;
read n;
if ((n < 0) && (s < 0) || (t > 0)) {
write - 1;
if (n > s) {
read s;
exit;
} else {
s = sum(n);
}
}
write s;
return 0;
}
int sum(int n, int s)
{
int s;
s = 0;
while (n > 0) {
s = s + n;
n = n - 1;
}
return s;
}