Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

lex_yacc_parser.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       lex_yacc_parser.cc
00003  *              $Id: lex_yacc_parser.cc,v 1.8 2002/05/16 22:09:33 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *      This is part of the LEX/YACC wrapper. Some of the functions (yyerror,
00010  *      yywrap etc) are here, but the syntactic hooks are not. You will find
00011  *      those in c_*_wrapper.[ch][ch] files.
00012  *
00013  *  Revision history:
00014  *
00015  *  $Log: lex_yacc_parser.cc,v $
00016  *  Revision 1.8  2002/05/16 22:09:33  alec
00017  *  sync
00018  *
00019  *  Revision 1.7  2002/05/10 07:15:10  alec
00020  *  parser parse tree ok
00021  *
00022  *  Revision 1.6  2002/05/08 18:19:14  alec
00023  *  *** empty log message ***
00024  *
00025  *  Revision 1.5  2002/05/04 17:39:22  alec
00026  *  the scanner works (slightly tested)
00027  *
00028  *  Revision 1.4  2002/04/29 17:55:41  alec
00029  *  regexps almost done
00030  *
00031  *  Revision 1.3  2002/04/29 09:34:10  alec
00032  *  scanner ptree building compiles
00033  *
00034  */
00035 
00036 /* 
00037   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00038 
00039   This program is free software; you can redistribute it and/or modify
00040   it under the terms of the GNU General Public License as published by
00041   the Free Software Foundation; either version 2 of the License, or
00042   (at your option) any later version.
00043 
00044   This program is distributed in the hope that it will be useful,
00045   but WITHOUT ANY WARRANTY; without even the implied warranty of
00046   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00047   GNU General Public License for more details.
00048 
00049   You should have received a copy of the GNU General Public License
00050   along with this program; if not, write to the Free Software
00051   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 /* LEX/YACC (or should it read yuck ?) interfacing stuff */
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 /* this one is used by formatError and formatWarning to format the messages */
00089 extern string fileName;
00090 
00091 
00092 bool LexYaccParser::parse (PropRegistry &registry,
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 

Generated at Tue Jul 9 21:05:44 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001