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

ebnf_node_builder.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       ebnf_node_builder.cc
00003  *              $Id: ebnf_node_builder.cc,v 1.5 2002/06/23 23:32:11 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  * 
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: ebnf_node_builder.cc,v $
00012  *  Revision 1.5  2002/06/23 23:32:11  alec
00013  *  la-time usercode (force)
00014  *
00015  *  Revision 1.4  2002/06/13 11:37:08  alec
00016  *  added #line stuff
00017  *
00018  *  Revision 1.3  2002/05/16 21:35:13  alec
00019  *  parser generation done
00020  *
00021  *  Revision 1.2  2002/05/10 07:15:10  alec
00022  *  parser parse tree ok
00023  *
00024  *  Revision 1.1  2002/05/08 18:17:37  alec
00025  *  *** empty log message ***
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 
00049 #include <vector>
00050 
00051 #include "ebnf_node_builder.hh"
00052 #include "ebnf_la_node.hh"
00053 #include "catch_clause.hh"
00054 
00055 
00056 EbnfNode* EbnfNodeBuilder::createOrNode (EbnfNode *pre, EbnfNode *post,
00057                                          const Position &pos)
00058 {
00059   return new EbnfOrNode(dynamic_cast<EbnfLaNode*>(pre),
00060                         dynamic_cast<EbnfLaNode*>(post),
00061                         pos);
00062 }
00063 
00064 
00065 EbnfNode* EbnfNodeBuilder::createCatNode (EbnfNode *pre, EbnfNode *post,
00066                                           const Position &pos)
00067 {
00068   return new EbnfCatNode(dynamic_cast<EbnfLaNode*>(pre),
00069                          dynamic_cast<EbnfLaNode*>(post),
00070                          pos);
00071 }
00072 
00073 
00074 EbnfNode* EbnfNodeBuilder::createPlusNode (EbnfNode *in,
00075                                            const Position &pos)
00076 {
00077   return new EbnfCatNode(dynamic_cast<EbnfLaNode*>(in->clone()),
00078                          new EbnfStarNode(dynamic_cast<EbnfLaNode*>(in),
00079                                           pos),
00080                          pos);
00081 }
00082 
00083 
00084 EbnfNode* EbnfNodeBuilder::createStarNode (EbnfNode *in,
00085                                            const Position &pos)
00086 {
00087   return new EbnfStarNode(dynamic_cast<EbnfLaNode*>(in),
00088                           pos);
00089 }
00090 
00091 
00092 EbnfNode* EbnfNodeBuilder::createOptionalNode (EbnfNode *in,
00093                                                const Position &pos)
00094 {
00095   return new EbnfOrNode(dynamic_cast<EbnfLaNode*>(in),
00096                         new EbnfLambdaNode(pos),
00097                         pos);
00098 }
00099 
00100 
00101 EbnfNode* EbnfNodeBuilder::createNonterminalNode (const string &targetVar,
00102                                                   const Position &targetVarPos,
00103                                                   const string &nontermId,
00104                                                   const string &actualArgs,
00105                                                  const Position &actualArgsPos,
00106                                                   const Position &pos)
00107 {
00108   return new EbnfNonterminalNode(targetVar, targetVarPos, nontermId,
00109                                  actualArgs, actualArgsPos, pos);
00110 }
00111 
00112 
00113 EbnfNode* EbnfNodeBuilder::createTerminalNode (const string &termId,
00114                                                const Position &pos)
00115   throw (ParseException)
00116 {
00117   if (!tokens.isToken(termId))
00118     throw ParseException(pos, string("Token \"") + termId + "\" was not declared in the lexical section.");
00119   return new EbnfTerminalNode(dynamic_cast<TokenDesc&>(tokens[termId]),
00120                               pos);
00121 }
00122 
00123 
00124 LaSpec* EbnfNodeBuilder::createLaSpec (int fixedLa, EbnfNode *synLa,
00125                                        const string &semLa,
00126                                        const Position &pos)
00127 {
00128   return new NumberedLaSpec(fixedLa, synLa, semLa, pos);
00129 }
00130 
00131 
00132 CatchClause* EbnfNodeBuilder::createCatchClause (const string &exceptionDecl,
00133                                                  const Position &edPos,
00134                                                  const string &code,
00135                                                  const Position &codePos)
00136 {
00137   return new CatchClause(exceptionDecl, edPos, code, codePos);
00138 }
00139 
00140 
00141 void EbnfNodeBuilder::setLookahead (EbnfNode* node, LaSpec* la)
00142 {
00143   dynamic_cast<EbnfLaNode*>(node)->laSpec = dynamic_cast<NumberedLaSpec*>(la);
00144 }
00145 
00146 void EbnfNodeBuilder::setStartCode (EbnfNode *node, const string &code,
00147                                     bool force, const Position &pos)
00148 {
00149   dynamic_cast<EbnfLaNode*>(node)->startCode.set(code, pos);
00150   dynamic_cast<EbnfLaNode*>(node)->forceStartCode = force;
00151 }
00152 
00153 void EbnfNodeBuilder::setEndCode (EbnfNode *node, const string &code,
00154                                   bool force, const Position &pos)
00155 {
00156   dynamic_cast<EbnfLaNode*>(node)->endCode.set(code, pos);
00157   dynamic_cast<EbnfLaNode*>(node)->forceEndCode = force;
00158 }
00159 
00160 void EbnfNodeBuilder::setCatchClauses (EbnfNode *node,
00161                                 vector<CatchClause> &catchList)
00162 {
00163   dynamic_cast<EbnfLaNode*>(node)->catchList = catchList;
00164 }

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