📄 macedon.y
字号:
messages1: MESSAGES OBRACE { start_messages(); } ;messages2: messages_recur CBRACE { done_messages(); } ;messages_recur: message | messages_recur message ;message: message1 message2 ; message1: id OBRACE { message_str = $1; add_message ($1, 0); } | id id OBRACE { message_str = $2; add_message ($2, $1); } ;message2: fields_recur CBRACE { } | CBRACE { } ;fields_recur: field { } | fields_recur field { } ;field: INT id SEMI{ add_message_field (message_str, "int", $2, "1", 0); } | DOUBLE id SEMI{ add_message_field (message_str, "double", $2, "1", 0); } | INT id id SEMI{ add_message_field (message_str, "int", $2, $3, 0); } | DOUBLE id id SEMI{ add_message_field (message_str, "double", $2, $3, 0); } | STRING id SEMI{ add_message_field (message_str, "char *", $2, "1", 0); } | id id SEMI { add_message_field (message_str, $1, $2, "1", 0); } | id id OPAREN id CPAREN SEMI { add_message_field (message_str, $1, $2, "1", $4); } | id id id SEMI { add_message_field (message_str, $1, $2, $3, 0); } ;transitions: transitions1 transitions2 { parse_stage = PARSE_INIT; } ; transitions1: TRANSITIONS OBRACE { parse_stage = PARSE_TRANSITIONS; } ;transitions2: transitions_recur CBRACE { } | transitions2a transitions2b {} ;transitions2a: transitions_recur GRAFT_HEAD {} ;transitions2b: GRAFT_BODY CBRACE { } ; transitions_recur: transition | transitions_recur transition ;transition: transition1 transition2 ;transition1: state_expr transition_type id { add_transition($1, $2, $3); } | transition_type id { add_transition("any", $1, $2); } ;transition_1: //id id id { add_transition($1,$2,$3); } //| id id { add_transition("any",$1,$2); }; state_expr transition_type transition_name transition_options { //cur_state = $1; //transition_stimulus_str = $2; add_transition($1, $2, $3); } | transition_type transition_name transition_options { add_transition("any",$1,$2); } ;state_expr: id { $$ = $1; } | STATE_EXPR { $$ = $1; } ;transition_options: OBRACKET topts CBRACKET {} | ; topts: | LOCKING EQ id SEMI topts {transition_locking($3);} ;transition2: GRAFT_BODY { done_transition(); } ;transition_type: //id { $$=$1; } //| RECV { $$="recv"; } //temp_str = (char *)malloc(40); //strcpy(temp_str, "recv_"); //$$= strcat(temp_str, $2); //} | FORWARD { $$="forward"; } //temp_str = (char *)malloc(40); //strcpy(temp_str, "forward_"); //$$= strcat(temp_str, $2); //} | TIMER { $$="timer"; } //temp_str = (char *)malloc(40); //strcpy(temp_str, "timer_"); //$$= strcat(temp_str, $2); //} | API { $$="API"; } ;transition_name: TRANS_NAME { $$=$1; };routines: routines1 routines2 { parse_stage = PARSE_INIT; } | ;routines1: ROUTINES OBRACE { parse_stage = PARSE_ROUTINES; } ;routines2: routine_list CBRACE ;routine_list: routine | routine_list routine ;routine: prototype GRAFT_BODY { fprintf(cfilefuncs,"\n}\n\n"); } ;prototype: prototype1 prototype2 ;prototype1: id id { add_prototype($1,$2); } | id STAR id { temp_str = (char*)malloc(60); sprintf(temp_str,"%s* ",$1); add_prototype(temp_str,$3); free(temp_str); } | id id id { temp_str = (char*)malloc(60); sprintf(temp_str,"%s %s ",$1,$2); add_prototype(temp_str,$3); free(temp_str); } | id id STAR id { temp_str = (char*)malloc(60); sprintf(temp_str,"%s %s* ",$1,$2); add_prototype(temp_str,$4); free(temp_str); } ;prototype2: PARAM_LIST { fprintf(hfile,"(%s);\n",the_param_list); fprintf(cfilefuncs,"(%s)\n{\n",the_param_list); fprintf(cfilefuncs, " double curtime = Scheduler::instance().clock();\n"); } ;id: ID { $$ = strdup($1); } ;idcomp: IDCOMP { $$ = strdup($1); } ; num: NUM { $$ = $1; } ;%%yyerror(char *errmsg){ fprintf(stderr, "%s\n", errmsg); fflush(stderr);} main(int argc, char **argv){ int i; int parseerror; char *infile, *outfile="macedon.default.outfile"; extern FILE *yyin, *yyout; progname = argv[0]; printf("Copyright (c) 2004, Charles Killian, Adolfo Rodriguez, Dejan Kostic, Sooraj Bhat, and Amin Vahdat\n"); printf("All rights reserved.\n"); printf("\n"); printf("Redistribution and use in source and binary forms, with or without\n"); printf("modification, are permitted provided that the following conditions are met:\n"); printf("\n"); printf(" * Redistributions of source code must retain the above copyright\n"); printf(" notice, this list of conditions and the following disclaimer.\n"); printf(" * Redistributions in binary form must reproduce the above copyright\n"); printf(" notice, this list of conditions and the following disclaimer in\n"); printf(" the documentation and/or other materials provided with the\n"); printf(" distribution.\n"); printf(" * Neither the names of Duke University nor The University of\n"); printf(" California, San Diego, nor the names of its contributors\n"); printf(" may be used to endorse or promote products derived from\n"); printf(" this software without specific prior written permission.\n"); printf("\n"); printf("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"); printf("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"); printf("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n"); printf("DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n"); printf("FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"); printf("DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"); printf("SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n"); printf("CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n"); printf("OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE\n"); printf("USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"); if(argc != 2) { fprintf(stderr, usage, progname); exit(1); } mac_name = infile = argv[1]; /* open for read */ yyin = fopen(infile,"r"); if(yyin == NULL) /* open failed */ { fprintf(stderr,"%s: cannot open %s\n", progname, infile); exit(1); } /* open for write */ yyout = fopen(outfile,"w"); if(yyout == NULL) /* open failed */ { fprintf(stderr,"%s: cannot open outfile: %s\n", progname, outfile); exit(1); } for (i=0; i<API_num_types; i++) API_specified[i] = 0; parseerror = yyparse(); unlink(outfile); /* junk */ if (parseerror) { warning("Parse Error",(char *)0); exit(2); } /* now check EOF condition */ if(!protocol_done) /* in the middle of a screen */ { warning("Premature EOF",(char *)0); exit(1); } exit(0); /* no error */}warning(char *s, char *t) /* print warning message */{ fprintf(stderr, "%s: %s", progname, s); if (t) fprintf(stderr, " %s", t); fprintf(stderr, " %s line %d\n", mac_name, lineno);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -