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 #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 }