%{ #define tags(x) 0 #include #include /*------------------------------------------------------------------- ###### # # ## ##### #### ###### ##### # # # # # # # # # # ###### # # # # #### ##### # # # ###### ##### # # ##### # # # # # # # # # # # # # # # #### ###### # # Versao <$Revision$$Date$> -------------------------------------------------------------------*/ int _accao=1; int in_sequence = 0; int cont_alt = 0; int cont_tup = 0; char * idtup() { char s[80]; sprintf(s,"_p%d", cont_tup++); return strdup(s); } char CONTEXTO= 'd'; #include "version" char straux [30], command [50]; char option; int jjDEBUG =1; #include "sexp.h" #include "met.h" void erro(); struct t_tipo { char ti[5]; struct t_tipo *arg1, *arg2, *next; }; typedef struct t_tipo TIPO; typedef struct t_tipo *APTIPO; %} %union { char *str; struct { char *arg; char *typ; } sig; } %{ /* *** Simbolos Terminais *** */ %} %token SIMB CONSTANTE INTEGER STRING BOOL %token SET LIST TYPE ENDTYPE P4 NIL RELACAO INCLUDE INCLUDEM DEBUGON %token DEBUGOFF QUIT MODEL ENDMODEL FSETA2 INV COMP FPROD FADD %{ /* *** fim de definicao de terminais *** */ %} %{ /* *** prioridades e associatividades: *** */ %} %nonassoc minima %nonassoc ';' %left ',' %nonassoc FUNCAO %nonassoc LAMBDA %nonassoc baixa %nonassoc LET OTHER SETA IF THEN RELBEGIN RELEND PRE ESTADO %nonassoc PERTENCE ELSE RETUR ALL EXIST EXIST1 %nonassoc '>' %left IMPLICA %left AND %left OR %left NOT %nonassoc EQ NEQ LEQ GEQ '<' GT %left STRCAT %left ADD SUB %left MUL DIV %nonassoc NOTIN IN %left UNION %left INTER %left '-' %nonassoc '#' alta %left '^' %left PLUS %left '/' %left '\\' %left '.' %left '[' %left '(' %left COMP %left FSETA LIST SET %right FSETA2 %left FADD %left FPROD %nonassoc CONSF ID IS ':' ORIO QUOTE %right maxima %nonassoc maximam %{ /* *** fim de definicao de prioridades *** */ %} %{ /* *** Simbolos Nao Terminais *** */ %} %type precond tag %type deffuncao defobj exp ffexp setexp seqexp letexp ifexp %type boolexp relexp estado retorno seqexp2 %type poscondicao tipo resultado resultado1 all exist exist1 %type exppair def from from2 include op_orio FunctExp inv %type casepair is_exp intexp strexp %type exppairlist explist deflist expcaselist comdef %type explist2 %type fromlist fromlist2 extensao compreensao compreensao2 %type ffcompreensao %type assinatura %type defTp tuplo rtuplo rtuplo2 %type itemtuplo funcfin relacao lista conjunto %type alternativa2 alternativa simpleType %type segmentoInicial defTipo idTipo expFPlist expFAlist %% especificacao : especificacao typesMod | especificacao bloco | especificacao ENDMODEL | especificacao MODEL SIMB { printf("%s",ppBeginModel($3)); } | ; /*--( Definicao de tipos )-------------------------------------------*/ defTipo : idTipo '=' defTp inv ';' { ppPrint(ppDefType($1,$3,$4)); } | idTipo P4 defTp inv ';' { ppPrint(ppDefType($1,$3,$4)); } | error ';' { yyerrok; } ; inv : INV '(' SIMB ')' '=' {CONTEXTO='d';} exp {CONTEXTO='t'; $$=ppInv(ppString($3),$7); } | {$$ = ppNull();} ; idTipo: SIMB { $$ = ppString($1); } ; defTp: simpleType { $$ = $1; } | alternativa2 { $$ = $1; /*DANGER*/ } | alternativa { $$ = $1; } | tuplo { $$ = ppProdExp($1); } ; simpleType : SIMB { $$ = ppString($1); } | NIL { $$ = str_save("nil"); } | relacao { $$ = $1; } | funcfin { $$ = $1; } | lista { $$ = $1; } | conjunto { $$ = $1; } | segmentoInicial { $$ = $1; } | '(' simpleType ')' { $$ = $2; } ; tuplo : simpleType INTER rtuplo2 { $$ = ppProd($1,$3); /* DANGER */ } ; rtuplo2 : simpleType { $$ = $1; /* DANGER */ } | rtuplo2 INTER simpleType { $$ = ppProd($1,$3); /* DANGER */ } ; tuplo : itemtuplo rtuplo { $$ = ppProd($1,$2); } ; rtuplo: itemtuplo rtuplo { $$ = ppProd($1,$2); } | { $$ = ppNull(); } ; itemtuplo : SIMB ':' simpleType %prec minima { $$ = ppProdItem(ppString($1),$3); } ; funcfin : simpleType SETA simpleType { $$ = ppFfun($1,$3); } ; relacao : simpleType RELACAO simpleType { $$ = ppBrel($1,$3); } ; lista : SIMB LIST { $$ = ppList(ppString($1)); } | '(' simpleType ')' LIST { $$ = ppList($2); } | segmentoInicial LIST { $$ = ppList($1); } ; conjunto : SIMB SET { $$ = ppSet(ppString($1)); } | '(' simpleType ')' SET { $$ = ppSet($2); } | segmentoInicial SET { $$ = ppSet($1); } ; segmentoInicial : INTEGER { $$ = ppInt(); } ; alternativa : '[' simpleType ']' %prec minima { $$ = ppAlt($2); } | simpleType '|' simpleType %prec minima { $$ = ppPlus($1,$3); } | alternativa '|' '[' simpleType ']' %prec minima { $$ = ppPlus($1,$4); } | alternativa '|' simpleType %prec minima { $$ = ppPlus($1,$3); } ; alternativa2 : simpleType PLUS simpleType %prec minima { $$ = ppPlus($1,$3); } | alternativa2 PLUS simpleType %prec minima { $$ = ppPlus($1,$3); } ; /*--( Definicao de tipos nos modulos )-------------------------------*/ typesMod : TYPE {CONTEXTO='t'; ppBeginDefType(); } defTipo { } restDefTypesMod { ppEndDefType(); } ENDTYPE {CONTEXTO='d';} ; restDefTypesMod : defTipo { } restDefTypesMod | ; /*--( Bloco = (deffuncao+include+teste)* )---------------------------*/ bloco : bloco elemento | elemento ; elemento : exp ';' { } | include { printf("%s",$1); } | ESTADO SIMB ':' tipo ';' { printf("%s",ppState(ppString($2),$4)); } | directiva | deffuncao ';' { } | error ';' {yyerrok;} elemento | QUIT { return(0);} ; /*--( directivas de debug/outras )-----------------------------------*/ directiva : DEBUGON {jjDEBUG = 1;} | DEBUGOFF {jjDEBUG = 0;} ; /*--( Includes )-----------------------------------------------------*/ include : INCLUDE SIMB '.' SIMB { $$ = ppInclude(ppString($2),ppString($4)); } | INCLUDE STRING { $$ = ppInclude($2,""); } | INCLUDE SIMB { $$ = ppInclude(ppString($2),""); } | INCLUDEM STRING { } | INCLUDEM SIMB '.' SIMB { } | INCLUDEM SIMB { } ; /*--( definicao de funcoes )-----------------------------------------*/ deffuncao : SIMB '(' explist ')' '=' exp { (void)ppBeginFunc(); (void)printf("%s",ppPrintAuxFunc($1,$3,$6)); (void)ppEndFunc(); } | FUNCAO SIMB assinatura precond /* mensagem */ poscondicao { (void)ppBeginFunc(); (void)printf("%s",ppPrintFunc(ppString($2),$3.arg,$3.typ,$4,$5)); (void)ppEndFunc(); } ; poscondicao : estado retorno { $$ = ppReturnState($2,$1); } | retorno estado { $$ = ppReturnState($1,$2); } | retorno { $$ = ppReturnState($1,""); } | estado { $$ = ppReturnState("",$1); } | LET '(' deflist ')' IN poscondicao { $$ = ppLetIn($3,$6); } ; retorno : RETUR exp { $$ = $2; } ; estado : ESTADO exp { $$ = $2; } ; assinatura : '(' explist2 ')' resultado { $$.arg = $2.arg; $$.typ = ppSign($2.typ,$4); } ; resultado : ':' resultado1 { $$ = $2; } | { $$ = ppNull(); } ; resultado1 : resultado1 tipo { $$ = $2; } | { $$ = ppNull(); } ; tipo : defTp { $$ = $1; } ; explist2 : SIMB ':' tipo ',' explist2 { $$.arg = ppArgList(ppString($1),$5.arg); $$.typ = ppTypList($3,$5.typ); } | SIMB ':' tipo { $$.arg = ppArgItem(ppString($1)); $$.typ = ppTypItem($3); } | SIMB ',' explist2 { $$.arg = ppArgList(ppString($1),$3.arg); $$.typ = ppNull(); } | SIMB { $$.arg = ppArgItem(ppString($1)); $$.typ = ppNull(); } | '(' SIMB ')' ',' explist2 { $$.arg = ppArgList(ppString($2),$5.arg); $$.typ = ppNull(); } | '(' SIMB ')' { $$.arg = ppArgItem(ppString($2)); $$.typ = ppNull(); } | { $$.arg = ppNull(); $$.typ = ppNull(); } ; precond : PRE exp { $$ = $2; /*ppPreExp($2);*/ } | PRE exp SETA exp { $$ = $2; /*ppPreExp($2);*/ } | { $$ = ppNull(); } ; /*--( definicao de variaveis de Estado )-----------------------------*/ defobj : SIMB atrib exp %prec baixa { $$ = ppStateAtrib(ppString($1),$3); } | SIMB '.' SIMB atrib exp %prec baixa { $$ = ppStateAtrib(ppString($1),ppString($5)); } ; atrib : PERTENCE ; /*--( Expressoes )---------------------------------------------------*/ exp : SIMB { $$ = ppString($1); } | '(' exp ')' { $$ = $2; } | CONSTANTE { $$ = $1; } /* | exp exp { #ifdef NYAG $$=mklista(cons($1,$2)); #endif #ifdef PRETTY $$ = ppExpExpList($1,$2); #endif } */ | exp '(' explist ')' %prec '(' { $$ = ppExpExpList($1,$3); } | FUNCAO assinatura precond /* mensagem */ poscondicao { (void)ppBeginFunc(); (void)printf("%s",ppPrintFunc("lambda",$2.arg,$2.typ,$3,$4)); (void)ppEndFunc(); } | LAMBDA '(' explist ')' '.' exp %prec PERTENCE { $$ = ppLambda($3,$6); } | SIMB '(' explist ')' %prec '(' { $$ = ppSymExpList(ppString($1),$3); } | QUOTE '(' explist ')' { } | op_orio ORIO '(' exp ',' exp ')' { $$ = ppOrio($1,$4,$6); } | NIL { } | defobj { $$ = $1; } | strexp { $$=$1; } | intexp { $$ = $1; } | ffexp { $$ = $1; } | relexp { $$ = $1; } | seqexp { $$ = $1; } | setexp { $$ = $1; } | letexp { $$ = $1; } | ifexp { $$ = $1; } | boolexp { $$ = $1; } | exp '\\' exp { $$ = ppDomSub($1,$3); } | exp '/' exp { $$ = ppDomRst($1,$3); } | exp '[' exp ']' %prec maxima { $$ = ppDomMap($1,$3); } | SIMB '.' SIMB { } | FunctExp ; strexp : STRING { $$ = ppStrExp($1); } | exp STRCAT exp { $$ = ppStrCat($1,$3); } ; op_orio : SIMB { $$ = ppString($1); } | ADD { $$ = ppADD(); } | STRCAT { $$ = ppSTRCAT(); } | MUL { $$ = ppMUL(); } | OR { $$ = ppOR(); } /* | '^' {$$=mkatconst("append");} */ | PLUS { $$ = ppPLUS(); } ; /*--( Expressoes Inteiras )----------------------------------------------*/ intexp : INTEGER { $$ = $1; } | '#' exp { $$ = ppSetCard($2); } | exp ADD exp { $$ = ppExpAdd($1,$3); } | exp SUB exp { $$ = ppExpSub($1,$3); } | exp DIV exp { $$ = ppExpDiv($1,$3); } | exp MUL exp { $$ = ppExpMul($1,$3); } ; /*--( Expressoes Bool )----------------------------------------------*/ boolexp : exp IN exp { $$ = ppBoolIn($1,$3); } | exp NOTIN exp { $$ = ppBoolNotin($1,$3); } | exp EQ exp { $$ = ppBoolEQ($1,$3); } | exp AND exp { $$ = ppBoolAnd($1,$3); } | exp IMPLICA exp { $$ = ppBoolImplies($1,$3); } | exp OR exp { $$ = ppBoolOr($1,$3); } | NOT exp { $$ = ppBoolNot($2); } | exp '<' exp { $$ = ppBoolLT($1,$3); } | exp GT exp { $$ = ppBoolGT($1,$3); } | exp '>' exp { $$ = ppBoolGT($1,$3); } | exp LEQ exp { $$ = ppBoolLEQ($1,$3); } | exp GEQ exp { $$ = ppBoolGEQ($1,$3); } | exp NEQ exp { $$ = ppBoolNEQ($1,$3); } | IS defTp '(' exp ')' { $$ = ppIsTypeExp($2,$4); } | ALL '(' all ')' { $$=$3; } | EXIST '(' exist ')' { $$=$3; } | EXIST1 '(' exist1 ')' { $$=$3; } | BOOL { $$ = ppBool($1); } ; FunctExp : exp SET { $$ = ppFSetExp($1); } | exp LIST { $$ = ppFSeqExp($1); } | exp FSETA { $$ = ppFSetaExp($1); } | FSETA2 exp { $$ = ppFSeta2Exp($2); } | exp COMP exp { $$ = ppFCompExp($1,$3); } | ID exp { $$ = ppIdExp($2); } | CONSF exp { $$ = ppCstExp($2); } | expFAlist { $$ = $1; /* DANGER */ } | expFPlist { $$ = $1; /* DANGER */ } ; expFAlist : exp FADD exp { $$ = ppExpAdd($1,$3); /* DANGER */ } | expFAlist FADD exp { $$ = ppExpAdd($1,$3); /* DANGER */ } ; expFPlist : exp FPROD exp { $$ = ppFProdExp($1,$3); /* DANGER */ } | expFPlist FPROD exp { $$ = ppFProdExp($1,$3); /* DANGER */ } ; all : SIMB PERTENCE exp ',' all { $$ = ppForAllList(ppString($1),$3,$5); } | SIMB PERTENCE exp ':' exp { $$ = ppForAllAnd(ppString($1),$3,$5); } ; exist : SIMB PERTENCE exp ',' exist { $$ = ppExistList(ppString($1),$3,$5); } | SIMB PERTENCE exp ':' exp { $$ = ppExistAnd(ppString($1),$3,$5); } ; exist1 : SIMB PERTENCE exp ',' exist1 { $$ = ppExist1List(ppString($1),$3,$5); } | SIMB PERTENCE exp ':' exp { $$ = ppExist1And(ppString($1),$3,$5); } ; /*--( Set e Seq )----------------------------------------------------*/ setexp : '{' compreensao '}' { $$ = ppSetExp($2); } | '{' extensao '}' { $$ = ppSetExp($2); } | '{' '}' { $$ = ppSetEmpty(); } | exp INTER exp { $$ = ppSetInter($1,$3); } | exp UNION exp { $$ = ppSetUnion($1,$3); } | exp '-' exp { $$ = ppSetDifer($1,$3); } ; compreensao : exp '|' fromlist { $$ = ppSetComp($1,$3); } ; compreensao2 : exp '|' fromlist2 { $$ = ppSetComp($1,$3); } ; extensao : extensao ',' exp { $$ = ppSetEnum($3,$1); } | exp { $$ = ppSetEnum($1,""); } seqexp2 : compreensao2 { $$ = ppSeqExp($1); } | extensao ',' exp '>' { $$ = ppSeqEnum($3,$1); } | exp '>' { $$ = ppSeqExp($1); } | '>' { $$ = ppSeqEmpty(); } | exp ':' exp '>' { $$ = ppSeqCons($1,$3); } ; seqexp : '<' {in_sequence++ ;} seqexp2 { $$ = $3; } | exp '^' exp { $$ = ppSeqAppend($1,$3); } ; fromlist : from ',' fromlist { $$ = ppFromList($1,$3); } | from { $$ = $1; } ; fromlist2 : from ',' fromlist2 { $$ = ppFromAndFrom($1,$3); } | from2 { $$ = ppAndFrom($1); } ; from : SIMB PERTENCE exp { $$ = ppFrom(ppString($1),$3); } | SIMB PERTENCE exp ':' exp { $$ = ppFromAnd(ppString($1),$3,$5); } ; from2 : SIMB PERTENCE exp '>' { $$ = ppFrom(ppString($1),$3); } | SIMB PERTENCE exp ':' exp '>' { $$ = ppFromAnd(ppString($1),$3,$5); } ; /*--( Funcoes finitas e relacoes binarias )--------------------------*/ ffexp : '[' ffcompreensao ']' { $$ = $2; /*ppFfunExp($2);*/ } | '[' exppairlist ']' { $$ = $2; /*ppFfunExp($2);*/ } | exp PLUS exp { $$ = ppFfunPlus($1,$3); } ; ffcompreensao : exp SETA exp '|' fromlist { $$ = ppFfunComp($1,$3,$5); } ; exppairlist : exppairlist ',' exppair { $$ = ppFfunPairList($3,$1); } | exppair { $$ = $1; } | { $$ = ppFfunEmpty(); } ; exppair : exp SETA exp { $$ = ppFfunPair($1,$3); } ; relexp : RELBEGIN ffcompreensao RELEND { } | RELBEGIN exppairlist RELEND { } ; explist : exp ',' explist { $$ = ppExpList($1,$3); } | exp { $$ = ppExpList($1,""); } | { $$ = ppExpList("",""); } ; /*--( Expressoes condicionais )--------------------------------------*/ letexp : LET '(' deflist ')' IN exp %prec LET { $$ = ppLetExp($3,$6); } ; deflist : def ',' deflist { $$ = ppDefList($1,$3); } | def { $$ = ppDefList($1,""); } | comdef ',' deflist { } | comdef { } ; comdef : '<' SIMB ',' SIMB GTs '=' exp { } ; def : SIMB '=' exp { $$ = ppDefVar(ppString($1),$3); } | '=' exp { $$ = ppDefVar("__",$2); } ; ifexp : IF exp THEN exp { $$ = ppIfThen($2,$4); } | IF '(' expcaselist { $$ = ppIfCase($3); } | IF exp THEN exp ELSE exp { $$ = ppIfThenElse($2,$4,$6); } ; expcaselist : casepair ',' expcaselist { $$ = ppIfCaseList($1,$3); } | casepair ')' { $$ = ppIfCaseList($1,""); } | ELSE SETA exp ')' { $$ = ppIfCaseElse($3); } | casepair ')' OTHER exp { $$ = ppIfCaseElse($4); } ; casepair : exp SETA exp { $$ = ppIfCaseExp($1,$3); } | is_exp ; is_exp: exp IS '<' SIMB ':' SIMB GTs SETA exp { $$ = ppIsExpSeq($4,$6,$9); } | exp IS '<' GTs SETA exp { $$ = ppIsExpEmptySeq($6); } | exp IS '{' SIMB ':' SIMB '}' SETA exp { $$ = ppIsExpSet($4,$6,$9); } | exp IS '{' '}' SETA exp { $$ = ppIsExpEmptySet($6); } | exp IS '[' SIMB SETA SIMB ':' SIMB ']' SETA exp { $$ = ppIsExpFF($4,$6,$8,$11); } | exp IS '[' ']' SETA exp { $$ = ppIsExpEmptyFF($6); } | exp IS tag ':' SIMB SETA exp { $$ = ppIsExpSet($3,$5,$7) ; /* DANGER */ } ; GTs : '>' | GT ; tag : INTEGER /*DANGER ?*/ | SIMB ; %% /* ---(Analisador lexico )----------------------------------------------*/ #include #include static int queres_comentarios=0; #include extern jmp_buf xljmpbuf ; #include "lex.yy.c" /* ---(Formata output )-------------------------------------------------*/ #if INTERACTIVE || FUNC #include "iformata.c" #else #include "formata.c" #endif /* ---(Funcoes auxiliares)----------------------------------------------*/ void met(s) char s []; { strcat(strcpy(straux,s),".met"); } char *aspas(s) char *s; {char *aux; aux=(char *) malloc(strlen(s)+3); return(strcat(strcat(strcpy(aux,"\""),s),"\"")); } #ifdef __TURBOC__ #define NAOBUF #else #define NAOBUF(f1,f2) setbuf(f1,NULL); setbuf(f2,NULL); fflush(f1); fflush(f2); /* #define NAOBUF setvbuf(yyout,buff,_IOLBF,BUFSIZ) #define NAOBUFi setvbuf(stdin,buff,_IOLBF,BUFSIZ) */ #endif __TURBOC__ /* ---(main )-----------------------------------------------------------*/ FILE *ftags; char fichin[100]; char buff[BUFSIZ]; char buffi[BUFSIZ]; int _ERRO=0; char *FILENAME=""; #ifdef FUNC char * S_GLOBI; char * S_GLOBO; int seca(S,S2) char * S; char * S2; { _ERRO=0; line_read=(char*)NULL; S_GLOBI=S; S_GLOBO=S2; clear_metoobuf(); yyparse(); return(_ERRO); } /* ---(Tratamento de erros em FUNC)-------------------------------------*/ void erro(s) char *s; { _ERRO=1;} void yyerror() {_ERRO=1;} #else /*FUNC*/ extern int neverprompt; main (argc,argv) int argc; char *argv[]; { #ifdef INTERACTIVE int i; char S[200]; #ifdef PIPE neverprompt=1; NAOBUF(stdin,stdout); #endif /*PIPE*/ tags( ftags=fopen("tags.aux","a")); #ifndef PIPE printversion(); printf("camila version %s (%s)\n",cam_version, cam_date); #endif /*PIPE*/ libxminit(0,NULL); /* inicia xmetoo */ sprintf(S,"(load \"%s/.metoorc\")",getenv("HOME")); #ifndef PIPE puts(S+7); #endif /*PIPE*/ libxmevalstr(S); if((argc ==3) && (!strcmp(argv[1],"-n"))) { #ifdef PIPE yyin=fopen(argv[2],"r"); #else /*PIPE*/ freopen(argv[2],"r",stdin); #endif /*PIPE*/ FILENAME = strdup(argv[2]); yyout = stdout; queres_comentarios=0; NAOBUF(yyin,yyout); } else if((argc ==2) && (!strcmp(argv[1],"-n"))) { yyout = stdout; queres_comentarios=0; NAOBUF(stdin,yyout); } else for(i=1; i< argc ; i++) { puts(argv[i]); sprintf(S,"(def _FILENAME \"%s\" ) ",argv[i]); libxmevalstr(S); sprintf(S,"(nload \"%s\" ) ",argv[i]); libxmevalstr(S); } yyparse(); #else /*INTERACTIVE */ if((argc ==3) && (!strcmp(argv[1],"-t"))) { yyin=fopen(argv[2],"r"); FILENAME = strdup(argv[2]); if(strcmp((char*)(FILENAME + strlen(FILENAME) -4),".cam")==0) { strcpy((char*)(FILENAME + strlen(FILENAME) -4), ".tex"); freopen(FILENAME,"w",stdout); } fprintf(stdout,"\\documentclass{article}\n"); fprintf(stdout,"\\input camila.mac\n"); //fprintf(stdout,"\\usepackage{fullpage}\n"); fprintf(stdout,"\\begin{document}\n"); yyparse(); fprintf(stdout,"\\end{document}\n"); } else if((argc ==4) && (!strcmp(argv[1],"-o"))) { yyin=fopen(argv[3],"r"); freopen(argv[2],"w",stdout); fprintf(stdout,"\\documentclass{article}\n"); fprintf(stdout,"\\input camila.mac\n"); //fprintf(stdout,"\\usepackage{fullpage}\n"); fprintf(stdout,"\\begin{document}\n"); yyparse(); fprintf(stdout,"\\end{document}\n"); } else if(argc ==2) { yyin=fopen(argv[1],"r"); FILENAME = strdup(argv[1]); if(strcmp((char*)(FILENAME + strlen(FILENAME) -4),".cam")==0) { strcpy((char*)(FILENAME + strlen(FILENAME) -4), ".tex"); freopen(FILENAME,"w",stdout); } yyparse(); } else { yyparse();} return _ERRO; #endif /*INTERACTIVE */ } /* ---(Tratamento de erros )--------------------------------------------*/ void erro(s) char *s; { _ERRO=1;fprintf(stderr,"%s %d : semantic ERROR: %s\n",FILENAME, yylineno,s);} void yyerror() { _ERRO=1;fprintf(stderr,"%s %d : syntatic ERROR detected in '%s'\n", FILENAME, yylineno,yytext);} #endif /*FUNC */ yywrap() { return (1);} /* ---(Tratamento de tipos )--------------------------------------------*/ #include "secatipo.c" /*---(Gerador de TAGS )------------------------------------------------ */ static char func_name[30]; void gera_tag_pair(nome) char *nome; { printf("invocada - %s\n",nome); } char *ppSorts(); char *ppOpers(); void ppPrint(char *s) { (void)printf("\n%s",s); } void ppBeginDefType() { (void)printf("%s",ppSorts()); (void)printf("\n$\\begin{array}{lcll}"); } void ppEndDefType() { (void)printf("\n\\end{array}$\n"); (void)printf("%s",ppOpers()); } char *ppDefType(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"%s & \\cong & %s & %s \\\\",a,b,c); return s; } char *ppProdExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\PROD %s \\DORP\n",a); return s; } char *ppProd(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); if (!strcmp(b,"")) sprintf(s,"%s",a); else sprintf(s,"%s \\NEXT %s",a,b); return s; } char *ppFfun(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\pfunc{%s}",a,b); return s; } char *ppProdItem(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\TYPE %s",a,b); return s; } char *ppBrel(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s \\brel{%s}",a,b); return s; } char *ppList(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"{%s^{\\star}}",a); /* //sprintf(s,"{\\seq{%s}}",a); */ return s; } char *ppInseg(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"{\\inseg{%s}}",a); return s; } char *ppSet(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"{\\set{%s}}",a); return s; } char *ppInt() { char *s; s = (char *)calloc(3,sizeof(char)); sprintf(s,"\\N"); } char *ppPlus(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); if (!strcmp(b,"")) sprintf(s,"%s",a); else sprintf(s,"{%s + %s}",a,b); return s; } char *ppAlt(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"%s + 1",a); return s; } char *ppArgItem(char *a) { char *s; s = (char *)calloc(strlen(a)+5,sizeof(char)); sprintf(s,"%s",a); return s; } char *ppTypItem(char *a) { char *s; s = (char *)calloc(strlen(a)+5,sizeof(char)); sprintf(s,"%s",a); return s; } char *ppArgList(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s,%s",a,b); return s; } char *ppTypList(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s \\times %s",a,b); return s; } char *ppSign(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\tfunc{%s}",a,b); return s; } char *ppPrintFunc(char *a,char *b,char *c,char *d,char *e) { char *s; if (strcmp(d,"")) { s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+strlen(d)+strlen(e)+255,sizeof(char)); sprintf(s,"%s:%s \\\\ %s(%s) \\deff \\\\ \\rule{3ex}{0pt} \n\\PRE %s \n\\IN %s \n\\ERP",a,c,a,b,d,e); } else { s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+strlen(d)+strlen(e)+255,sizeof(char)); sprintf(s,"%s:%s \\\\ %s(%s) \\deff \\\\ \\rule{3ex}{0pt} %s %s",a,c,a,b,d,e); } return s; } char *ppPrintAuxFunc(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"%s(%s) \\deff \\\\ \\rule{3ex}{0pt} %s",a,b,c); return s; } char *ppLetIn(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\LET %s \n\\IN %s \n\\TEL",a,b); return s; } char *ppDefVar(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s = %s",a,b); return s; } char *ppExpExpList(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s(%s)",a,b); return s; } char *ppSymExpList(char *a,char *b) { char *s; /* if (!strcmp(a,"strcat")) { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s(%s)",a,b); } */ if (!strcmp(a,"UNION")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\bigcup (%s)",b); } else if (!strcmp(a,"first")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_1(%s)",b); } else if (!strcmp(a,"second")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_2(%s)",b); } else if (!strcmp(a,"p1")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_1(%s)",b); } else if (!strcmp(a,"p2")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_2(%s)",b); } else if (!strcmp(a,"p3")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_3(%s)",b); } else if (!strcmp(a,"p4")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_4(%s)",b); } else if (!strcmp(a,"p5")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\pi_5(%s)",b); } else if (!strcmp(a,"inseg")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\inseg{%s}",b); } else if (!strcmp(a,"progn")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\ndo(%s)",b); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s(%s)",a,b); } return s; } char *ppExpList(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"%s",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s,%s",a,b); } return s; } char *ppExpAdd(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s + %s}",a,b); return s; } char *ppExpSub(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s - %s}",a,b); return s; } char *ppExpDiv(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s / %s}",a,b); return s; } char *ppExpMul(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\times %s}",a,b); return s; } char *ppBool(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); if (!strcmp(a,"true")) { sprintf(s,"\n\\TRUE "); } else if (!strcmp(a,"false")) { sprintf(s,"\n\\FALSE"); } return s; } char *ppBoolIn(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\in %s}",a,b); return s; } char *ppBoolNotin(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s \\notin %s",a,b); return s; } char *ppBoolEQ(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s = %s",a,b); return s; } char *ppBoolAnd(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\and %s}",a,b); return s; } char *ppBoolOr(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\vee %s}",a,b); return s; } char *ppBoolImplies(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\Rightarrow %s}",a,b); return s; } char *ppBoolNot(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\n{\\neg %s}",a); return s; } char *ppBoolLT(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s < %s}",a,b); return s; } char *ppBoolGT(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s > %s}",a,b); return s; } char *ppBoolLEQ(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\leq %s}",a,b); return s; } char *ppBoolGEQ(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\geq %s}",a,b); return s; } char *ppBoolNEQ(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\neq %s}",a,b); return s; } char *ppDomSub(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\mapds %s}",a,b); return s; } char *ppDomRst(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n{%s \\mapdr %s}",a,b); return s; } char *ppDomMap(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s(%s)",a,b); return s; } char *ppSetCard(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\n{\\card{%s}}",a); return s; } char *ppStrExp(char *a) { char *s,*s1; if (!strcmp(a,"\"\\n\"")) { s = (char *)calloc(15,sizeof(char)); sprintf(s,"\"NL\""); } else if (!strcmp(a,"\"&\"")) { s = (char *)calloc(15,sizeof(char)); sprintf(s,"\"\\&\""); } else if (!strcmp(a,"\"\\\\\"")) { s = (char *)calloc(25,sizeof(char)); sprintf(s,"\"$\\backslash\\backslash$\""); } else if (!strcmp(a,"\"^\"")) { s = (char *)calloc(25,sizeof(char)); sprintf(s,"\"$\\uparrow$\""); } else { s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\n%s",a); } s1 = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s1,"\\mattt{%s}",s); return s1; } char *ppStrCat(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n%s \\mathbin{++} %s",a,b); return s; } char *ppLetExp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\LET %s \n\\IN %s \n\\TEL",a,b); return s; } char *ppState(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\STATE{%s}{%s}",a,b); return s; } char *ppStateAtrib(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s' = %s",a,b); return s; } /* Sequences */ char *ppSeqExp(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\\enlist{%s}",a); return s; } char *ppSeqEmpty() { char *s; s = (char *)calloc(15,sizeof(char)); sprintf(s,"\\emptylist"); return s; } char *ppSeqCons(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\\enlist{%s}",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\\enlist{%s:%s}",a,b); } return s; } char *ppSeqEnum(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\\enlist{%s}",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\\enlist{%s,%s}",b,a); } return s; } char *ppSeqAppend(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\conc %s",a,b); return s; } /* SETS */ char *ppSetExp(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"\\{%s\\}",a); return s; } char *ppSetEmpty() { char *s; s = (char *)calloc(15,sizeof(char)); sprintf(s,"\\emptyset"); return s; } char *ppSetInter(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\cap %s",a,b); return s; } char *ppSetUnion(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\cup %s",a,b); return s; } char *ppSetDifer(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s - %s",a,b); return s; } char *ppSetComp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\asor %s",a,b); return s; } char *ppSetEnum(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s,"%s",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s,%s",a,b); } return s; } /* FFUNs */ char *ppFfunExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\\left( \\begin{array}{c}\n %s \n\\end{array} \\right)",a); return s; } char *ppFfunPair(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\\left( \\begin{array}{c}\n %s \\\\ %s \n\\end{array} \\right)",a,b); return s; } char *ppFfunPlus(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s \\plus %s",a,b); return s; } char *ppFfunPairList(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\\left( \\begin{array}{c}\n %s \n\\end{array} \\right)",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\\left( \\begin{array}{cc}\n %s & %s \n\\end{array} \\right)",a,b); } return s; } char *ppFfunComp(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\\left( \\begin{array}{c}\n %s \\\\ %s \n\\end{array} \\right)_{%s}",a,b,c); return s; } char *ppFfunEmpty() { char *s; s = (char *)calloc(255,sizeof(char)); sprintf(s,"\\left( \\begin{array}{c}\n \\\\ \n\\end{array} \\right)"); return s; } /* From Expressions */ char *ppFrom(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s \\in %s",a,b); return s; } char *ppFromAnd(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+25,sizeof(char)); sprintf(s,"%s \\in %s \\wedge %s",a,b,c); return s; } char *ppFromAndFrom(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+25,sizeof(char)); sprintf(s,"%s \\wedge %s",a,b); return s; } char *ppAndFrom(char *a) { char *s; s = (char *)calloc(strlen(a)+5,sizeof(char)); sprintf(s,"%s",a); return s; } char *ppFromList(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"%s",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s, %s",a,b); } return s; } /* IF expressions */ char *ppIfThen(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\COND{%s}{%s}{\\bot}",a,b); return s; } char *ppIfThenElse(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n\\COND{%s}{%s}{%s}",a,b,c); return s; } char *ppBrace(char *a) { char *s; s = (char *)calloc(strlen(a)+5,sizeof(char)); sprintf(s,"(%s)",a); return s; } char *ppDefList(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"%s",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s\\\\%s",a,b); } return s; } char *ppIsTypeExp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\\is{%s}(%s)",a,b); return s; } char *ppNull() { return(str_save("")); } char *ppADD() { return(str_save("+"));} char *ppMUL() { return(str_save("$\\times$"));} char *ppPLUS() { return(str_save("+"));} char *ppAND() { return(str_save("$\\and$"));} char *ppOR() { return(str_save("$\\or$"));} char *ppSTRCAT() { return(str_save("$\\mathbin{++}$"));} char *ppOrio(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); if (!strcmp(a,"UNION")) sprintf(s,"\\bigcup_{%s}(%s,%s)",a,b,c); else sprintf(s,"%s-red(%s,%s)",a,b,c); return s; } void ppBeginFunc() { (void)printf("\n$\\begin{array}{l}\n"); } void ppEndFunc() { (void)printf("\n\\end{array}$\n\n\\traco\n"); } char *ppReturnState(char *a,char *b) { char *s; if (!strcmp(a,"")) { s = (char *)calloc(strlen(b)+255,sizeof(char)); sprintf(s,"%s",b); } else if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"%s",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\POST %s \n\\IN %s \n\\TSOP",b,a); } return s; } char *ppPreExp(char *a) { char *s; if (!strcmp(a,"")) { s = (char *)calloc(5,sizeof(char)); sprintf(s,""); } else { s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\PRE %s \n\\ERP \\\\ \\rule{3ex}{0pt}",a); } return s; } char *ppIfCase(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\CASE %s ",a); return s; } char *ppIfCaseExp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n%s \\VALUE %s",a,b); return s; } char *ppIfCaseList(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \n \\ESAC\n",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"%s \\\\ %s",a,b); } return s; } char *ppIfCaseElse(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\\OTHERWISE \\VALUE %s \n \\ESAC\n",a); return s; } /* Quantifiers */ char *ppForAllAnd(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n\\forall %s \\in %s \\wedge %s",a,b,c); return s; } char *ppForAllList(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n\\forall %s \\in %s, %s",a,b,c); return s; } char *ppExistAnd(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); /* sprintf(s,"\n\\exists %s \\in %s \\wedge %s",a,b,c); */ sprintf(s,"\n\\exists %s \\in %s : %s",a,b,c); return s; } char *ppExistList(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n\\exists %s \\in %s, %s",a,b,c); return s; } char *ppExist1And(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n\\exists^{1} %s \\in %s \\wedge %s",a,b,c); return s; } char *ppExist1List(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n\\exists^{1} %s \\in %s, %s",a,b,c); return s; } char *ppSorts() { char *s; s = (char *)calloc(255,sizeof(char)); sprintf(s,"\n\\SORTS\n"); return s; } char *ppOpers() { char *s; s = (char *)calloc(255,sizeof(char)); sprintf(s,"\n\\OPERS\n"); return s; } /* Functorial expressions */ char *ppFSetExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n%s\\!\\!-\\!\\!set ",a); return s; } char *ppFSeqExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n%s\\!\\!\\!-\\!\\!seq ",a); return s; } char *ppFSetaExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n%s \\hookrightarrow\\star ",a); return s; } char *ppFSeta2Exp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\star\\hookrightarrow %s ",a); return s; } char *ppFProdExp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n%s \\times %s ",a,b); return s; } char *ppFCompExp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\COMP{%s}{%s}",a,b); return s; } char *ppIdExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\ID{%s}",a); return s; } char *ppCstExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\CST{%s}",a); return s; } /* Pattern-matching */ char *ppIsExpEmptySeq(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\nis\\!-\\!\\!<> \\longrightarrow %s",a); return s; } char *ppIsExpSeq(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\nis\\!-\\!\\!<%s:%s> \\longrightarrow %s",a,b,c); return s; } char *ppIsExpEmptySet(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\nis\\!-\\!\\!\\{\\} \\longrightarrow %s",a); return s; } char *ppIsExpSet(char *a,char *b,char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\nis\\!-\\!\\!\\{%s:%s\\} \\longrightarrow %s",a,b,c); return s; } char *ppIsExpEmptyFF(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\nis\\!-\\!\\![] \\longrightarrow %s",a); return s; } char *ppIsExpFF(char *a,char *b,char *c,char *d) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+strlen(d)+255,sizeof(char)); sprintf(s,"\nis\\!-\\!\\!<%s \\hookrightarrow %s : %s> \\longrightarrow %s",a,b,c,d); return s; } char *ppInv(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\INV{%s} = %s",a,b); return s; } char *ppLambda(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\LAMBDA{%s}.%s",a,b); return s; } char *ppInclude(char *a,char *b) { char *s; if (!strcmp(b,"")) { s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\INCLUDE{%s}",a); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\n\\INCLUDE{%s.%s}",a,b); } return s; } char *ppBeginModel(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n\\MODEL{%s}",a); return s; } char *ppString(char *a) { int i,j; char *s; s = (char *)calloc(strlen(a)*2,sizeof(char)); i = 0; j = 0; while (a[i] != '\0') { if (a[i] != '_') { s[j] = a[i]; ++i; ++j; } else { s[j] = '\\'; s[j+1] = '_'; ++i; j+=2; } } s[j] = '\0'; return s; }