%{ #include #include #include "xmldata.h" extern int yylineno; %} %union{ char *str; AttrList alist; TextNodePtr tnode; ElemNodePtr enode; NodePtr node; } %token ID ATTRVAL TEXT BELEMENT EELEMENT BPI EPI %start DocXml %type ID ATTRVAL TEXT EELEMENT %type Attr AttrList %type NodeList Node BElement EmptyElement %% DocXml : Declaration DocumentAbstractTree { printf("Reconheci um Documento XML!!!\n"); }; Declaration : BPI ID AttrList EPI { printf("PI%s\n",$2); showAttrList($3); }; AttrList : AttrList Attr { $$ = add2AttrList($1,$2); } | { $$ = NULL; } ; Attr : ID '=' ATTRVAL { $$ = consAttrList($1,$3,NULL); }; BElement : ID AttrList { $$ = consNodefromElem(consElemNode($1,$2,NULL,NULL)); }; DocumentAbstractTree : BElement NodeList EELEMENT { $1->val.e->child = $2; showNodeESIS($1); }; NodeList : NodeList Node { $$ = add2NodeList($1,$2); } | Node { $$ = $1; } ; Node : TEXT { $$ = consNodefromText(consTextNode($1,NULL)); /* contents,sibling */ } | BElement NodeList EELEMENT { $1->val.e->child = $2; /* add child list */ $$ = $1; } | EmptyElement { $$ = $1; } ; EmptyElement : BElement EEMPTY { $$ = $1; }; %% int main() { yyparse(); } void yyerror(char *s) { printf("%s near %d",s,yylineno); }