Parser Demo
/*
* This program parses its input according to the following expression grammar:
* Asst --> Id := Expr ;
* Expr --> Term | { [ + | - ] Term }*
* Term --> Fact | { [ * | / ] Fact }*
* Fact --> Id | Lit | ( Expr )
*
* The program reads standard input and attempts to parse it as an Asst. It
* then prints a representation of the input structure. If you type the input,
* make sure to issue an EOF (^D in unix, ^Z in windows shell) at the end.
*
* The parser itself (which encodes the rules) resides in parser.h/parser.cpp.
*/
#include <stdlib.h>
#include <iostream>
#include "parser.h"
using namespace std;
// Read and print.
main()
{
Parser p(cin);
try {
p.parse();
} catch(exception &e) {
cout << "Parsing failed: " << e.what() << endl;
exit(1);
}
p.print(cout);
}