%{ /* * Name : nac.y * Purpose : Syntax processing for the NAC (n-address code) formalism. * Author : Nikolaos Kavvadias (C) 2009, 2010, 2011 * Date : 17-Mar-2011 */ #include #include #include #include // #define YYSTYPE unsigned int #define YYDEBUG 1 extern char *yytext; int i; %} %token T_LPAREN T_RPAREN T_LBRACE T_RBRACE T_LBRACKET T_RBRACKET %token T_COMMA T_COLON T_SEMI T_ASSIGN T_EQUAL %token T_PROCEDURE T_LOCALVAR T_GLOBALVAR T_IN T_OUT %token T_ID %start nac_top %% nac_top : procedure_list | globalvar_def procedure_list ; globalvar_def : globalvar_prefix id_list T_SEMI | globalvar_def globalvar_prefix id_list T_SEMI ; globalvar_prefix : T_GLOBALVAR type_spec ; procedure_def : procedure_prefix T_LPAREN arg_list T_RPAREN T_LBRACE stmt_list T_RBRACE | procedure_prefix T_LPAREN arg_list T_RPAREN T_LBRACE localvar_list stmt_list T_RBRACE ; procedure_list : procedure_def | procedure_list procedure_def ; procedure_prefix : T_PROCEDURE id ; localvar_list : localvar_prefix id_list T_SEMI | localvar_list localvar_prefix id_list T_SEMI ; localvar_prefix : T_LOCALVAR type_spec ; stmt_list : /* empty */ | stmt_list stmt ; stmt : nac | pcall | label ; nac : opnd_out_list assign_op id opnd_in_list T_SEMI | opnd_out_list assign_op id T_SEMI | id opnd_in_list T_SEMI | id T_SEMI ; pcall : T_LPAREN opnd_out_list T_RPAREN assign_op id T_LPAREN opnd_in_list T_RPAREN T_SEMI | T_LPAREN opnd_out_list T_RPAREN assign_op id T_SEMI | id T_LPAREN opnd_in_list T_RPAREN T_SEMI | T_LPAREN T_RPAREN assign_op id T_LPAREN T_RPAREN T_SEMI ; assign_op : T_ASSIGN ; label : id T_COLON ; opnd_out_list : id_list ; opnd_in_list : id_list ; arg_list : /* empty */ | arg_in | arg_out | arg_list T_COMMA arg_in | arg_list T_COMMA arg_out ; arg_in : T_IN type_spec id ; arg_out : T_OUT type_spec id ; id_list : id | id_list T_COMMA id ; id : T_ID ; type_spec : T_ID ; %% #include #include #include /* For strcmp, strlen */ extern int column; extern FILE *yyin; int yyerror(char *s) { fflush(stdout); printf("\n%*s\n%*s\n", column, "^", column, s); return 0; }