00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #include <lestes/common.hh> 00029 #include <lestes/intercode/intercode.g.hh> 00030 #include <lestes/lang/cplus/sem/as_decl.g.hh> 00031 #include <lestes/lang/cplus/sem/as_declarator_op2op_func.g.hh> 00032 #include <lestes/lang/cplus/sem/as_expr.g.hh> 00033 #include <lestes/lang/cplus/sem/as_other.g.hh> 00034 #include <lestes/lang/cplus/sem/as_statements.g.hh> 00035 #include <lestes/lang/cplus/sem/sa_class_declaration.g.hh> 00036 #include <lestes/lang/cplus/sem/sa_context.g.hh> 00037 #include <lestes/lang/cplus/sem/sa_loggers.hh> 00038 #include <lestes/lang/cplus/sem/sa_namespace.g.hh> 00039 #include <lestes/lang/cplus/sem/sa_simple_declaration.g.hh> 00040 #include <lestes/lang/cplus/sem/sa_statements.g.hh> 00041 #include <lestes/lang/cplus/sem/sa_usings.g.hh> 00042 #include <lestes/lang/cplus/sem/ss_misc.g.hh> 00043 #include <lestes/lang/cplus/syn/errors.hh> 00044 #include <lestes/lang/cplus/syn/errors.m.hh> 00045 #include <lestes/lang/cplus/syn/hinter.g.hh> 00046 #include <lestes/lang/cplus/syn/hinter.hh> 00047 #include <lestes/lang/cplus/syn/manager.hh> 00048 #include <lestes/lang/cplus/syn/parse_result.hh> 00049 #include <lestes/lang/cplus/syn/parser.hh> 00050 #include <lestes/lang/cplus/syn/semval.hh> 00051 #include <lestes/lang/cplus/syn/syn.hh> 00052 #include <lestes/lang/cplus/syn/token.hh> 00053 #include <lestes/msg/logger.hh> 00054 #include <lestes/msg/logger_util.hh> 00055 #include <lestes/std/dumper.hh> 00056 #include <lestes/std/source_location.hh> 00057 00058 #include <iostream> 00059 #include <iterator> 00060 #include <algorithm> 00061 #include <fstream> 00062 00063 package(lestes); 00064 package(lang); 00065 package(cplus); 00066 package(syn); 00067 00068 declare_logger( pl ); 00069 initialize_logger( pl, "parser", syn_logger ); 00070 00071 // ugly, but we do not want to fully qualify as_* types all the time 00072 using namespace ::lestes::intercode; 00073 using namespace ::lestes::lang::cplus::sem; 00074 00075 static int yylex( semval *sv ) 00076 { 00077 ptr<bison_token> t = manager::yylex(); 00078 llog(pl) << "yylex: " << t << "\n"; 00079 sv->select<bison_token>() = t; 00080 return t->type_get(); 00081 } 00082 00083 // interface mandated by bison 00084 static void yyerror( ptr<as_base> &, const char * str ) 00085 { 00086 llog(pl) << "yyerror: " << str << "\n"; 00087 // do not report errors when trying to resolve an ambiguity 00088 // nor when we are expecting more errors to follow (we are failing) 00089 if (!manager::in_disambiguation() && !manager::failing_get()) { 00090 ptr<bison_token> prev = manager::prev_yylex(); 00091 // supress confusing message about TOK_EOF -- it might be end 00092 // of a function body just as well 00093 if (prev->type_get() == bison_token::TOK_EOF) 00094 report << bad_end << prev->location_get(); 00095 else 00096 report << parse_error << lstring(str) << prev->location_get(); 00097 } 00098 } 00099 00100 void parser::init() 00101 { 00102 // there used to be something here :-) 00103 } 00104 00105 // do not include enum yytokentype in the result; it is included in token.hh 00106 #define YYTOKENTYPE 00107 00108 /* hack to allow compilation under some versions of g++ that do not allow __attribute__ after a label */ 00109 #define __attribute__( x ) 00110 00111 #include <lestes/lang/cplus/syn/parser.tab.cc> 00112 00113 #undef __attribute__ 00114 00115 ptr<parse_result_type> parser::parse() 00116 { 00117 ptr<as_base> as_result = NULL; 00118 llog_xml_open(pl,"parse") << "\n"; 00119 bool success = (yyparse(as_result) == 0); 00120 llog_xml_close(pl,"parse") << "\n"; 00121 return parse_result_type::create( success, manager::prev_yylex(), as_result ); 00122 } 00123 00124 const char * parser::token_type2name( int type ) 00125 { 00126 int tok_type = YYTRANSLATE( type ); 00127 lassert( tok_type != YYUNDEFTOK ); 00128 return yytname[tok_type]; 00129 } 00130 00131 end_package(syn); 00132 end_package(cplus); 00133 end_package(lang); 00134 end_package(lestes);
1.5.1-20070107