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

parser_spec.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       parser_spec.cc
00003  *              $Id: parser_spec.cc,v 1.7 2002/06/13 11:39:54 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  * 
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: parser_spec.cc,v $
00012  *  Revision 1.7  2002/06/13 11:39:54  alec
00013  *  added #line stuff
00014  *
00015  *  Revision 1.6  2002/05/16 22:10:35  alec
00016  *  sync
00017  *
00018  *  Revision 1.5  2002/05/10 07:15:10  alec
00019  *  parser parse tree ok
00020  *
00021  *  Revision 1.4  2002/05/08 18:20:17  alec
00022  *  *** empty log message ***
00023  *
00024  *  Revision 1.3  2002/04/29 09:34:10  alec
00025  *  scanner ptree building compiles
00026  *
00027  */
00028 
00029 /*
00030   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00031 
00032   This program is free software; you can redistribute it and/or modify
00033   it under the terms of the GNU General Public License as published by
00034   the Free Software Foundation; either version 2 of the License, or
00035   (at your option) any later version.
00036 
00037   This program is distributed in the hope that it will be useful,
00038   but WITHOUT ANY WARRANTY; without even the implied warranty of
00039   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00040   GNU General Public License for more details.
00041 
00042   You should have received a copy of the GNU General Public License
00043   along with this program; if not, write to the Free Software
00044   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00045 
00046  */
00047 
00048 #include <algorithm>
00049 
00050 #include "debug.h"
00051 #include "parser_spec.hh"
00052 #include "itoken_spec.hh"
00053 #include "ebnf_la_node.hh"
00054 #include "ebnf_node_builder.hh"
00055 
00056 ParserSpec::ParserSpec (PropRegistry &registry_, ITokenSpec &tokens_) :
00057   tokens(tokens_),
00058   nodeBuilder(*new EbnfNodeBuilder(registry_, tokens_))
00059 {}
00060 
00061 
00062 IEbnfNodeBuilder& ParserSpec::getEbnfNodeBuilder()
00063 {
00064   return nodeBuilder;
00065 }
00066 
00067 
00068 void ParserSpec::addProduction (const string &name,
00069                                 const string &retTypeName,
00070                                 const Position &retTypePos,
00071                                 const string &formalArgs,
00072                                 const Position &formalArgsPos,
00073                                 const string &exceptList,
00074                                 const Position &exceptListPos,
00075                                 const string &preambleCode,
00076                                 const Position &preambleCodePos,
00077                                 EbnfNode *expansion,
00078                                 const Position &pos)
00079   throw (ParseException)
00080 {
00081   if (isProduction(name))
00082     throw ParseException(pos, string("Duplicate production name ") +
00083                          name + ".");
00084   productions.push_back(ProductionSpec(name, retTypeName, retTypePos,
00085                                        formalArgs, formalArgsPos,
00086                                        exceptList, exceptListPos,
00087                                        preambleCode, preambleCodePos,
00088                                        dynamic_cast<EbnfLaNode*>(expansion),
00089                                        pos));
00090 }
00091 
00092 
00093 void ParserSpec::setPreambleCode (const string &block, const Position &pos)
00094 {
00095   preambleCode.set(block, pos);
00096 }
00097 
00098 
00099 void ParserSpec::setClassName (const string &className_)
00100 {
00101   className = className_;
00102 }
00103 
00104 
00105 void ParserSpec::setInheritance (const string &inheritance_,
00106                                  const Position &pos)
00107 {
00108   inheritance.set(inheritance_, pos);
00109 }
00110 
00111 
00112 void ParserSpec::addCodeBlock (const string &block, const Position &pos)
00113 {
00114   userCode.push_back(CodeChunk(pos, block));
00115 }
00116 
00117 
00118 bool operator == (ProductionSpec &p, const string &prodName)
00119 {
00120   return p.name == prodName;
00121 }
00122 
00123 
00124 bool ParserSpec::isProduction (const string &name)
00125 {
00126   return(find(productions.begin(), productions.end(), name) !=
00127                                                   productions.end());
00128 }
00129 
00130 
00131 ProductionSpec& ParserSpec::getProduction (const string &name)
00132   throw (ParseException)
00133 {
00134   vector<ProductionSpec>::iterator i = find(productions.begin(),
00135                                             productions.end(),
00136                                             name);
00137   if (i == productions.end())
00138     throw ParseException(string("Production \"") + name + "\" not found");
00139 
00140   return *i;
00141 }
00142 
00143 #ifdef DEBUG
00144 void ParserSpec::dump (ostream &os) const
00145 {
00146     os << "ParseSpec dump: " << endl
00147        << "className: " << className << endl
00148        << "inheritance: " << inheritance.code << endl
00149        << "preambleCode:" << endl
00150        << preambleCode.code << endl
00151        << "----------------------------------------------------------" << endl
00152        << "userCode:" << endl;
00153     for (int i = 0; i < userCode.size(); i++)
00154       os << userCode[i].code << endl;
00155     os << "----------------------------------------------------------" << endl
00156        << "Productions: " << endl;
00157     for (int i = 0; i < productions.size(); i++) {
00158       productions[i].dump(os);
00159       os << endl;
00160     }
00161     os << "----------------------------------------------------------" << endl;
00162 }
00163 #endif

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