00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include <string>
00021 #include <vector>
00022 using namespace std;
00023
00024 #include "FormulaGrammar.h"
00025
00026
00027
00028
00029
00030 int main( int argc, char ** argv )
00031 {
00032
00033
00034 if ( argc != 1 )
00035 {
00036 if ( (argc == 2 && ( string( argv[ 1 ] ) == "-h" )) ||
00037 (argc == 2 && ( string( argv[ 1 ] ) == "--help" )) )
00038 {
00039 cout << "Usage: " << argv[ 0 ] << " [-h | --help]" << endl
00040 << "Expects a formula on the standard input." << endl;
00041 return 0;
00042 }
00043
00044
00045 cerr << "Unexpected arguments. Type " << argv[ 0 ]
00046 << " --help for usage." << endl;
00047 return 1;
00048 }
00049
00050
00051 string InputFormula;
00052 vector< string > Code;
00053 parse_info< const char * > Info;
00054 SFormulaGrammar FormulaGrammar( Code );
00055
00056
00057
00058 cin >> InputFormula;
00059 if ( cin.fail() )
00060 {
00061 cerr << "Wrong input stream" << endl;
00062 return 2;
00063 }
00064
00065
00066 try
00067 {
00068
00069 Info = parse( InputFormula.c_str(), FormulaGrammar, space_p );
00070 if ( !Info.full )
00071 {
00072 cerr << "Parsing error. Stopped at: '" << Info.stop << "'" << endl;
00073 return 3;
00074 }
00075
00076
00077 for ( vector< string >::const_iterator k( Code.begin() );
00078 k != Code.end(); ++k )
00079 {
00080 cout << *k << endl;
00081 }
00082 }
00083 catch ( exception & Exception )
00084 {
00085 cerr << Exception.what() << endl;
00086 return 4;
00087 }
00088 catch ( ... )
00089 {
00090 cerr << "Unknown exception." << endl;
00091 return 4;
00092 }
00093
00094 return 0;
00095 }
00096