%top { #include "grammar.h" } %{ #include "manual.h" %} %option noyywrap %option yylineno %option stack %option noyy_top_state %x comments %x ins_name try_details ins_details %x encoding encoding_type encoding_content syntax_content %x encoding_bits encoding_bits_size %x top_brace %x raw_line raw_block %% [ \t\n]+ { } "/*" { BEGIN(comments); } "*/" { BEGIN(INITIAL); } [^*\n] { } "Copyright"[^\n]* { yylvalp->string = strdup(yytext); return COPYRIGHT; } "*" { } "\n" { } "@title" { BEGIN(ins_name); return TITLE; } [ ][A-Za-z0-9-]+ { yylvalp->string = strdup(yytext + 1); BEGIN(try_details); return INS_NAME; } [ ,/-] { BEGIN(ins_details); yylvalp->character = yytext[0]; return INS_SEP; } [\n] { BEGIN(INITIAL); } [^\n]* { yylvalp->cstring = yytext; return INS_DETAILS; } [\n] { BEGIN(INITIAL); } "@id" { yy_push_state(raw_line); return ID; } "@desc" { yy_push_state(raw_block); return DESC; } "@encoding" { yy_push_state(encoding); return ENCODING; } [ ] { } "(" { yy_push_state(encoding_type); } [A-Za-z] { yylvalp->string = strdup(yytext); return TYPE; } [0-9]+ { yylvalp->integer = atoi(yytext); return NUMBER; } ")" { yy_pop_state(); } "{" { yy_push_state(encoding_content); } [ \t\n]+ { } "}" { yy_pop_state(); yy_pop_state(); } "@format" { yy_push_state(raw_line); return FORMAT; } "@unused" { yy_push_state(raw_line); return UNUSED; } "@half" { yy_push_state(raw_line); return HALF; } "@word" { yy_push_state(raw_line); return WORD; } "@syntax" { yy_push_state(syntax_content); yy_push_state(top_brace); return SYNTAX; } "@hooks" { yy_push_state(raw_block); return HOOKS; } [ \t\n]+ { } "@subid" { yy_push_state(raw_line); return SUBID; } "@assert" { yy_push_state(raw_block); return ASSERT; } "@conv" { yy_push_state(raw_block); return CONV; } "@asm" { yy_push_state(raw_line); return ASM; } "@rules" { yy_push_state(raw_block); return RULES; } "}" { yy_pop_state(); } [ \t\n]+ { } "{" { yy_pop_state(); } [^\n]+ { yylvalp->cstring = yytext; return RAW_LINE; } "\n" { yy_pop_state(); } [ \t\n]+ { } "{" { read_block(temp); yylvalp->cstring = temp; return RAW_BLOCK; } "}" { yy_pop_state(); } "{" { read_block(temp); yylvalp->cstring = temp; return RAW_BLOCK; } <*>. { char *msg; asprintf(&msg, "Unhandled token in d2c definition: '%s'", yytext); YY_FATAL_ERROR(msg); free(msg); } %%