00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include <cstdio>
00056 #include "../config.h"
00057 #include "parse_util.hh"
00058 #include "lex_yacc_parser.hh"
00059
00060 #include "options_recorder.hh"
00061
00062 #include "cw_options_recorder.h"
00063 #include "cw_iscanner_spec.h"
00064 #include "macro_token_expander.hh"
00065 #include "cw_macro_token_expander.h"
00066 #include "token_spec.hh"
00067 #include "cw_itoken_spec.h"
00068 #include "scanner_spec.hh"
00069 #include "cw_re_node_builder.h"
00070 #include "token_spec.hh"
00071 #include "cw_iparser_spec.h"
00072 #include "cw_ebnf_node_builder.h"
00073 #include "parser_spec.hh"
00074
00075
00076
00077 #ifdef DEBUG
00078 extern int yy_flex_debug;
00079 extern int yydebug;
00080 #endif
00081
00082 extern "C" int yyparse();
00083 extern "C" int yylex();
00084 extern FILE* yyin;
00085 extern int yylineno;
00086
00087
00088
00089 extern string fileName;
00090
00091
00092 bool LexYaccParser::parse (PropRegistry ®istry,
00093 ITokenSpec &tSpec,
00094 IScannerSpec &sSpec,
00095 IParserSpec &pSpec)
00096 {
00097
00098 #ifdef DEBUG
00099 yy_flex_debug = 0;
00100 yydebug = 0;
00101 if (((string)registry["debug"]).find('s') != string::npos) yy_flex_debug = 1;
00102 if (((string)registry["debug"]).find('p') != string::npos) yydebug = 1;
00103 #endif
00104
00105
00106 if (!(yyin = fopen(((string)registry["input_file"]).c_str(), "r"))) {
00107 die(formatError(string("Could not open file \"") +
00108 registry["input_file"] + "\" for reading."));
00109 }
00110
00111 fileName = registry["input_file"];
00112
00113 if (registry["be_verbose"])
00114 cout << "Reading from file: " << (string)registry["input_file"] << endl;
00115
00116 cw_optionsRecorder = new OptionsRecorder(registry);
00117 cw_macroTokenExpander = new MacroTokenExpander();
00118 cw_scannerSpec = &sSpec;
00119 cw_parserSpec = &pSpec;
00120 cw_reNodeBuilder = &sSpec.getReNodeBuilder();
00121 cw_tokenSpec = &tSpec;
00122 cw_ebnfNodeBuilder = &pSpec.getEbnfNodeBuilder();
00123
00124 bool res = yyparse() == 0;
00125
00126 #ifdef DEBUG
00127 if (((string)registry["debug"]).find('d') != string::npos) {
00128 sSpec.dump(cerr);
00129 pSpec.dump(cerr);
00130 }
00131 #endif
00132
00133 return res;
00134 }
00135