%{ #include #include "y.tab.h" char *copy_str(char *); int line_num; %} S \x20\x0a\x0d\x09 DATE [0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[A-Z]* %start STRING %% "" { return PROLOG; } [\x20\x0a\x0d\x09] { if (*yytext == '\n') { line_num += 1; } } "<" { return S_TAG_OPEN; } "">" { return TAG_CLOSE; } "/>" { return EMPTY_TAG_CLOSE; } [a-zA-Z_:][a-zA-Z0-9\.\-_:]* { yylval.sval = copy_str(yytext); return NAME; } "=" { return *yytext; } "\"" { BEGIN(STRING); return *yytext; } "\"" { BEGIN(INITIAL); return *yytext; } [^"] { yylval.cval = *yytext; return CHAR; } -?[0-9]+ { yylval.lval = strtol(yytext, NULL, 10); return INTEGER; } -?[0-9]+\.?[0-9]* { yylval.dval = strtod(yytext, NULL); return DOUBLE; } {DATE} { return DATE; } %% char * copy_str(char *str) { size_t len = strlen(str) + 1; char *copy = malloc(sizeof(char) * len); strncpy(copy, str, len); return copy; }