📄 mod_yacc.y
字号:
{ return check_id (sub_id, kind, TRUE);}/*---------------------------------------------------------------------------*/static void init_buffer (){ buf_len = 0; buffer[0] = '\0';}/*---------------------------------------------------------------------------*/static void append (char *str){ int len = strlen (str); if (len + buf_len > BUFFER_SIZE) { yyerror ("Buffer overflow - try reducing the complexity of CM-macro array subscripts"); exit (1); } (void)strcat (buffer,str);}%}%union { char *str; Sub_Id_t sub_id;}%type <str> buffered_c_code%type <sub_id> subscriptable_id id%token TOK_ARGS%token TOK_INIT%token TOK_ANALYSIS%token TOK_NEW_TIMEPOINT%token TOK_TIME%token TOK_RAD_FREQ%token TOK_TEMPERATURE%token TOK_T %token TOK_PARAM %token TOK_PARAM_SIZE %token TOK_PARAM_NULL %token TOK_PORT_SIZE %token TOK_PORT_NULL %token TOK_PARTIAL %token TOK_AC_GAIN%token TOK_CHANGED%token TOK_OUTPUT_DELAY %token TOK_STATIC_VAR %token TOK_STATIC_VAR_SIZE%token TOK_INPUT%token TOK_INPUT_STRENGTH%token TOK_INPUT_STATE%token TOK_INPUT_TYPE%token TOK_OUTPUT%token TOK_OUTPUT_CHANGED%token TOK_OUTPUT_STRENGTH%token TOK_OUTPUT_STATE%token TOK_OUTPUT_TYPE%token TOK_COMMA%token TOK_LPAREN%token TOK_RPAREN%token TOK_LBRACKET%token TOK_RBRACKET%token TOK_MISC_C%token TOK_IDENTIFIER%token TOK_LOAD%token TOK_TOTAL_LOAD%token TOK_MESSAGE%token TOK_CALL_TYPE%start mod_file%%mod_file : /* empty */ | mod_file c_code ; c_code : /* empty */ | c_code c_char | c_code macro /*| TOK_RPAREN {yyerror ("Unmatched )"); YYERROR;} | TOK_RBRACKET {yyerror ("Unmatched ]"); YYERROR;}*/ ;buffered_c_code : {init_buffer();} buffered_c_code2 {$$ = strdup (buffer);} ;buffered_c_code2 : /* empty */ | buffered_c_code2 buffered_c_char ;buffered_c_char : TOK_IDENTIFIER {append (mod_yytext);} | TOK_MISC_C {append (mod_yytext);} | TOK_COMMA {append (mod_yytext);} | TOK_LBRACKET {append("[");} buffered_c_code2 TOK_RBRACKET {append("]");} | TOK_LPAREN {append("(");} buffered_c_code2 TOK_RPAREN {append(")");} ;c_char : TOK_IDENTIFIER {fputs (mod_yytext, mod_yyout);} | TOK_MISC_C {fputs (mod_yytext, mod_yyout);} | TOK_COMMA {fputs (mod_yytext, mod_yyout);} | TOK_LBRACKET {putc ('[', mod_yyout);} c_code TOK_RBRACKET {putc (']', mod_yyout);} | TOK_LPAREN {putc ('(', mod_yyout);} c_code TOK_RPAREN {putc (')', mod_yyout);} ;macro : TOK_INIT {fprintf (mod_yyout, "private->circuit.init");} | TOK_ARGS {fprintf (mod_yyout, "Mif_Private_t *private");} | TOK_ANALYSIS {fprintf (mod_yyout, "private->circuit.anal_type");} | TOK_NEW_TIMEPOINT {fprintf (mod_yyout, "private->circuit.anal_init");} | TOK_CALL_TYPE {fprintf (mod_yyout, "private->circuit.call_type");} | TOK_TIME {fprintf (mod_yyout, "private->circuit.time");} | TOK_RAD_FREQ {fprintf (mod_yyout, "private->circuit.frequency");} | TOK_TEMPERATURE {fprintf (mod_yyout, "private->circuit.temperature");} | TOK_T TOK_LPAREN buffered_c_code TOK_RPAREN {fprintf (mod_yyout, "private->circuit.t[%s]", $3);} | TOK_PARAM TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, PARAM); fprintf (mod_yyout, "private->param[%d]->element[%s]", i, subscript ($3)); put_type (mod_yyout, mod_ifs_table->param[i].type); } | TOK_PARAM_SIZE TOK_LPAREN id TOK_RPAREN {int i = valid_id ($3, PARAM); fprintf (mod_yyout, "private->param[%d]->size", i);} | TOK_PARAM_NULL TOK_LPAREN id TOK_RPAREN {int i = valid_id ($3, PARAM); fprintf (mod_yyout, "private->param[%d]->is_null", i);} | TOK_PORT_SIZE TOK_LPAREN id TOK_RPAREN {int i = valid_id ($3, CONN); fprintf (mod_yyout, "private->conn[%d]->size", i);} | TOK_PORT_NULL TOK_LPAREN id TOK_RPAREN {int i = valid_id ($3, CONN); fprintf (mod_yyout, "private->conn[%d]->is_null", i);} | TOK_PARTIAL TOK_LPAREN subscriptable_id TOK_COMMA subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); int j = valid_subid ($5, CONN); check_dir (i, OUT, "PARTIAL"); check_dir (j, IN, "PARTIAL"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->partial[%d].port[%s]", i, subscript($3), j, subscript($5));} | TOK_AC_GAIN TOK_LPAREN subscriptable_id TOK_COMMA subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); int j = valid_subid ($5, CONN); check_dir (i, OUT, "AC_GAIN"); check_dir (j, IN, "AC_GAIN"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->ac_gain[%d].port[%s]", i, subscript($3), j, subscript($5));} | TOK_STATIC_VAR TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, STATIC_VAR); fprintf (mod_yyout, "private->inst_var[%d]->element[%s]", i, subscript($3)); if (mod_ifs_table->inst_var[i].is_array && !($3.has_subscript)) { /* null - eg. for malloc lvalue */ } else { put_type (mod_yyout, mod_ifs_table->inst_var[i].type); } } | TOK_STATIC_VAR_SIZE TOK_LPAREN id TOK_RPAREN {int i = valid_subid ($3, STATIC_VAR); fprintf (mod_yyout, "private->inst_var[%d]->size", i, subscript($3));} | TOK_OUTPUT_DELAY TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, OUT, "OUTPUT_DELAY"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->delay", i, subscript($3));} | TOK_CHANGED TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, OUT, "CHANGED"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->changed", i, subscript($3));} | TOK_INPUT TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, IN, "INPUT"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->input", i, subscript($3)); put_conn_type (mod_yyout, mod_ifs_table->conn[i].allowed_port_type[0]);} | TOK_INPUT_TYPE TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, IN, "INPUT_TYPE"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->type_str", i, subscript($3)); } | TOK_OUTPUT_TYPE TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, OUT, "OUTPUT_TYPE"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->type_str", i, subscript($3)); } | TOK_INPUT_STRENGTH TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, IN, "INPUT_STRENGTH"); fprintf (mod_yyout, "((Digital_t*)(private->conn[%d]->port[%s]->input", i, subscript($3)); put_conn_type (mod_yyout, mod_ifs_table->conn[i].allowed_port_type[0]); fprintf (mod_yyout, "))->strength");} | TOK_INPUT_STATE TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, IN, "INPUT_STATE"); fprintf (mod_yyout, "((Digital_t*)(private->conn[%d]->port[%s]->input", i, subscript($3)); put_conn_type (mod_yyout, mod_ifs_table->conn[i].allowed_port_type[0]); fprintf (mod_yyout, "))->state");} | TOK_OUTPUT TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, OUT, "OUTPUT"); fprintf (mod_yyout, "private->conn[%d]->port[%s]->output", i, subscript($3)); put_conn_type (mod_yyout, mod_ifs_table->conn[i].allowed_port_type[0]);} | TOK_OUTPUT_STRENGTH TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, OUT, "OUTPUT_STRENGTH"); fprintf (mod_yyout, "((Digital_t*)(private->conn[%d]->port[%s]->output", i, subscript($3)); put_conn_type (mod_yyout, mod_ifs_table->conn[i].allowed_port_type[0]); fprintf (mod_yyout, "))->strength");} | TOK_OUTPUT_STATE TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); check_dir (i, OUT, "OUTPUT_STATE"); fprintf (mod_yyout, "((Digital_t*)(private->conn[%d]->port[%s]->output", i, subscript($3)); put_conn_type (mod_yyout, mod_ifs_table->conn[i].allowed_port_type[0]); fprintf (mod_yyout, "))->state");} | TOK_OUTPUT_CHANGED TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); fprintf (mod_yyout, "private->conn[%d]->port[%s]->changed", i, subscript($3));} | TOK_LOAD TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); fprintf (mod_yyout, "private->conn[%d]->port[%s]->load", i, subscript($3));} | TOK_TOTAL_LOAD TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); fprintf (mod_yyout, "private->conn[%d]->port[%s]->total_load", i, subscript($3));} | TOK_MESSAGE TOK_LPAREN subscriptable_id TOK_RPAREN {int i = valid_subid ($3, CONN); fprintf (mod_yyout, "private->conn[%d]->port[%s]->msg", i, subscript($3));} ;subscriptable_id : id | id TOK_LBRACKET buffered_c_code TOK_RBRACKET {$$ = $1; $$.has_subscript = TRUE; $$.subscript = $3;} ;id : TOK_IDENTIFIER {$$.has_subscript = FALSE; $$.id = strdup (mod_yytext);} ;%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -