%{ typedef struct _rented_coder rented_coder; #include "d2c-d2c_gram.h" #include #include /* Tente de libérer autant de mémoire que possible... */ void free_flex_memory(void) ; %} %option noyywrap %option nounput %option noinput %option yylineno %option stack %option noyy_top_state %x comments %x ins_name try_details ins_details %x encoding encoding_type encoding_content %x encoding_bits encoding_bits_size %x syntax syntax_name syntax_int syntax_ext %x conv_begin conv_content conv_arg conv_arg_binval %x arg arg_binval %x hooks_begin hooks_content %x rules_begin rules_content rules_cond rules_cond_binval rules_cond_hexval rules_action rules_action_see rules_action_call %% [ \t\n]+ { } "/*" { BEGIN(comments); } "*/" { BEGIN(INITIAL); } [^*\n] { } "Copyright"[^\n]* { d2c_lval.string = strdup(yytext); return COPYRIGHT; } "*" { } "\n" { } "@title" { BEGIN(ins_name); return TITLE; } [ ][A-Za-z-]+ { d2c_lval.string = strdup(yytext + 1); BEGIN(try_details); return INS_NAME; } [ ,/] { BEGIN(ins_details); } [\n] { BEGIN(INITIAL); } [^\n]* { d2c_lval.cstring = yytext; return INS_DETAILS; } [\n] { BEGIN(INITIAL); } "@encoding" { BEGIN(encoding); return ENCODING; } [ ] { } "(" { BEGIN(encoding_type); } [A-Za-z] { d2c_lval.string = strdup(yytext); return TYPE; } [0-9]+ { d2c_lval.integer = atoi(yytext); return NUMBER; } ")" { BEGIN(encoding); } "{" { BEGIN(encoding_content); } [ \t\n]+ { } "}" { BEGIN(INITIAL); } "@half" { BEGIN(encoding_bits); return HALF; } "@word" { BEGIN(encoding_bits); return WORD; } " " { } "\n" { BEGIN(encoding_content); } [A-Za-z_][A-Za-z0-9__]* { d2c_lval.string = strdup(yytext); return NAME; } "(" { BEGIN(encoding_bits_size); } [0-9]+ { d2c_lval.integer = atoi(yytext); return SIZE; } ")" { BEGIN(encoding_bits); } [01] { d2c_lval.integer = atoi(yytext); return BIT; } "@syntax" { BEGIN(syntax); return SYNTAX; } [ ]+ { } "\n" { BEGIN(encoding_content); } [\"] { BEGIN(syntax_name); } [^ \n\"]+ { d2c_lval.string = strdup(yytext); return OPERAND_NAME; } [\"] { BEGIN(syntax); } "{" { BEGIN(syntax_int); } [^ \n}]+ { d2c_lval.string = strdup(yytext); return OPERAND_INTERNAL; } "}" { BEGIN(syntax); } "<" { BEGIN(syntax_ext); } [^ \n>]+ { d2c_lval.string = strdup(yytext); return OPERAND_VISIBLE; } ">" { BEGIN(syntax); } "@conv" { BEGIN(conv_begin); return CONV; } [ ]+ { } "{" { BEGIN(conv_content); } "}" { BEGIN(encoding_content); } [ \t\n]+ { } [A-Za-z_][A-Za-z0-9_]* { if (strcmp(yytext, "NOT") == 0) return NOT; else { d2c_lval.string = strdup(yytext); return NAME; } } "=" { return EQ; } "(" { BEGIN(conv_arg); return OP; } [A-Za-z_][A-Za-z0-9_]* { if (strcmp(yytext, "NOT") == 0) return NOT; else if (strcmp(yytext, "AND") == 0) return AND_LOG; else if (strcmp(yytext, "EOR") == 0) return EOR; else { d2c_lval.string = strdup(yytext); return NAME; } } [0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; } "'" { BEGIN(conv_arg_binval); } [01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; } "'" { BEGIN(conv_arg); } "," { return COMMA; } ":" { return COLON; } [ ]+ { } ")" { BEGIN(conv_content); return CP; } [A-Za-z_][A-Za-z0-9_]* { if (strcmp(yytext, "NOT") == 0) return NOT; else if (strcmp(yytext, "AND") == 0) return AND_LOG; else if (strcmp(yytext, "EOR") == 0) return EOR; else { d2c_lval.string = strdup(yytext); return NAME; } } [0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; } "'" { BEGIN(arg_binval); } [01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; } "'" { BEGIN(arg); } "," { return COMMA; } ":" { return COLON; } [ ]+ { } ")" { yy_pop_state(); return CP; } "@hooks" { BEGIN(hooks_begin); return HOOKS; } [ ]+ { } "{" { BEGIN(hooks_content); } "}" { BEGIN(encoding_content); } [ \t\n]+ { } [a-z_][a-z0-9_]* { d2c_lval.string = strdup(yytext); return NAME; } "=" { return EQ; } "@rules" { BEGIN(rules_begin); return RULES; } \/\/[^\n]+ { printf("SKIP '%s'\n", yytext); } [ ]+ { } "{" { BEGIN(rules_content); } [ \t\n]+ { } "}" { BEGIN(encoding_content); } "see " { BEGIN(rules_action_see); return SEE; } "unpredictable" { return UNPREDICTABLE; } "call" { BEGIN(rules_action_call); return CALL; } "chk_call" { BEGIN(rules_action_call); return CHK_CALL; } "if" { BEGIN(rules_cond); return IF; } [ ]+ { } "(" { return EXPR_START; } [A-Za-z_][A-Za-z0-9_]* { d2c_lval.string = strdup(yytext); return NAME; } "==" { return EQUAL; } "'" { BEGIN(rules_cond_binval); } [01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; } "'" { BEGIN(rules_cond); } "0x" { BEGIN(rules_cond_hexval); } [0-9a-f][0-9a-f]* { d2c_lval.string = strdup(yytext); BEGIN(rules_cond); return HEXVAL; } ")" { return EXPR_END; } "&&" { return AND; } "&" { return AND_LOG; } ";" { BEGIN(rules_action); return THEN; } [ ]+ { } "see " { BEGIN(rules_action_see); return SEE; } [^\n]* { d2c_lval.cstring = yytext; BEGIN(rules_content); return INS_DETAILS; } "unpredictable" { BEGIN(rules_content); return UNPREDICTABLE; } "call" { BEGIN(rules_action_call); return CALL; } "chk_call" { BEGIN(rules_action_call); return CHK_CALL; } [\t ]+ { } [A-Za-z_][A-Za-z0-9_]* { d2c_lval.string = strdup(yytext); return NAME; } "(" { yy_push_state(arg); return OP; } [\n] { BEGIN(rules_content); } %% /****************************************************************************** * * * Paramètres : - * * * * Description : Tente de libérer autant de mémoire que possible... * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ void free_flex_memory(void) { yy_delete_buffer(YY_CURRENT_BUFFER); }