// Purpose: Tests the production rule for Declaration List bool syntaxparser::DeclarationList(){ bool bDeclarationList = false; if (displayFlag){ cout <<endl<< "<DeclarationList> ::= <Declaration>;<DeclarationList>" << endl; printproduction("<DeclarationList> ::= <Declaration>;<DeclarationList>"); } Declaration(); //checks to see if next lexeme is a qualifier if(lexeme ==";"){ Lexer(); if(lexeme == "int" || lexeme == "boolean"){ project3.addType(lexeme); Lexer(); // if we have a semi colon then we recursively call for more additional declarations DeclarationList(); } else if (lexeme == "real"){ error("The 'real' type is not valid for Rat10F"); } } else error("Missing ;"); bDeclarationList = true; return bDeclarationList; }
bool syntaxparser::Assign(){ bool bAssign = false; if (token == "identifier"){ print(); // Save the token string assign_save; assign_save = lexeme; cout<<endl; Lexer(); if(displayFlag){ cout << "<Assign> ::= <Identifier> := <Expression>;" << endl; printproduction("<Assign> ::= <Identifier> := <Expression>;"); } if (lexeme == ":="){ print(); cout<<endl; Lexer(); Expression(); string addr; addr = project3.get_address(assign_save); project3.gen_inst("POPM", addr); if(lexeme == ";"){ print(); cout<<endl; Lexer(); bAssign = true; }else error("Missing ';'"); } } return bAssign; }
bool syntaxparser::TermPrime(){ bool bTermPrime = false; if (lexeme == "*"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<TermPrime> ::= *<Factor><TermPrime>" << endl; printproduction("<TermPrime> ::= *<Factor><TermPrime>"); } Factor(); project3.gen_inst("MUL","-999"); string type1, type2; type1 = project3.returnSymbolType(2); type2 = project3.returnSymbolType(3); if(type1 == "boolean") error("Cannot perform '*' on boolean"); if (type2 == "boolean") error("Cannot perform '*' on boolean"); TermPrime(); bTermPrime = true; } else if (lexeme == "/"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<TermPrime> ::= /<Term><FactorPrime>" << endl; printproduction("<TermPrime> ::= /<Term><FactorPrime>"); } bTermPrime = true; Factor(); project3.gen_inst("DIV", "-999"); string type1, type2; type1 = project3.returnSymbolType(2); type2 = project3.returnSymbolType(3); if(type1 == "boolean") error("Cannot perform '/' on boolean"); if (type2 == "boolean") error("Cannot perform '/' on boolean"); TermPrime(); } else{ bTermPrime = true; if(displayFlag){ cout << "<TermPrime> ::= epsilon" << endl; printproduction("<TermPrime> ::= epsilon"); } } return bTermPrime; }
void XSDParser::SkipContent() { TToken tok; bool eatEOT= false; XSDLexer& l = dynamic_cast<XSDLexer&>(Lexer()); for ( tok = l.Skip(); ; tok = l.Skip()) { if (tok == T_EOF) { return; } ConsumeToken(); switch (tok) { case K_ENDOFTAG: if (!eatEOT) { return; } break; case K_CLOSING: SkipContent(); break; default: case K_ELEMENT: break; } eatEOT = tok == K_ELEMENT; } }
string XSDParser::ParseGroup(DTDElement* owner, int emb) { string name; TToken tok = GetRawAttributeSet(); if (GetAttribute("ref")) { string id = CreateEntityId(m_Value,DTDEntity::eGroup); name = CreateTmpEmbeddedName(owner->GetName(), emb); DTDElement& node = m_MapElement[name]; node.SetEmbedded(); node.SetName(m_Value); node.SetOccurrence( ParseMinOccurs( node.GetOccurrence())); node.SetOccurrence( ParseMaxOccurs( node.GetOccurrence())); node.SetQualified(owner->IsQualified()); SetCommentsIfEmpty(&(node.Comments())); if (m_ResolveTypes) { if (m_MapEntity.find(id) != m_MapEntity.end()) { PushEntityLexer(id); ParseGroupRef(node); } else { ParseError("Unresolved entity", id.c_str()); } } else { node.SetTypeName(node.GetName()); node.SetType(DTDElement::eUnknownGroup); Lexer().FlushCommentsTo(node.Comments()); } } if (tok == K_CLOSING) { ParseContent(m_MapElement[name]); } m_ExpectLastComment = true; return name; }
int main() { string input; while (prompt(input)) { istringstream iss(input); try { cout << " = " << flush; Lexer Lexer(iss); Scanner Scanner(Lexer); cout << *(Scanner.Scan()->Evaluate(BuiltInEnvironment())) << endl; } catch (InternalError const &re) { cerr << "internal error" << endl; } catch (SyntaxError const &re) { cerr << "syntax error" << endl; } catch (PreprocessError const &re) { cerr << "preprocess error" << endl; } catch (RuntimeError const &re) { cerr << "runtime error" << endl; } catch (UserException const &re) { cerr << "exception: " << *(re.m_pValue) << endl; } catch (ExitException const &re) { return re.m_pCode->m_n; } } cout << endl; }
void XSDParser::ParseEnumeration(DTDAttribute& att) // enumeration // http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#rf-enumeration // actual value // http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#key-vv { TToken tok = GetRawAttributeSet(); att.SetType(DTDAttribute::eEnum); int id = 0; if (GetAttribute("intvalue")) { id = NStr::StringToInt(m_Value); att.SetType(DTDAttribute::eIntEnum); } if (GetAttribute("value")) { string v(m_ValuePrefix); if (!v.empty()) { v += ':'; } v += m_Value; NStr::TruncateSpacesInPlace(v); att.AddEnumValue(v, Lexer().CurrentLine(), id); } if (tok == K_CLOSING) { ParseContent(att); } }
/* MAIN FUNCTION */ int main(int argc, char* argv[]) { char CharSource[MAX_NUM_CHARS_IN_SOURCE] = ""; Token TokSource[MAX_NUM_TOKENS_IN_SOURCE]; int i; if (argc > 1) { for (i = 1; i < argc; ++i) { strcat(CharSource, argv[i]); } } else { printf(">>"); gets(CharSource); printf("the input expression is %s\n", CharSource); } Lexer(CharSource, TokSource); Token* TokBegin = TokSource; printf("%f\n", Eval_Expression(&TokBegin)); return EXIT_SUCCESS; }
// Purpose: Tests the production rule for Read bool syntaxparser::Read(){ bool bRead = false; if (lexeme == "read"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<Read> ::= read ( <IDs> );" << endl; printproduction("<Read> ::= read ( <IDs> );"); } if (lexeme == "("){ print(); cout<<endl; Lexer(); string temp_id; temp_id = lexeme; IDs(); if (lexeme == ")"){ print(); cout<<endl; Lexer(); if (lexeme == ";"){ print(); cout<<endl; project3.gen_inst("PUSHSTD", ""); string addr; addr = project3.get_address(temp_id); project3.gen_inst("POPM", addr); Lexer(); bRead = true; }else error("Missing ';'"); }else error("Missing ')'"); } } return bRead; }
bool syntaxparser::Function(){ bool bFunction = false; if (displayFlag){ cout<<"<Function> ::= function <identifier> [ <Opt Parameter List> ] <Opt Declaration List> <Body>"<<endl; printproduction("<Function> ::= function <identifier> [ <Opt Parameter List> ] <Opt Declaration List> <Body>"); } print(); if( lexeme == "function"){ Lexer(); print(); if(token == "identifier"){ Lexer(); print(); if(lexeme == "["){ Lexer(); if(OptParameterList()){ if(lexeme == "]"){ print(); Lexer(); cout<<endl; if(OptDeclarationList()){ if(Body()){ bFunction = true; } } }else error("Missing ']'"); } }else{ error("Missing '[' separator"); } }else{ error("Missing identifier"); } } return bFunction; }
// Purpose: Tests the production rule for Compound bool syntaxparser::Compound(){ bool bCompound = false; if (lexeme == "{"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<compound> ::= { <Statement List> }" << endl; printproduction("<compound> ::= { <Statement List> }"); } StatementList(); if(lexeme == "}"){ print(); cout<<endl; bCompound = true; Lexer(); }else error("Missing '}'"); } return bCompound; }
// Purpose: Tests the production rule for IDs bool syntaxparser::IDs(){ bool bIDs = false; if(token == "identifier"){ if(project3.checkDuplicates(lexeme)){ project3.addIdentifier(lexeme); } else error("Already declared variable"); print(); Lexer(); if (displayFlag){ cout << "<IDs> ::= <Identifier>"<<endl; printproduction("<IDs> ::= <Identifier>"); } if (lexeme == ","){ if (displayFlag){ cout << "<IDs> ::= <Identifier>, <IDs>" << endl; printproduction("<IDs> ::= <Identifier>, <IDs>"); } print(); // print out the comma Lexer(); // get the next token to see if ID //print(); // print out the next token, which should be an identifier IDs(); bIDs = true; } bIDs = true; } else error("Missing Identifier"); return bIDs; }
// Purpose: Tests the production rule for Body bool syntaxparser::Body(){ bool body = false; if(lexeme == "{"){ print(); Lexer(); if(displayFlag){ cout<<endl<<"<Body> ::= { <Statement List> }"<<endl; printproduction("<Body> ::= { <Statement List> }"); } StatementList(); if(lexeme == "}"){ print(); Lexer(); body = true; }else{ error("Missing '}'"); } }else{ error("Missing '{'"); } return body; }
bool syntaxparser::While(){ bool bWhile = false; if (lexeme == "while"){ print(); cout<<endl; string addr; addr = project3.get_instr_address(); project3.gen_inst("Label", "-999"); Lexer(); if(displayFlag){ cout << "<While> ::=( <Condition> ) <Statement>" << endl; printproduction("<While> ::=( <Condition> ) <Statement>"); } if (lexeme == "("){ print(); cout<<endl; Lexer(); Condition(); if (lexeme == ")"){ print(); cout<<endl; Lexer(); Statement(); project3.gen_inst("JUMP", addr); addr = project3.get_instr_address(); project3.back_patch( addr); bWhile = true; }else error("Missing ')'"); } } return bWhile; }
bool syntaxparser::Relop(){ cout<<endl; bool Relop = false; if(lexeme == "="){ print(); Lexer(); Relop = true; if(displayFlag){ cout<<"<Relop> ::= =" << endl; printproduction("<Relop> ::= ="); } }else if(lexeme =="/="){ print(); Lexer(); Relop = true; if(displayFlag){ cout<<"<Relop> ::= /=" << endl; printproduction("<Relop> ::= /="); } }else if(lexeme ==">"){ print(); Lexer(); Relop = true; if(displayFlag){ cout<<"<Relop> ::= >" << endl; printproduction("<Relop> ::= >"); } }else if(lexeme =="<"){ print(); Lexer(); Relop = true; if(displayFlag){ cout<<"<Relop> ::= <" << endl; printproduction("<Relop> ::= <"); } }else if(lexeme =="=>"){ print(); Lexer(); Relop = true; if(displayFlag){ cout<<"<Relop> ::= =>" << endl; printproduction("<Relop> ::= =>"); } }else if(lexeme =="<="){ print(); Lexer(); Relop = true; if(displayFlag){ cout<<"<Relop> ::= <=" << endl; printproduction("<Relop> ::= <="); } }else error("Missing Relop"); cout<<endl; return Relop; }
bool syntaxparser::Write(){ bool bWrite = false; if (lexeme == "write"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<Write> ::= write ( <Expression> );" << endl; printproduction("<Write> ::= write ( <Expression> );"); } if (lexeme == "("){ print(); cout<<endl; Lexer(); Expression(); if (lexeme == ")"){ print(); cout<<endl; Lexer(); if (lexeme == ";"){ print(); cout<<endl; project3.gen_inst("POPSTD", ""); //give the second parameter a nil value Lexer(); bWrite = true; }else error("Missing ';'"); }else error("Missing ')'"); } } return bWrite; }
void syntaxparser::Rat10F(){ setDisplay(); Lexer(); print(); if( lexeme == "$$"){ if (displayFlag){ //cout << "<Rat10F> ::= $$<Opt Function Definitions> $$ <Opt Declaration List> <Statement List> $$" << endl; //printproduction("<Rat10F> ::= $$<Opt Function Definitions> $$ <Opt Declaration List> <Statement List> $$"); cout << "<Rat10F> ::= $$ $$ <Opt Declaration List> <Statement List> $$" << endl; printproduction("<Rat10F> ::= $$ $$ <Opt Declaration List> <Statement List> $$"); } //OptFunctionDefinitions(); Lexer(); if( lexeme == "$$"){ Lexer(); OptDeclarationList(); project3.StopAddingtoSymbolTable(); StatementList(); //project3.printsymboltable(assemblyfilename); project3.printInstTable(assemblyfilename); // printing the project3 instruction table to file if( lexeme == "$$"){ print(); cout<<"========>>>>> Syntax is Correct! <<<<<=========="<<endl; } else if( lexeme != "$$") error("Missing Finishing $$"); } else if( lexeme != "$$") error("Missing $$ after Function definitions"); } else if( lexeme != "$$") error("Missing $$"); }
bool syntaxparser::ParameterList(){ bool bParameterList= false, flag=false; if (displayFlag){ cout << "<Parameter List> ::= <Parameter> , <Parameter List>"<< endl; printproduction("<Parameter List> ::= <Parameter> , <Parameter List>"); } Parameter(); if(lexeme ==","){ Lexer(); // if we have a comma then we recursively call for more additional parameters ParameterList(); } bParameterList= true; return bParameterList; }
bool syntaxparser::Return(){ bool bReturn = false; if (lexeme == "return"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<Return> ::= return;" << endl; printproduction("<Return> ::= return;"); } if (lexeme == ";"){ print(); cout<<endl; Lexer(); bReturn = true; } else { Expression(); if (lexeme == ";"){ print(); cout<<endl; Lexer(); bReturn = true; if(displayFlag){ cout << "<Return> ::= return <Expression>;" << endl; printproduction("<Return> ::= return <Expression>;"); } }else error("Missing ';'"); } } return bReturn; }
void XSDParser::ParseAttribute(DTDElement& node) { DTDAttribute a; node.AddAttribute(a); DTDAttribute& att = node.GetNonconstAttributes().back(); att.SetSourceLine(Lexer().CurrentLine()); SetCommentsIfEmpty(&(att.Comments())); bool ref=false, named_type=false; bool qualified = m_AttributeFormDefault; TToken tok = GetRawAttributeSet(); if (GetAttribute("ref")) { att.SetName(m_Value); ref=true; } if (GetAttribute("name")) { att.SetName(m_Value); } if (GetAttribute("type")) { if (!DefineAttributeType(att)) { att.SetTypeName(m_Value); named_type = true; } } if (GetAttribute("use")) { if (IsValue("required")) { att.SetValueType(DTDAttribute::eRequired); } else if (IsValue("optional")) { att.SetValueType(DTDAttribute::eImplied); } else if (IsValue("prohibited")) { att.SetValueType(DTDAttribute::eProhibited); } } if (GetAttribute("default")) { att.SetValue(m_Value); } if (GetAttribute("form")) { qualified = IsValue("qualified"); } att.SetQualified(qualified); if (tok == K_CLOSING) { ParseContent(att); } if (!ref && !named_type) { att.SetTypeIfUnknown(DTDAttribute::eString); } m_ExpectLastComment = true; }
void XSDParser::ParseDocumentation(void) { TToken tok = GetRawAttributeSet(); if (tok == K_ENDOFTAG) { return; } if (tok == K_CLOSING) { XSDLexer& l = dynamic_cast<XSDLexer&>(Lexer()); while (l.ProcessDocumentation()) ; } tok = GetNextToken(); if (tok != K_ENDOFTAG) { ParseError("endoftag"); } m_ExpectLastComment = true; }
bool syntaxparser::Parameter(){ bool Parameter = false; if (displayFlag){ cout<<"<Parameter> ::= <IDS> : <Qualifier>"<<endl; printproduction("<Parameter> ::= <IDS> : <Qualifier>"); } IDs(); if(lexeme ==":"){ print(); //print the colon Lexer(); //get next token Qualifier(); Parameter = true; }else{ error("Missing ':'"); } return Parameter; }
bool syntaxparser::Qualifier(){ bool bQualifier = false; if(displayFlag){ cout << "<Qualifier> ::= " << lexeme << endl; printproduction("<Qualifier> ::= " + lexeme); } if (lexeme == "int" || lexeme =="boolean") { project3.addType(lexeme); print(); bQualifier = true; Lexer(); } else if (lexeme == "real"){ error("The 'real' type is not valid for Rat10F"); } return bQualifier; }
bool syntaxparser::OptFunctionDefinitions(){ bool OptFunctionDefinitions =false; Lexer(); //check to see if the next lexeme is a function if (lexeme == "function"){ if (displayFlag){ cout<<"<Opt Function Definitions> ::= <FunctionDefinitions>"<<endl; printproduction("<Opt Function Definitions> ::= <FunctionDefinitions>"); } OptFunctionDefinitions = true; FunctionDefinitions(); // call the function } else{ // if no optional function definitions then its empty if (displayFlag){ cout<<"<Opt Function Definitions> ::= <Empty>"<<endl; printproduction("<Opt Function Definitions> ::= <Empty>"); } Empty(); //call the empty function OptFunctionDefinitions= true; } return OptFunctionDefinitions; }
// Purpose: Tests the production rule for Factor bool syntaxparser::Factor(){ bool Factor = false; if(lexeme == "-"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout<<"<Factor> ::= -<Primary>"<<endl; printproduction("<Factor> ::= -<Primary>"); } Primary(); Factor = true; }else { if(displayFlag){ cout<<"<Factor> ::= <Primary>"<<endl; printproduction("<Factor> ::= <Primary>"); } Primary(); Factor = true; } return Factor; }
void XSDParser::ParseAttributeGroup(DTDElement& node) { TToken tok = GetRawAttributeSet(); if (GetAttribute("ref")) { if (m_ResolveTypes) { string id = CreateEntityId(m_Value,DTDEntity::eAttGroup); if (m_MapEntity.find(id) != m_MapEntity.end()) { PushEntityLexer(id); ParseAttributeGroupRef(node); } else { ParseError("Unresolved entity", id.c_str()); } } else { DTDAttribute a; a.SetType(DTDAttribute::eUnknownGroup); a.SetTypeName(m_Value); Lexer().FlushCommentsTo(node.AttribComments()); node.AddAttribute(a); } } if (tok == K_CLOSING) { ParseContent(node); } }
void AbstractParser::CopyLineComment(int line, CComments& comments, int flags) { if ( !(flags & eNoFetchNext) ) Lexer().FillComments(); _TRACE("CopyLineComment("<<line<<") current: "<<Lexer().CurrentLine()); _TRACE(" "<<(Lexer().HaveComments()?Lexer().NextComment().GetLine():-1)); while ( Lexer().HaveComments() ) { const AbstractLexer::CComment& c = Lexer().NextComment(); if ( c.GetLine() > line ) { // next comment is below limit line return; } if ( c.GetLine() == line && (flags & eCombineNext) ) { // current comment is on limit line -> allow next line comment ++line; } comments.Add(c.GetValue()); Lexer().SkipNextComment(); } }
bool XSDParser::ParseContent(DTDElement& node, bool extended /*=false*/) { DTDElement::EType curr_type; int emb=0; bool eatEOT= false; bool hasContents= false; TToken tok; for ( tok=GetNextToken(); ; tok=GetNextToken()) { emb= node.GetContent().size(); if (tok != T_EOF && tok != K_ENDOFTAG && tok != K_ANNOTATION) { hasContents= true; } switch (tok) { case T_EOF: return hasContents; case K_ENDOFTAG: if (eatEOT) { eatEOT= false; break; } FixEmbeddedNames(node); return hasContents; case K_COMPLEXTYPE: ParseComplexType(node); break; case K_SIMPLECONTENT: ParseSimpleContent(node); break; case K_EXTENSION: ParseExtension(node); break; case K_RESTRICTION: ParseRestriction(node); break; case K_ATTRIBUTE: ParseAttribute(node); break; case K_ATTRIBUTEGROUP: ParseAttributeGroup(node); break; case K_ANY: node.SetTypeIfUnknown(DTDElement::eSequence); { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eAny); elem.SetQualified(node.IsQualified()); ParseAny(elem); AddElementContent(node,name); } break; case K_SEQUENCE: emb= node.GetContent().size(); if (emb != 0 && extended) { node.SetTypeIfUnknown(DTDElement::eSequence); if (node.GetType() != DTDElement::eSequence) { ParseError("sequence"); } tok = GetRawAttributeSet(); eatEOT = true; break; } curr_type = node.GetType(); if (curr_type == DTDElement::eUnknown || curr_type == DTDElement::eUnknownGroup || (m_ResolveTypes && curr_type == DTDElement::eEmpty)) { node.SetType(DTDElement::eSequence); ParseContainer(node); if (node.GetContent().empty()) { node.ResetType(curr_type); } } else { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eSequence); elem.SetQualified(node.IsQualified()); ParseContainer(elem); AddElementContent(node,name); } break; case K_CHOICE: curr_type = node.GetType(); if (curr_type == DTDElement::eUnknown || curr_type == DTDElement::eUnknownGroup || (m_ResolveTypes && curr_type == DTDElement::eEmpty)) { node.SetType(DTDElement::eChoice); ParseContainer(node); if (node.GetContent().empty()) { node.ResetType(curr_type); } } else { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eChoice); elem.SetQualified(node.IsQualified()); ParseContainer(elem); AddElementContent(node,name); } break; case K_SET: curr_type = node.GetType(); if (curr_type == DTDElement::eUnknown || curr_type == DTDElement::eUnknownGroup || (m_ResolveTypes && curr_type == DTDElement::eEmpty)) { node.SetType(DTDElement::eSet); ParseContainer(node); if (node.GetContent().empty()) { node.ResetType(curr_type); } } else { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eSet); elem.SetQualified(node.IsQualified()); ParseContainer(elem); AddElementContent(node,name); } break; case K_ELEMENT: { string name = ParseElementContent(&node,emb); AddElementContent(node,name); } break; case K_GROUP: { string name = ParseGroup(&node,emb); AddElementContent(node,name); } break; case K_ANNOTATION: SetCommentsIfEmpty(&(node.Comments())); ParseAnnotation(); break; case K_UNION: ParseUnion(node); break; case K_LIST: ParseList(node); break; default: for ( tok = GetNextToken(); tok == K_ATTPAIR || tok == K_XMLNS; tok = GetNextToken()) ; if (tok == K_CLOSING) { ParseContent(node); } break; } } FixEmbeddedNames(node); return hasContents; }
string XSDParser::ParseElementContent(DTDElement* owner, int emb) { TToken tok; string name, value; bool ref=false, named_type=false; bool qualified = m_ElementFormDefault; int line = Lexer().CurrentLine(); tok = GetRawAttributeSet(); if (GetAttribute("ref")) { if (IsValue("schema") && GetElementNamespace(m_ValuePrefix) == eSchemaNamespace) { name = CreateTmpEmbeddedName(owner->GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(m_Value); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eAny); ref=false; } else { name = m_Value; ref=true; } } if (GetAttribute("name")) { ref=false; name = m_Value; if (owner) { name = CreateTmpEmbeddedName(owner->GetName(), emb); m_MapElement[name].SetEmbedded(); m_MapElement[name].SetNamed(); } m_MapElement[name].SetName(m_Value); m_MapElement[name].SetSourceLine(line); SetCommentsIfEmpty(&(m_MapElement[name].Comments())); } if (GetAttribute("type")) { if (!DefineElementType(m_MapElement[name])) { m_MapElement[name].SetTypeName(m_Value); named_type = true; } } if (owner && GetAttribute("form")) { qualified = IsValue("qualified"); } if (GetAttribute("default")) { m_MapElement[name].SetDefault(m_Value); } if (owner && !name.empty()) { owner->SetOccurrence(name, ParseMinOccurs( owner->GetOccurrence(name))); owner->SetOccurrence(name, ParseMaxOccurs( owner->GetOccurrence(name))); } if (tok != K_CLOSING && tok != K_ENDOFTAG) { ParseError("endoftag"); } m_MapElement[name].SetNamespaceName(m_TargetNamespace); m_MapElement[name].SetQualified(qualified); bool hasContents = false; if (tok == K_CLOSING) { hasContents = ParseContent(m_MapElement[name]); } m_ExpectLastComment = true; if (!ref && !named_type) { m_MapElement[name].SetTypeIfUnknown( hasContents ? DTDElement::eEmpty : DTDElement::eString); } return name; }
void XSDParser::ParseTypeDefinition(DTDEntity& ent) { string data = ent.GetData(); string closing; TToken tok; CComments comments; bool doctag_open = false; for ( tok=GetNextToken(); tok != K_ENDOFTAG; tok=GetNextToken()) { if (tok == T_EOF) { break; } { CComments comm; Lexer().FlushCommentsTo(comm); if (!comm.Empty()) { CNcbiOstrstream buffer; comm.PrintDTD(buffer); data += CNcbiOstrstreamToString(buffer); data += closing; closing.erase(); } if (!closing.empty()) { if (!comments.Empty()) { CNcbiOstrstream buffer; comments.Print(buffer, "", "\n", ""); data += CNcbiOstrstreamToString(buffer); comments = CComments(); } data += closing; closing.erase(); doctag_open = false; } } if (tok == K_DOCUMENTATION) { if (!doctag_open) { data += "<" + m_Raw; } m_Comments = &comments; ParseDocumentation(); if (!doctag_open) { if (m_Raw == "/>") { data += "/>"; closing.erase(); } else { data += ">"; closing = m_Raw; doctag_open = true; } } } else if (tok == K_APPINFO) { ParseAppInfo(); } else { data += "<" + m_Raw; for ( tok = GetNextToken(); tok == K_ATTPAIR || tok == K_XMLNS; tok = GetNextToken()) { data += " " + m_Raw; } data += m_Raw; } if (tok == K_CLOSING) { ent.SetData(data); ParseTypeDefinition(ent); data = ent.GetData(); } } if (!comments.Empty()) { CNcbiOstrstream buffer; comments.Print(buffer, "", "\n", ""); data += CNcbiOstrstreamToString(buffer); data += closing; } data += '\n'; data += m_Raw; ent.SetData(data); }