%{ /* * WARNING: This is not an XML 1.0 parser, but an experiment with an XML-like * language. See http://www.w3.org/XML/9707/XML-in-C * * Author: Bert Bos * Created: 9 July 1997 * * Copyright © 1997-2004 World Wide Web Consortium * See http://www.w3.org/Consortium/Legal/copyright-software-19980720.html */ #include extern char yytext[]; %} %union {char *s;} %token VERSION ATTDEF ENDDEF EQ SLASH CLOSE END %token ENCODING NAME VALUE DATA COMMENT START %type name_opt %% document : prolog element misc_seq_opt ; prolog : version_opt encoding_opt misc_seq_opt ; version_opt : VERSION {printf("\n");} | /*empty*/ ; encoding_opt : ENCODING {printf("\n",$1); free($1);} | /*empty*/ ; misc_seq_opt : misc_seq_opt misc | /*empty*/ ; misc : COMMENT {printf("%s", $1);} | attribute_decl ; attribute_decl : ATTDEF NAME {printf("\n\n");} ; element : START {printf("\n<%s", $1); free($1);} attribute_seq_opt empty_or_content ; empty_or_content : SLASH CLOSE {printf("/>\n");} | CLOSE {printf(">\n");} content END name_opt CLOSE {printf("\n\n", $5); free($5);} ; content : content DATA {printf("%s", $2); free($2);} | content misc | content element | /*empty*/ ; name_opt : NAME {$$ = $1;} | /*empty*/ {$$ = strdup("");} ; attribute_seq_opt : attribute_seq_opt attribute | /*empty*/ ; attribute : NAME {printf(" %s", $1); free($1);} | NAME EQ VALUE {printf(" %s=%s", $1, $3); free($1); free($3);} ;