%{ @ifdef TAGS #define tags(x) x @else #define tags(x) 0 @endif #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(char *e); void yyerror(char *s); @ifdef NYAG apsexp lambdaexp(aplista l,apsexp e); aplista insereEQ(aplista itipo); apsexp deffuncao(char *nome,aplista para,apsexp assin, apsexp pre,apsexp exep,apsexp post); apsexp poscondicao(apsexp estado,apsexp expressao,int n); apsexp lambdaexpfunc(aplista para,apsexp pre,apsexp exep,apsexp post); @endif @ifdef TAGS void gera_tag_pair(char *nome); void geratag(char *nome); @endif extern FILE *yyin, *yyout; extern int yylineno; extern char yytext[]; @ifdef PRETTY void ppPrint(char *s); void ppBeginDefType(); void ppEndDefType(); char *ppDefType(char *a,char *b,char *c); char *ppProdExp(char *a); char *ppProdComp(char *a,char *b); char *ppProd(char *a,char *b); char *ppProd2(char *a,char *b); char *ppFmat(char *a,char *b); char *ppFfun(char *a,char *b); char *ppProdItem(char *a,char *b); char *ppBrel(char *a,char *b); char *ppList(char *a); char *ppInseg(char *a); char *ppSet(char *a); char *ppInt(); char *ppPlus(char *a,char *b); char *ppAlt(char *a); char *ppArgItem(char *a); char *ppTypItem(char *a); char *ppArgList(char *a,char *b); char *ppTypList(char *a,char *b); char *ppSign(char *a,char *b); char *ppPrintFunc(char *a,char *b,char *c,char *d,char *e, int compact); char *ppPrintAuxFunc(char *a,char *b,char *c, int compact); char *ppLetIn(char *a,char *b); char *ppDefVar(char *a,char *b); char *ppExpExpList(char *a,char *b); char *ppSymExpList(char *a,char *b); char *ppExpList(char *a,char *b); char *ppExpAdd(char *a,char *b); char *ppExpSub(char *a,char *b); char *ppExpDiv(char *a,char *b); char *ppExpInfix(char *a,char *b, char *c); char *ppFracExp(char *a,char *b); char *ppExpMul(char *a,char *b); char *ppBool(char *a); char *ppBoolIn(char *a,char *b); char *ppBoolNotin(char *a,char *b); char *ppBoolEQ(char *a,char *b); char *ppBoolAnd(char *a,char *b); char *ppNlOr(char *a,char *b); char *ppBoolOr(char *a,char *b); char *ppBoolImplies(char *a,char *b); char *ppBoolNot(char *a); char *ppBoolLT(char *a,char *b); char *ppBoolGT(char *a,char *b); char *ppBoolLEQ(char *a,char *b); char *ppBoolGEQ(char *a,char *b); char *ppBoolNEQ(char *a,char *b); char *ppDomSub(char *a,char *b); char *ppDomRst(char *a,char *b); char *ppDomMap(char *a,char *b); char *ppSetCard(char *a); char *ppStrExp(char *a); char *ppStrCat(char *a,char *b); char *ppLetExp(char *a,char *b); char *ppState(char *a,char *b); char *ppStateAtrib(char *a,char *b); char *ppSeqExp(char *a); char *ppSeqEmpty(); char *ppSeqCons(char *a,char *b); char *ppSeqEnum(char *a,char *b); char *ppSeqAppend(char *a,char *b); char *ppSetExp(char *a); char *ppSetEmpty(); char *ppSetInter(char *a,char *b); char *ppSetUnion(char *a,char *b); char *ppSetDifer(char *a,char *b); char *ppSetComp(char *a,char *b); char *ppSetEnum(char *a,char *b); char *ppFfunExp(char *a); char *mynl(char *a); char *myarray(char *a); char *ppFfunPair(char *a,char *b); char *ppFfunPlus(char *a,char *b); char *ppFfunPairList(char *a,char *b); char *ppFfunComp(char *a,char *b,char *c); char *ppFfunEmpty(); char *ppFrom(char *a,char *b); char *ppFromAnd(char *a,char *b,char *c); char *ppFromAndFrom(char *a,char *b); char *ppAndFrom(char *a); char *ppFromList(char *a,char *b); char *ppIfThen(char *a,char *b); char *ppIfThenElse(char *a,char *b,char *c); char *ppBrace(char *a); char *ppDefList(char *a,char *b); char *ppIsTypeExp(char *a,char *b); char *ppNull() ; char *ppADD() ; char *ppMUL() ; char *ppPLUS() ; char *ppAND() ; char *ppAND() ; char *ppOR() ; char *ppOR() ; char *ppSTRCAT() ; char *ppOrio(char *a,char *b,char *c); void ppBeginFunc(int i); void ppBeginObj(); void ppEndObj(); void ppEndFunc(int i); char *ppReturnState(char *a,char *b); char *ppPreExp(char *a); char *ppIfCase(char *a); char *ppIfCaseExp(char *a,char *b); char *ppIfCaseList(char *a,char *b); char *ppIfCaseElse(char *a); char *ppIfCaseOther(char *a,char *b); char *ppForAllAnd(char *a,char *b,char *c); char *ppForAllList(char *a,char *b,char *c); char *ppExistAnd(char *a,char *b,char *c); char *ppExistList(char *a,char *b,char *c); char *ppExist1And(char *a,char *b,char *c); char *ppExist1List(char *a,char *b,char *c); char *ppSorts(); char *ppOpers(); char *ppFSetExp(char *a); char *ppFSeqExp(char *a); char *ppFSetaExp(char *a); char *ppFSeta2Exp(char *a); char *ppFProdExp(char *a,char *b); char *ppFCompExp(char *a,char *b); char *ppIdExp(char *a); char *ppCstExp(char *a); char *ppIsExpEmptySeq(char *a,char *b); char *ppIsExpSeq(char *a,char *b,char *c,char *d); char *ppIsExpEmptySet(char *a, char *b); char *ppIsExpSet(char *a,char *b,char *c,char *d); char *ppIsExpEmptyFF(char *a, char *b); char *ppIsExpFF(char *a,char *b,char *c,char *d,char *e); char *ppInv(char *a,char *b); char *ppLambda(char *a,char *b); char *ppInclude(char *a,char *b); char *ppBeginModel(char *a); char *ppString(char *a); @endif #include /* ---(Formata output )-------------------------------------------------*/ @ifdef NYAG static int queres_comentarios=1; @endif @ifdef PRETTY static int queres_comentarios=0; @endif @ifdef TAGS static int queres_comentarios=0; @endif #if INTERACTIVE || FUNC #include "iformata.c" #else #include "formata.c" #endif struct t_tipo { char ti[5]; struct t_tipo *arg1, *arg2, *next; }; typedef struct t_tipo TIPO; typedef struct t_tipo *APTIPO; %} @ifdef NYAG %union {char *str; APTIPO Tipo; struct{ apsexp s1; apsexp s2;} yypar; struct{ aplista par; apsexp sig;} yysig; struct{ aplista par; aplista partyp;} yysiglist; apsexp yysexp; aplista yylista;} @endif @ifdef PRETTY %union { char *str; struct { char *arg; char *typ; } sig; } @endif @ifdef TAGS %union { char *str; } @endif %{ /* *** Simbolos Terminais *** */ %} %token NYAVAIL SIMB CONSTANTE INTEGER STRING BOOL FUNCAO '=' %token SET LIST TYPE ENDTYPE P4 NIL RELACAO INCLUDE INCLUDEM DEBUGON TBOOL %token DEBUGOFF QUIT MODEL ENDMODEL FSETA2 INV COMP FPROD FADD DEFTYPE %{ /* *** fim de definicao de terminais *** */ %} %{ /* *** prioridades e associatividades: *** */ %} %nonassoc minima %nonassoc ';' %left ',' %nonassoc FUNCAO %nonassoc LAMBDA %nonassoc baixa %nonassoc SSETA %nonassoc LET OTHER SETA IF THEN RELBEGIN RELEND PRE ESTADO %nonassoc PERTENCE ELSE RETUR ALL EXIST EXIST1 %nonassoc '>' %left IMPLICA %left AND %left OR OR2 %left NOT %nonassoc EQ NEQ LEQ GEQ '<' GT %nonassoc TRIPLO %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 '(' BEGINARRAY NEWLINE %left COMP %left FSETA LIST SET %right FSETA2 %left FADD %left FPROD %nonassoc CONSF ID IS TIN TOUT ':' ORIO QUOTE %right maxima %nonassoc maximam %{ /* *** fim de definicao de prioridades *** */ %} %{ /* *** Simbolos Nao Terminais *** */ %} %type astop @ifdef NYAG %type tag %type precond %type deffuncao defobj exp ffexp setexp seqexp letexp ifexp %type boolexp relexp estado /* mensagem*/ 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 expFPlist expFAlist %type assinatura %type defTp funcmat tuplo rtuplo rtuplo2 %type itemtuplo funcfin relacao lista conjunto %type alternativa2 alternativa simpleType %type segmentoInicial defTipo idTipo @endif @ifdef PRETTY %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 funcmat tuplo rtuplo rtuplo2 %type itemtuplo funcfin relacao lista conjunto %type alternativa2 alternativa simpleType %type segmentoInicial defTipo idTipo expFPlist expFAlist @endif %% especificacao : especificacao typesMod | especificacao bloco | especificacao ENDMODEL | especificacao MODEL SIMB { @ifdef PRETTY printf("%s",ppBeginModel($3)); } | ; /*--( Definicao de tipos )-------------------------------------------*/ defTipo : idTipo '=' defTp inv ';' { @ifdef NYAG $$ = funnar("deftype",cons($1, $3)); if($4){ char s[80]; sprintf(s,"inv_%s", atomo($1)); fimdef(_def(mkatconst(s),$4));} @endif @ifdef PRETTY ppPrint(ppDefType($1,$3,$4)); } | idTipo P4 defTp inv ';' { @ifdef NYAG $$ = funnar("deftype",cons($1, $3)); if($4){ char s[80]; sprintf(s,"inv_%s", atomo($1)); fimdef(_def(mkatconst(s),$4));} @endif @ifdef PRETTY ppPrint(ppDefType($1,$3,$4)); } | error ';' { yyerrok; @ifdef NYAG $$ = mkatconst(";ERROR"); } ; inv : INV '(' SIMB ')' '=' {CONTEXTO='d';} exp {CONTEXTO='t'; @ifdef NYAG $$=lambdaexp(cons(mkatomo($3),nill),$7); @ifdef PRETTY $$=ppInv(ppString($3),$7); } | @ifdef NYAG {$$=NULL;} @ifdef PRETTY {$$ = ppNull();} ; idTipo: SIMB { @ifdef NYAG $$ = mkatomo($1); @ifdef PRETTY $$ = ppString($1); } ; defTp: simpleType { @ifdef NYAG $$ = (CONTEXTO == 't')?insereEQ($1): $1 ; @ifdef PRETTY $$ = $1; } | alternativa2 { @ifdef NYAG { char s[80],*s1;; sprintf(s,"_%d", cont_alt++); s1=strdup(s); fimdef(funnar("deftype",cons(mkatconst(s),cons(mkatconst("ALT"),$1 )))); $$ = cons(mkatconst("TUP (tag ANY)"), lista1(mkpair(mkatconst("val"),mkatomo(s1) ))); } @endif @ifdef PRETTY $$ = $1; /*DANGER*/ } | alternativa { @ifdef NYAG $$ = cons(mkatconst("ALT"),$1 ); @ifdef PRETTY $$ = $1; } | simpleType INTER rtuplo2 %prec baixa { /* simple tuplo */ @ifdef NYAG $$ = cons(mkatconst("TUP"), cons(funnar("_p1",$1), $3)); @ifdef PRETTY $$ = ppProd2($1,$3); /* DANGER */ } | funcmat { @ifdef NYAG $$ = $1; @ifdef PRETTY $$ = $1; } | tuplo { @ifdef NYAG $$ = $1; @ifdef PRETTY $$ = ppProdExp($1); } ; funcmat : SSETA simpleType { @ifdef NYAG $$ = cons(mkatconst("ANY"),nill); @ifdef PRETTY $$ = ppFmat("",$2); } | simpleType SSETA simpleType { @ifdef NYAG $$ = cons(mkatconst("ANY"),nill); @ifdef PRETTY $$ = ppFmat($1,$3); } | simpleType INTER rtuplo2 SSETA simpleType %prec baixa { @ifdef NYAG $$ = cons(mkatconst("ANY"),nill); @ifdef PRETTY $$ = ppFmat(ppProd2($1,$3),$5); } ; simpleType : SIMB { @ifdef NYAG $$ = cons(mkatomo($1), nill); @ifdef PRETTY $$ = ppString($1); } | NIL { @ifdef NYAG $$ = cons(mkatconst("NIL"), nill); @ifdef PRETTY $$ = strdup("nil"); } | relacao { @ifdef NYAG $$ = $1; @ifdef PRETTY $$ = $1; } | funcfin { @ifdef NYAG $$ = $1; @ifdef PRETTY $$ = $1; } | TBOOL { @ifdef NYAG $$ = cons(mkatconst("SYM"), nill); @ifdef PRETTY $$ = ppString("Bool"); } | lista { @ifdef NYAG $$ = $1; @ifdef PRETTY $$ = $1; } | conjunto { @ifdef NYAG $$ = $1; @ifdef PRETTY $$ = $1; } | segmentoInicial { @ifdef NYAG $$ = cons($1, nill); @ifdef PRETTY $$ = $1; } | '(' simpleType ')' { @ifdef NYAG $$ = $2; @ifdef PRETTY $$ = ppBrace($2); } | '(' funcmat ')' { @ifdef NYAG $$ = $2; @ifdef PRETTY $$ = ppBrace($2); } | NYAVAIL { @ifdef NYAG $$ = cons(mkatconst("ANY"), nill); @ifdef PRETTY $$ = myarray($1); } ; rtuplo2 : simpleType %prec baixa { @ifdef NYAG $$ = cons(funnar("_p2",$1), nill); cont_tup=3; @ifdef PRETTY $$ = $1; /* DANGER */ } | rtuplo2 INTER simpleType %prec baixa { @ifdef NYAG $$ = conc($1, cons(mklista(cons(mkatomo(idtup()),$3)), nill)); @ifdef PRETTY $$ = ppProd2($1,$3); /* DANGER */ } ; tuplo : itemtuplo rtuplo { @ifdef NYAG $$ = cons(mkatconst("TUP"), conc($1, $2)); @ifdef PRETTY $$ = ppProd($1,$2); } ; rtuplo: itemtuplo rtuplo { @ifdef NYAG $$ = conc($1, $2); @ifdef PRETTY $$ = ppProd($1,$2); } | { @ifdef NYAG $$ = nill; @ifdef PRETTY $$ = ppNull(); } ; itemtuplo : SIMB ':' simpleType %prec baixa { @ifdef NYAG $$ = cons(mklista(cons(mkatomo($1),$3)), nill); @ifdef PRETTY $$ = ppProdItem(ppString($1),$3); } ; itemtuplo : INTER SIMB ':' simpleType %prec baixa { @ifdef NYAG $$ = cons(mklista(cons(mkatomo($2),$4)), nill); @ifdef PRETTY $$ = ppProdItem(ppString($2),$4); } ; funcfin : simpleType SETA simpleType { @ifdef NYAG $$ = cons(mkatconst("FF"), conc($1,$3)); @ifdef PRETTY $$ = ppFfun($1,$3); } ; relacao : simpleType RELACAO simpleType { @ifdef NYAG $$ = cons(mkatconst("REL"), conc($1,$3)); @ifdef PRETTY $$ = ppBrel($1,$3); } ; lista : SIMB LIST { @ifdef NYAG $$ = lista2(mkatconst("LIST"), mkatomo($1)); @ifdef PRETTY $$ = ppList(ppString($1)); } | TBOOL LIST { @ifdef NYAG $$ = lista2(mkatconst("LIST"), mkatconst("SYM")); @ifdef PRETTY $$ = ppList(ppString("bool")); } | '(' simpleType ')' LIST { @ifdef NYAG $$ = cons(mkatconst("LIST"), $2); @ifdef PRETTY $$ = ppList($2); } | segmentoInicial LIST { @ifdef NYAG $$ = lista2(mkatconst("LIST"), $1); @ifdef PRETTY $$ = ppList($1); } ; conjunto : SIMB SET { @ifdef NYAG $$ = lista2(mkatconst("SET"), mkatomo($1)); @ifdef PRETTY $$ = ppSet(ppString($1)); } | TBOOL SET { @ifdef NYAG $$ = lista2(mkatconst("SET"), mkatconst("SYM")); @ifdef PRETTY $$ = ppList(ppString("bool")); } | '(' simpleType ')' SET { @ifdef NYAG $$ = cons(mkatconst("SET"), $2); @ifdef PRETTY $$ = ppSet($2); } | segmentoInicial SET { @ifdef NYAG $$ = lista2(mkatconst("SET"), $1); @ifdef PRETTY $$ = ppSet($1); } ; segmentoInicial : INTEGER { @ifdef NYAG $$ = mkatconst("INT"); @ifdef PRETTY $$ = ppInt(); } ; alternativa : '[' simpleType ']' %prec baixa { @ifdef NYAG $$ = cons(mkatconst("NIL"), $2); @ifdef PRETTY $$ = ppAlt($2); } | simpleType '|' simpleType %prec baixa { @ifdef NYAG $$ = conc($1,$3); @ifdef PRETTY $$ = ppPlus($1,$3); } | alternativa '|' '[' simpleType ']' %prec baixa { @ifdef NYAG $$ = conc($1,cons(mkatconst("NIL"),$4 )); @ifdef PRETTY $$ = ppPlus($1,$4); } | alternativa '|' simpleType %prec baixa { @ifdef NYAG $$ = conc($1,$3 ); @ifdef PRETTY $$ = ppPlus($1,$3); } ; alternativa2 : simpleType PLUS simpleType %prec baixa { @ifdef NYAG $$ = conc($1,$3); @ifdef PRETTY $$ = ppPlus($1,$3); } | alternativa2 PLUS simpleType %prec baixa { @ifdef NYAG $$ = conc($1,$3 ); @ifdef PRETTY $$ = ppPlus($1,$3); } ; /*--( Definicao de tipos nos modulos )-------------------------------*/ typesMod : TYPE {CONTEXTO='t'; @ifdef PRETTY ppBeginDefType(); } defTipo { @ifdef NYAG fimdef($3); } restDefTypesMod @ifdef PRETTY { ppEndDefType(); } ENDTYPE {CONTEXTO='d';} | DEFTYPE {CONTEXTO='t'; @ifdef PRETTY ppBeginDefType(); } defTipo { @ifdef PRETTY { ppEndDefType(); } @ifdef NYAG fimdef($3); CONTEXTO='d'; } ; restDefTypesMod : defTipo { @ifdef NYAG fimdef($1); } restDefTypesMod | ; /*--( Bloco = (deffuncao+include+teste)* )---------------------------*/ bloco : bloco elemento | elemento ; elemento : exp ';' { @ifdef NYAG fimdef($1); @ifdef PRETTY ppBeginObj(); printf("%s",$1); ppEndObj(); } | include { @ifdef NYAG fimdef($1); @ifdef PRETTY printf("%s",$1); } | ESTADO SIMB ':' tipo ';' { @ifdef NYAG fimdef(_def(mkatconst("_state"), _quote(mkatomo($2)))); @ifdef PRETTY printf("%s",ppState(ppString($2),$4)); } | directiva | deffuncao ';' { @ifdef NYAG fimdef($1); } | error ';' {yyerrok;} elemento | QUIT { @ifdef NYAG fimdef(funnar("!",nill)); return(0);} ; /*--( directivas de debug/outras )-----------------------------------*/ directiva : DEBUGON {jjDEBUG = 1;} | DEBUGOFF {jjDEBUG = 0;} ; /*--( Includes )-----------------------------------------------------*/ include : INCLUDE SIMB '.' SIMB { @ifdef NYAG char comando [80]; sprintf(comando,"seca %s.%s %s.met", $2, $4, $2 ); system (comando); sprintf (comando,"\"%s.met\"", $2); $$=fununa("load",mkatconst(comando)); @endif @ifdef PRETTY $$ = ppInclude(ppString($2),ppString($4)); } | INCLUDE STRING { @ifdef NYAG $$=fununa("nload",mkatomo($2)); @ifdef PRETTY $$ = ppInclude($2,""); } | INCLUDE SIMB { @ifdef NYAG char comando [80]; sprintf(comando,"seca %s %s.met",$2,$2 ); system (comando); sprintf (comando,"\"%s.met\"", $2); $$=fununa("load",mkatconst(comando)); @endif @ifdef PRETTY $$ = ppInclude(ppString($2),""); } | INCLUDEM STRING { @ifdef NYAG $$=fununa("load",mkatomo($2)); } | INCLUDEM SIMB '.' SIMB { @ifdef NYAG char comando [80]; sprintf (comando,"\"%s.%s\"",$2,$4); $$=fununa("load",mkatconst(comando)); @endif } | INCLUDEM SIMB { @ifdef NYAG char comando [80]; sprintf (comando,"\"%s\"",$2); $$=fununa("load",mkatconst(comando)); @endif } ; /*--( definicao de funcoes )-----------------------------------------*/ deffuncao : SIMB '(' explist ')' '=' exp { @ifdef NYAG $$=deffun($1,$3,$6); @ifdef TAGS tags(geratag($1)); @ifdef PRETTY (void)ppBeginFunc(1); (void)printf("%s",ppPrintAuxFunc($1,$3,$6,strlen($5))); (void)ppEndFunc(1); @endif } | SIMB '=' exp %prec baixa { @ifdef NYAG $$=_def(mkatomo($1),$3); @ifdef PRETTY (void)ppBeginObj(); (void)printf("%s",ppPrintAuxFunc($1,"",$3,-1)); (void)ppEndObj(); @endif } | FUNCAO astop SIMB assinatura precond /* mensagem */ poscondicao { @ifdef NYAG $$=deffuncao($3,$4.par,$4.sig,$5.s1,$5.s2,$6); @ifdef TAGS geratag($3); @ifdef PRETTY (void)ppBeginFunc($2?0:1); (void)printf("%s",ppPrintFunc(ppString($3),$4.arg,$4.typ,$5,$6,strlen($1))); (void)ppEndFunc($2?0:1); @endif } ; astop : {$$= NULL;} | INTER {$$= "1";} ; poscondicao : estado retorno { @ifdef NYAG $$= poscondicao($1,$2,1); @ifdef PRETTY $$ = ppReturnState($2,$1); } | retorno estado { @ifdef NYAG $$= poscondicao($1,$2,2); @ifdef PRETTY $$ = ppReturnState($1,$2); } | retorno { @ifdef NYAG $$= poscondicao(snill,$1,1); @ifdef PRETTY $$ = ppReturnState($1,""); } | estado { @ifdef NYAG $$= poscondicao($1,snill,1); @ifdef PRETTY $$ = ppReturnState("",$1); } | LET '(' deflist ')' IN poscondicao { @ifdef NYAG $$=funbin("let",mklista($3),$6); @ifdef PRETTY $$ = ppLetIn($3,$6); } ; retorno : RETUR exp { @ifdef NYAG $$=$2; @ifdef PRETTY $$ = $2; } ; estado : ESTADO exp { @ifdef NYAG $$=$2; @ifdef PRETTY $$ = $2; } ; assinatura : '(' explist2 ')' resultado { @ifdef NYAG $$.par=$2.par; $$.sig=mkpair(mklista($2.partyp),$4); @endif @ifdef PRETTY $$.arg = $2.arg; $$.typ = ppSign($2.typ,$4); @endif } ; resultado : ':' resultado1 { @ifdef NYAG $$=$2; @ifdef PRETTY $$ = $2; } | { @ifdef NYAG $$=mkatconst("NIL"); @ifdef PRETTY $$ = ppNull(); } ; resultado1 : resultado1 tipo { @ifdef NYAG $$=$2; @ifdef PRETTY $$ = $2; } | { @ifdef NYAG $$=mkatconst("NIL"); @ifdef PRETTY $$ = ppNull(); } ; tipo : defTp { @ifdef NYAG $$=mklista($1); @ifdef PRETTY $$ = $1; } ; explist2 : SIMB ':' tipo ',' explist2 { @ifdef NYAG $$.par=cons(mkatomo($1),$5.par); $$.partyp=cons($3,$5.partyp); @endif @ifdef PRETTY $$.arg = ppArgList(ppString($1),$5.arg); $$.typ = ppTypList($3,$5.typ); @endif } | SIMB ':' tipo { @ifdef NYAG $$.par=cons(mkatomo($1),nill); $$.partyp=cons($3,nill); @endif @ifdef PRETTY $$.arg = ppArgItem(ppString($1)); $$.typ = ppTypItem($3); @endif } | SIMB ',' explist2 { @ifdef NYAG $$.par=cons(mkatomo($1),$3.par); $$.partyp=cons(mkatconst("ANY"),$3.partyp); @endif @ifdef PRETTY $$.arg = ppArgList(ppString($1),$3.arg); $$.typ = ppNull(); @endif } | SIMB { @ifdef NYAG $$.par=cons(mkatomo($1),nill); $$.partyp=cons(mkatconst("ANY"),nill); @endif @ifdef PRETTY $$.arg = ppArgItem(ppString($1)); $$.typ = ppNull(); @endif } | '(' SIMB ')' ',' explist2 { @ifdef NYAG $$.par=$5.par;$$.partyp=$5.partyp; @ifdef PRETTY $$.arg = ppArgList(ppString($2),$5.arg); $$.typ = ppNull(); @endif } | '(' SIMB ')' { @ifdef NYAG $$.par=nill;$$.partyp=nill; @ifdef PRETTY $$.arg = ppArgItem(ppString($2)); $$.typ = ppNull(); @endif } | { @ifdef NYAG $$.par=nill;$$.partyp=nill; @ifdef PRETTY $$.arg = ppNull(); $$.typ = ppNull(); @endif } ; precond : PRE exp { @ifdef NYAG $$.s1=$2; $$.s2 = snill; @ifdef PRETTY $$ = $2; /*ppPreExp($2);*/ } | PRE exp SETA exp { @ifdef NYAG $$.s1=$2;$$.s2=$4; @ifdef PRETTY $$ = $2; /*ppPreExp($2);*/ } | { @ifdef NYAG $$.s1=snill;$$.s2=snill; @ifdef PRETTY $$ = ppNull(); } ; /*--( definicao de variaveis de Estado )-----------------------------*/ defobj : SIMB atrib exp %prec baixa { @ifdef NYAG $$=_def(mkatomo($1),$3); @ifdef PRETTY $$ = ppStateAtrib(ppString($1),$3); } | SIMB '.' SIMB atrib exp %prec baixa { @ifdef NYAG $$=funtre("tplus",mkatomo($1),mkatomo($3),$5); @ifdef PRETTY $$ = ppStateAtrib(ppString($1),ppString($5)); } ; atrib : PERTENCE ; /*--( Expressoes )---------------------------------------------------*/ exp : SIMB { @ifdef NYAG $$=mkatomo($1); @ifdef PRETTY $$ = ppString($1); } | BEGINARRAY exp ')' { @ifdef NYAG $$=$2; @ifdef PRETTY $$ = myarray($2); } | exp NEWLINE { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = mynl($1); } | '(' exp ')' { @ifdef NYAG $$=$2; @ifdef PRETTY $$ = $2; } | NYAVAIL { @ifdef NYAG $$=mkatconst("\"not yet available\""); @ifdef PRETTY $$ = myarray($1); } | CONSTANTE { @ifdef NYAG $$=mkatomo($1); @ifdef PRETTY $$ = $1; } /* | exp exp { @ifdef NYAG $$=mklista(cons($1,$2)); @ifdef PRETTY $$ = ppExpExpList($1,$2); } */ | exp '(' explist ')' %prec '(' { @ifdef NYAG $$=mklista(cons($1,$3)); @ifdef PRETTY $$ = ppExpExpList($1,$3); } | FUNCAO assinatura precond /* mensagem */ poscondicao { @ifdef NYAG $$=lambdaexpfunc($2.par,$3.s1,$3.s2,$4); @ifdef PRETTY (void)ppBeginFunc(1); (void)printf("%s",ppPrintFunc("lambda",$2.arg,$2.typ,$3,$4,strlen($1))); (void)ppEndFunc(1); @endif } | LAMBDA '(' explist ')' '.' exp %prec PERTENCE { @ifdef NYAG $$=lambdaexp($3,$6); @ifdef PRETTY $$ = ppLambda($3,$6); } | SIMB '(' explist ')' %prec '(' { @ifdef NYAG $$=mklista(cons(mkatomo($1),$3)); @ifdef TAGS tags(gera_tag_pair($1)); @ifdef PRETTY $$ = ppSymExpList(ppString($1),$3); } | QUOTE '(' explist ')' { @ifdef NYAG $$=mklista(cons(mkatconst("quote"),$3)); } | op_orio ORIO '(' exp ',' exp ')' { @ifdef NYAG $$=funtre("reduce",$4,$1,$6); @ifdef PRETTY $$ = ppOrio($1,$4,$6); } | NIL { @ifdef NYAG $$=mkatconst("NIL"); @ifdef PRETTY $$ = ppString("NIL"); } | defobj { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | strexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$=$1; } | intexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | ffexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | relexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | seqexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | setexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | letexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | ifexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | boolexp { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = $1; } | exp '\\' exp { @ifdef NYAG $$=_ds($1,$3); @ifdef PRETTY $$ = ppDomSub($1,$3); } | exp '/' exp { @ifdef NYAG $$=funbin("dr",$1,$3); @ifdef PRETTY $$ = ppDomRst($1,$3); } | exp '[' exp ']' %prec maxima { @ifdef NYAG $$=_ap($1,$3); @ifdef PRETTY $$ = ppDomMap($1,$3); } | SIMB '.' SIMB { @ifdef NYAG $$=_ap(mkatomo($1), _quote(mkatomo($3))); } | FunctExp ; strexp : STRING { @ifdef NYAG $$=mkatomo($1); @ifdef PRETTY $$ = ppStrExp($1); } | exp STRCAT exp { @ifdef NYAG $$=funbin("strcat",$1,$3); @ifdef PRETTY $$ = ppSeqAppend($1,$3); } ; op_orio : SIMB { @ifdef NYAG $$=mkatomo($1); @ifdef PRETTY $$ = ppString($1); } | ADD { @ifdef NYAG $$=mkatconst("add"); @ifdef PRETTY $$ = ppADD(); } | STRCAT { @ifdef NYAG $$=mkatconst("strcat"); @ifdef PRETTY $$ = ppSTRCAT(); } | MUL { @ifdef NYAG $$=mkatconst("mul"); @ifdef PRETTY $$ = ppMUL(); } | OR { @ifdef NYAG $$=mkatconst("or"); @ifdef PRETTY $$ = ppOR(); } /* | '^' {$$=mkatconst("append");} */ | PLUS { @ifdef NYAG $$=mkatconst("plus"); @ifdef PRETTY $$ = ppPLUS(); } ; /*--( Expressoes Inteiras )----------------------------------------------*/ intexp : INTEGER { @ifdef NYAG $$=mkatomo($1); @ifdef PRETTY $$ = $1; } | '#' exp { @ifdef NYAG $$=fununa("card",$2); @ifdef PRETTY $$ = ppSetCard($2); } | exp ADD exp { @ifdef NYAG $$=funbin("add",$1,$3); @ifdef PRETTY $$ = ppExpInfix($1,"+",$3); } | exp SUB exp { @ifdef NYAG $$=funbin("sub",$1,$3); @ifdef PRETTY $$ = ppExpInfix($1,"-",$3); } | exp DIV exp { @ifdef NYAG $$=funbin("div",$1,$3); @ifdef PRETTY $$ = ppFracExp($1,$3); } | exp MUL exp { @ifdef NYAG $$=funbin("mul",$1,$3); @ifdef PRETTY $$ = ppExpInfix($1,"\\times",$3); } ; /*--( Expressoes Bool )----------------------------------------------*/ boolexp : exp IN exp { @ifdef NYAG $$=_in($1,$3); @ifdef PRETTY $$ = ppBoolIn($1,$3); } | exp NOTIN exp { @ifdef NYAG $$=_not(_in($1,$3)); @ifdef PRETTY $$ = ppBoolNotin($1,$3); } | exp EQ exp { @ifdef NYAG $$=_eq($1,$3); @ifdef PRETTY $$ = ppBoolEQ($1,$3); } | exp AND exp { @ifdef NYAG $$=_and($1,$3); @ifdef PRETTY $$ = ppBoolAnd($1,$3); } | exp IMPLICA exp { @ifdef NYAG $$=_or(_not($1),$3); @ifdef PRETTY $$ = ppBoolImplies($1,$3); } | exp OR2 exp { @ifdef NYAG $$=funbin("or2",$1,$3); @ifdef PRETTY $$ = ppNlOr($1,$3); } | exp OR exp { @ifdef NYAG $$=_or($1,$3); @ifdef PRETTY $$ = ppBoolOr($1,$3); } | NOT exp { @ifdef NYAG $$=_not($2); @ifdef PRETTY $$ = ppBoolNot($2); } /* | exp '<' exp '<' exp %prec TRIPLO { @ifdef NYAG $$=_and(funbin("lt",$1,$3),funbin("lt",copia($3),$5)); @ifdef PRETTY $$ = ppBoolLT(ppBoolLT($1,$3),$5); } */ | exp '<' exp { @ifdef NYAG $$=funbin("lt",$1,$3); @ifdef PRETTY $$ = ppBoolLT($1,$3); } | exp GT exp { @ifdef NYAG $$=funbin("gt",$1,$3); @ifdef PRETTY $$ = ppBoolGT($1,$3); } | exp '>' exp { @ifdef NYAG $$=funbin("gt",$1,$3); @ifdef PRETTY $$ = ppBoolGT($1,$3); } /* | exp LEQ exp LEQ exp %prec TRIPLO { @ifdef NYAG $$=_and(funbin("leq",$1,$3),funbin("leq",copia($3),$5)); @ifdef PRETTY $$ = ppBoolLEQ(ppBoolLEQ($1,$3),$5); } */ | exp LEQ exp { @ifdef NYAG $$=funbin("leq",$1,$3); @ifdef PRETTY $$ = ppBoolLEQ($1,$3); } | exp GEQ exp { @ifdef NYAG $$=funbin("geq",$1,$3); @ifdef PRETTY $$ = ppBoolGEQ($1,$3); } | exp NEQ exp { @ifdef NYAG $$=funbin("nequal",$1,$3); @ifdef PRETTY $$ = ppBoolNEQ($1,$3); } | IS defTp '(' exp ')' { @ifdef NYAG $$=funnar("is",conc($2,cons($4,nill))); @ifdef PRETTY $$ = ppIsTypeExp($2,$4); } | ALL '(' all ')' { @ifdef NYAG $$=$3; @ifdef PRETTY $$=$3; } | EXIST '(' exist ')' { @ifdef NYAG $$=$3; @ifdef PRETTY $$=$3; } | EXIST1 '(' exist1 ')' { @ifdef NYAG $$=$3; @ifdef PRETTY $$=$3; } | BOOL { @ifdef NYAG $$=mkatomo($1); @ifdef PRETTY $$ = ppBool($1); } ; FunctExp : exp SET { @ifdef NYAG $$=fununa("_set",$1); @ifdef PRETTY $$ = ppFSetExp($1); } | exp LIST { @ifdef NYAG $$=fununa("_seq",$1); @ifdef PRETTY $$ = ppFSeqExp($1); } | exp FSETA { @ifdef NYAG $$=fununa("_ffl",$1); @ifdef PRETTY $$ = ppFSetaExp($1); } | FSETA2 exp { @ifdef NYAG $$=fununa("_ffr",$2); @ifdef PRETTY $$ = ppFSeta2Exp($2); } | exp COMP exp { @ifdef NYAG $$=funbin("comp",$1,$3); @ifdef PRETTY $$ = ppFCompExp($1,$3); } | ID exp { @ifdef NYAG $$= _ff1( _list2( mkatconst("_x_"), mkatconst("_x_")), _from(mkatconst("_x_"),$2)); @endif @ifdef PRETTY $$ = ppIdExp($2); } | CONSF exp { @ifdef NYAG $$= _lambda1( mkatconst("_y_"), $2); @ifdef PRETTY $$ = ppCstExp($2); } | expFAlist { @ifdef NYAG $$= fununa("fadd",funnar("list",$1)); @ifdef PRETTY $$ = $1; /* DANGER */ } | expFPlist { @ifdef NYAG $$= fununa("fprod",funnar("list",$1)); @ifdef PRETTY $$ = $1; /* DANGER */ } | TOUT SIMB { @ifdef NYAG $$= fununa("_out_",mkatomo($2)); @ifdef PRETTY $$ = $2; /* ERRO:DANGER */ } | TOUT SIMB '(' exp ')' { @ifdef NYAG $$= funbin("out_",mkatomo($2),$4); @ifdef PRETTY $$ = $4; /* ERRO:DANGER */ } | TIN SIMB { @ifdef NYAG $$= fununa("_in_",mkatomo($2)); @ifdef PRETTY $$ = $2; /* ERRO:DANGER */ } | TIN SIMB '(' exp ')' { @ifdef NYAG $$= funbin("in_",mkatomo($2),$4); @ifdef PRETTY $$ = $4; /* ERRO:DANGER */ } ; expFAlist : exp FADD exp { @ifdef NYAG $$= cons($1,cons($3,nill)); @ifdef PRETTY $$ = ppExpAdd($1,$3); /* DANGER */ } | expFAlist FADD exp { @ifdef NYAG $$= conc($1,cons($3,nill)); @ifdef PRETTY $$ = ppExpAdd($1,$3); /* DANGER */ } ; expFPlist : exp FPROD exp { @ifdef NYAG $$= cons($1,cons($3,nill)); @ifdef PRETTY $$ = ppFProdExp($1,$3); /* DANGER */ } | expFPlist FPROD exp { @ifdef NYAG $$= conc($1,cons($3,nill)); @ifdef PRETTY $$ = ppFProdExp($1,$3); /* DANGER */ } ; all : SIMB PERTENCE exp ',' all { @ifdef NYAG $$=funtre("ALL",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppForAllList(ppString($1),$3,$5); } | SIMB PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("ALL",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppForAllAnd(ppString($1),$3,$5); } | '(' SIMB SETA SIMB ')' PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("ALL",mkatconst("_"), $7, _let(lista2( mkpair(mkatomo($2),_p1(mkatconst("_"))), mkpair(mkatomo($4),_p2(mkatconst("_")))), $9)); @endif @ifdef PRETTY $$ = ppExistAnd(ppFfunPair($2,$4),$7,$9); } ; exist : SIMB PERTENCE exp ',' exist { @ifdef NYAG $$=funtre("EXIST",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppExistList(ppString($1),$3,$5); } | SIMB PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("EXIST",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppExistAnd(ppString($1),$3,$5); } | '(' SIMB SETA SIMB ')' PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("EXIST",mkatconst("_"), $7, _let(lista2( mkpair(mkatomo($2),_p1(mkatconst("_"))), mkpair(mkatomo($4),_p2(mkatconst("_")))), $9)); @endif @ifdef PRETTY $$ = ppExistAnd(ppFfunPair($2,$4),$7,$9); } ; exist1 : SIMB PERTENCE exp ',' exist1 { @ifdef NYAG $$=funtre("EXIST1",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppExist1List(ppString($1),$3,$5); } | SIMB PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("EXIST1",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppExist1And(ppString($1),$3,$5); } | '(' SIMB SETA SIMB ')' PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("EXIST1",mkatconst("_"), $7, _let(lista2( mkpair(mkatomo($2),_p1(mkatconst("_"))), mkpair(mkatomo($4),_p2(mkatconst("_")))), $9)); @endif @ifdef PRETTY $$ = ppExistAnd(ppFfunPair($2,$4),$7,$9); } ; /*--( Set e Seq )----------------------------------------------------*/ setexp : '{' compreensao '}' { @ifdef NYAG $$=funnar("set",$2); @ifdef PRETTY $$ = ppSetExp($2); } | '{' extensao '}' { @ifdef NYAG $$=funnar("makeset",inverte($2)); @ifdef PRETTY $$ = ppSetExp($2); } | '{' '}' { @ifdef NYAG $$=funnar("makeset",nill); @ifdef PRETTY $$ = ppSetEmpty(); } | exp INTER exp { @ifdef NYAG $$=funbin("intersection",$1,$3); @ifdef PRETTY $$ = ppSetInter($1,$3); } | exp UNION exp { @ifdef NYAG $$=funbin("union",$1,$3); @ifdef PRETTY $$ = ppSetUnion($1,$3); } | exp '-' exp { @ifdef NYAG $$=_diff($1,$3); @ifdef PRETTY $$ = ppSetDifer($1,$3); } ; compreensao : exp '|' fromlist { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppSetComp($1,$3); } ; compreensao2 : exp '|' fromlist2 { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppSetComp($1,$3); } ; extensao : extensao ',' exp { @ifdef NYAG $$=cons($3,$1); @ifdef PRETTY $$ = ppSetEnum($1,$3); } | exp { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = ppSetEnum("",$1); } ; seqexp2 : compreensao2 { @ifdef NYAG $$=funnar("seq",$1); @ifdef PRETTY $$ = ppSeqExp($1); } | extensao ',' exp '>' { @ifdef NYAG $$=funnar("makeseq",inverte(cons($3,$1))); @ifdef PRETTY $$ = ppSeqEnum($1,$3); } | exp '>' { @ifdef NYAG $$=funnar("makeseq",cons($1,nill)); @ifdef PRETTY $$ = ppSeqExp($1); } | '>' { @ifdef NYAG $$=funnar("makeseq",nill); @ifdef PRETTY $$ = ppSeqEmpty(); } | exp ':' exp '>' { @ifdef NYAG $$=funbin("cons",$1,$3); @ifdef PRETTY $$ = ppSeqCons($1,$3); } ; seqexp : '<' {in_sequence++ ;} seqexp2 { @ifdef NYAG $$=$3; in_sequence--; @ifdef PRETTY $$ = $3; } | exp '^' exp { @ifdef NYAG $$=funbin("append",$1,$3); @ifdef PRETTY $$ = ppSeqAppend($1,$3); } ; fromlist : from ',' fromlist { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppFromList($1,$3); } | from { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = $1; } ; fromlist2 : from ',' fromlist2 { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppFromAndFrom($1,$3); } | from2 { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = ppAndFrom($1); } ; from : SIMB PERTENCE exp { @ifdef NYAG $$=_from(mkatomo($1),$3); @ifdef PRETTY $$ = ppFrom(ppString($1),$3); } | SIMB PERTENCE exp ':' exp { @ifdef NYAG $$=funtre("from",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppFromAnd(ppString($1),$3,$5); } ; from2 : SIMB PERTENCE exp '>' { @ifdef NYAG $$=_from(mkatomo($1),$3); @ifdef PRETTY $$ = ppFrom(ppString($1),$3); } | SIMB PERTENCE exp ':' exp '>' { @ifdef NYAG $$=funtre("from",mkatomo($1),$3,$5); @ifdef PRETTY $$ = ppFromAnd(ppString($1),$3,$5); } ; /*--( Funcoes finitas e relacoes binarias )--------------------------*/ ffexp : '[' ffcompreensao ']' { @ifdef NYAG $$=funnar("ff1",$2); @ifdef PRETTY $$ = $2; /*ppFfunExp($2);*/ } | '[' exppairlist ']' { @ifdef NYAG $$=funnar("makeff",inverte($2)); @ifdef PRETTY $$ = ppFfunExp($2); } | exp PLUS exp { @ifdef NYAG $$=_plus($1,$3); @ifdef PRETTY $$ = ppFfunPlus($1,$3); } ; ffcompreensao : exp SETA exp '|' fromlist { @ifdef NYAG $$=cons(_list2($1,$3),$5); @ifdef PRETTY $$ = ppFfunComp($1,$3,$5); } ; exppairlist : exppairlist ',' exppair { @ifdef NYAG $$=cons($3,$1); @ifdef PRETTY $$ = ppFfunPairList($1,$3); } | exppair { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = $1; } | { @ifdef NYAG $$=nill; @ifdef PRETTY $$ = ppFfunEmpty(); } ; exppair : exp SETA exp { @ifdef NYAG $$=mkpair($1,$3); @ifdef PRETTY $$ = ppFfunPair($1,$3); } ; relexp : RELBEGIN ffcompreensao RELEND { @ifdef NYAG $$=funnar("rel",$2); } | RELBEGIN exppairlist RELEND { @ifdef NYAG $$=funnar("makerel",inverte($2)); } ; explist : exp ',' explist { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppExpList($1,$3); } | exp { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = ppExpList($1,""); } | { @ifdef NYAG $$=nill; @ifdef PRETTY $$ = ppExpList("",""); } ; /*--( Expressoes condicionais )--------------------------------------*/ letexp : LET '(' deflist ')' IN exp %prec LET { @ifdef NYAG $$=funbin("let",mklista($3),$6); @ifdef PRETTY $$ = ppLetExp($3,$6); } ; deflist : def ',' deflist { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppDefList($1,$3); } | def { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = ppDefList($1,""); } | comdef ',' deflist { @ifdef NYAG $$=conc($1,$3); @ifdef PRETTY $$ = ppDefList($1,$3); } | comdef { @ifdef NYAG $$=$1; @ifdef PRETTY $$ = ppDefList($1,""); } ; comdef : '<' SIMB ':' SIMB GTs '=' exp { @ifdef NYAG $$ = lista3(mkpair(mkatconst("_"),$7), mkpair(mkatomo($2),fununa("head",mkatconst("_"))), mkpair(mkatomo($4),fununa("tail",mkatconst("_")))); @endif @ifdef PRETTY $$ = ppDefVar(ppSeqCons($2,$4),$7); @endif } | '<' SIMB ',' SIMB GTs '=' exp { @ifdef NYAG $$ = lista3(mkpair(mkatconst("_"),$7), mkpair(mkatomo($2),fununa("first",mkatconst("_"))), mkpair(mkatomo($4),fununa("second",mkatconst("_")))); @endif @ifdef PRETTY $$ = ppDefVar(ppSeqEnum($2,$4),$7); @endif } | '<' SIMB ',' SIMB ',' SIMB GTs '=' exp { @ifdef NYAG $$ = lista4(mkpair(mkatconst("_"),$9), mkpair(mkatomo($2),fununa("p1",mkatconst("_"))), mkpair(mkatomo($4),fununa("p2",mkatconst("_"))), mkpair(mkatomo($6),fununa("p3",mkatconst("_")))); @endif @ifdef PRETTY $$ = ppDefVar(ppSeqEnum($2,ppSetEnum($4,$6)),$9); @endif } ; def : SIMB '=' exp { @ifdef NYAG $$=mkpair(mkatomo($1),$3); @ifdef PRETTY $$ = ppDefVar(ppString($1),$3); } | SIMB '(' explist ')' '=' exp { @ifdef NYAG $$=mkpair(mkatomo($1),lambdaexp($3,$6)) ; @ifdef PRETTY $$ = ppDefVar(ppExpExpList($1,$3) ,$6); } | '=' exp { @ifdef NYAG $$=mkpair(mkatconst("__"),$2); @ifdef PRETTY $$ = ppDefVar("__",$2); } ; ifexp : IF exp THEN exp { @ifdef NYAG $$=funbin("if",$2,$4); @ifdef PRETTY $$ = ppIfThen($2,$4); } | IF '(' expcaselist { @ifdef NYAG $$=funnar("cond",$3); @ifdef PRETTY $$ = ppIfCase($3); } | IF exp THEN exp ELSE exp { @ifdef NYAG $$=funtre("if",$2,$4,$6); @ifdef PRETTY $$ = ppIfThenElse($2,$4,$6); } ; expcaselist : casepair ',' expcaselist { @ifdef NYAG $$=cons($1,$3); @ifdef PRETTY $$ = ppIfCaseList($1,$3); } | casepair ')' { @ifdef NYAG $$=cons($1,nill); @ifdef PRETTY $$ = ppIfCaseList($1,""); } | ELSE SETA exp ')' { @ifdef NYAG $$= cons(mkpair(_true,$3), nill); @ifdef PRETTY $$ = ppIfCaseElse($3); } | casepair ')' OTHER exp { @ifdef NYAG $$=cons($1, cons(mkpair(_true,$4), nill)); @ifdef PRETTY $$ = ppIfCaseOther($1,$4); } ; casepair : exp SETA exp { @ifdef NYAG $$=mkpair($1,$3); @ifdef PRETTY $$ = ppIfCaseExp($1,$3); } | is_exp ; is_exp: exp IS '<' SIMB ':' SIMB GTs SETA exp { @ifdef NYAG $$=mkpair( _and(_not(_null($1)), _is(mkatconst("LIST ANY"),copia($1))), _let(lista2(mkpair(mkatomo($4),_hd(copia($1))), mkpair(mkatomo($6),_tl(copia($1)))), $9)); @endif @ifdef PRETTY $$ = ppIsExpSeq($1,$4,$6,$9); } | exp IS '<' GTs SETA exp { @ifdef NYAG $$=mkpair(_null($1),$6); @ifdef PRETTY $$ = ppIsExpEmptySeq($1,$6); } | exp IS '{' SIMB ':' SIMB '}' SETA exp { @ifdef NYAG $$=mkpair(_and(_not(_null($1)), _is(mkatconst("SET ANY"),copia($1))), _let(lista2(mkpair(mkatomo($4),_choice(copia($1))), mkpair(mkatomo($6), _diff(copia($1),_set1(mkatconst($4))))), $9)); @endif @ifdef PRETTY $$ = ppIsExpSet($1,$4,$6,$9); } | exp IS '{' '}' SETA exp { @ifdef NYAG $$=mkpair(_null($1),$6); @ifdef PRETTY $$ = ppIsExpEmptySet($1,$6); } | exp IS '[' SIMB SETA SIMB ':' SIMB ']' SETA exp { @ifdef NYAG $$=mkpair( _and(_not(_null($1)), _is(mkatconst("FF ANY ANY"),copia($1))), _let(lista3(mkpair(mkatomo($4),_choice(_dom(copia($1)))), mkpair(mkatomo($6),_ap($1,mkatomo(copia($4)))), mkpair(mkatomo($8),_ds($1,_set1(mkatomo($4))))), $11)); @endif @ifdef PRETTY $$ = ppIsExpFF($1,$4,$6,$8,$11); } | exp IS '[' ']' SETA exp { @ifdef NYAG $$=mkpair( _null($1), $6); @ifdef PRETTY $$ = ppIsExpEmptyFF($1,$6); } | exp IS tag ':' SIMB SETA exp { @ifdef NYAG $$=mkpair(_and(_not(_null($1)), /*_and(_is(mkatconst("LIST ANY"),copia($1)),)*/ _eq(_p1(copia($1)),mkatomo($3))), _let(lista1(mkpair(mkatomo($5),_p2(copia($1)))), $7)); @endif @ifdef PRETTY $$ = ppIsExpSet($1,$3,$5,$7) ; /* DANGER */ } ; GTs : '>' | GT ; tag : INTEGER /*DANGER ?*/ | SIMB ; %% /* ---(Analisador lexico )----------------------------------------------*/ #include extern jmp_buf xljmpbuf ; #include "lex.yy.c" /* ---(Funcoes auxiliares)----------------------------------------------*/ void met(char s[]) { strcat(strcpy(straux,s),".met"); } char *aspas(char *s) {char *aux; aux=(char *) malloc(strlen(s)+3); return(strcat(strcat(strcpy(aux,"\""),s),"\"")); } @ifdef NYAG /* ---(Definicao de Funcoes )-------------------------------------------*/ apsexp poscondicao(apsexp estado,apsexp expressao,int n) { apsexp aux; if((estado == snill)&&(expressao != snill)) aux = expressao; else if (estado == snill) {erro("Function without postcondition (or ';' misplaced)"); aux = mkatconst("\"????\"");} else if (expressao == snill) aux = estado; else aux = funbin((n==1)?"progn":"prog1", estado, expressao); return(aux); } apsexp deffuncao(char *nome,aplista para,apsexp assin, apsexp pre,apsexp exep,apsexp post) {apsexp defassi,deffu; if(jjDEBUG) /* ----(assinatura: )------------------ */ { fimdef( _def(_ops, _plus( _ops, fununa( "makeff", mkpair( _quote(mkatconst(nome)), /* perigoso ?!! */ _quote(assin)))))); /* ----(definicao : )------------------ */ if (pre == snill) deffu=(deffun(nome,para,post)); else { if (exep == snill) exep = funbin( "strcat", mkatconst("\"ERROR (precondition violated) in function \""), mkatomo(aspas(nome))); deffu=(deffun(nome, para, funtre( "if", pre, post, exep))); } } else /* ----(assinatura: )------------------ */ { fimdef( _def( _ops, _plus( _ops, fununa( "makeff", mkpair( _quote(mkatconst(nome)), /* perigoso ?!! */ _quote( mklista( lista3( el1(lista(assin)), el2(lista(assin)), (pre == snill)?_true:pre)))))))); /* ----(definicao : )------------------ */ deffu=(deffun(nome,para,post)); } return(deffu); } apsexp lambdaexp(aplista l,apsexp e) { return (funbin("lambda", mklista(l), e));} apsexp lambdaexpfunc(aplista para,apsexp pre,apsexp exep,apsexp post) {apsexp defassi,deffu; if(jjDEBUG) /* ----(definicao : )------------------ */ { if (pre == snill) deffu=(lambdaexp(para,post)); else { if (exep == snill) exep = mkatconst("\"ERROR (precondition violated) in function \""); deffu=lambdaexp(para,funtre( "if", pre, post, exep)); } } else /* ----(definicao : )------------------ */ deffu=lambdaexp(para,post); return(deffu); } @endif #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(char *s){ _ERRO=1;} void yyerror(char *s) {_ERRO=1;} #else /*FUNC*/ #include int jjexist(char* s){ FILE *aux; int r; aux = fopen(s,"r"); if(aux){fclose(aux); r=1;} else {errno= r = 0;} return r; } extern int neverprompt; main (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,"%s/.metoorc",getenv("HOME")); if(getenv("HOME") && jjexist(S)) { sprintf(S,"(load \"%s/.metoorc\")",getenv("HOME")); libxmevalstr(S); #ifndef PIPE puts(S+7); #endif /*PIPE*/ } else { /* printf ("Erro: cant find metoorc; continuing anyway\n"); */ } 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++) { if(! neverprompt) puts(argv[i]); sprintf(S,"(def _FILENAME \"%s\" ) ",argv[i]); libxmevalstr(S); if(strcmp((char*)(argv[i] + strlen(argv[i]) -4),".met")==0) sprintf(S,"(load \"%s\" ) ",argv[i]); else sprintf(S,"(nload \"%s\" ) ",argv[i]); libxmevalstr(S); } yyparse(); #else /*INTERACTIVE */ @ifdef PRETTY 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();} @else if((argc ==3) && (!strcmp(argv[1],"-n"))) { yyin = fopen(argv[2],"r"); FILENAME = strdup(argv[2]); fprintf(stderr,"DEBUG1: %s %s %s\n",argv[0],argv[1], argv[2]); yyout = stdout; queres_comentarios=0; NAOBUF(yyout,yyin); yyparse(); } else if((argc ==2) && (!strcmp(argv[1],"-n"))) { yyin = stdin; yyout = stdout; NAOBUF(yyout,yyin); FILENAME = strdup(""); fprintf(stderr,"DEBUG2: %s -n\n",argv[0]); queres_comentarios=0; yyparse(); } /* tags : seca -t file else if((argc ==3) && (!strcmp(argv[1],"-t"))) { _accao = 2; yyin = fopen(argv[2],"r"); FILENAME = strdup(argv[2]); if(yyin) { ftags=fopen("tags.aux","a"); queres_comentarios=0; strcpy(fichin,argv[2]); yyparse(); } else fprintf(stderr,".can't open file '%s'\n",argv[3]); } */ /* prettyp : seca -p infile outfile */ else if((argc == 4) && (!strcmp(argv[1],"-p"))) { _accao = 3; yyin = fopen(argv[2],"r"); FILENAME = strdup(argv[2]); if(yyin) { yyout = fopen(argv[3],"w+"); yyparse();} else fprintf(stderr,"..can't open file '%s'\n",argv[2]); } /* nyag : seca filein fileout */ else if(argc == 3) { _accao = 1; yyin = fopen(argv[1],"r"); FILENAME = strdup(argv[1]); if(yyin) { yyout = fopen(argv[2],"w+"); yyparse();} else fprintf(stderr,"...can't open file '%s'\n",argv[1]); } /* nyag : seca file */ else if(argc ==2) { _accao = 1; yyin = fopen(argv[1],"r"); FILENAME = strdup(argv[1]); if(yyin) yyparse(); else fprintf(stderr,"....can't open file '%s'\n",argv[1]); } else if(argc == 1) yyparse(); else fprintf(stderr,"Use:\n%s [filein [fileout]]\n\ -p filein fileout\n\ -t filein\n",argv[0]); @endif return _ERRO; #endif /*INTERACTIVE */ } /* ---(Tratamento de erros )--------------------------------------------*/ void erro(char *s) { _ERRO=1;fprintf(stderr,"%s %d : semantic ERROR: %s\n",FILENAME, yylineno,s);} void yyerror(char *s) { _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(char *nome) { printf("invocada - %s\n",nome); } @ifdef TAGS void geratag(char *nome) { fprintf(ftags,"%s %s /FUNC\\ [ ]\\ *\\ <%s\\ >/\n",nome,fichin,nome); printf(" %s\n\n",nome); } @endif @ifdef NYAG aplista insereEQ(aplista itipo) { aplista aux = itipo; char *iatomo; if (isatomo(head(itipo))) { iatomo = atomo(head(itipo)); /* se o atomo nao for nenhum dos seguintes: */ if (strcmp(iatomo,"INT") && strcmp(iatomo,"STR") && strcmp(iatomo,"ANY") && strcmp(iatomo, "SYM") ) /* inserir "EQ": */ aux = cons(mkatconst("EQ"), itipo); } return(aux); } @endif @ifdef PRETTY char *ppSorts(); char *ppOpers(); void ppPrint(char *s) { (void)printf("\n%s",s); } void ppBeginDefType() { (void)printf("%s",ppSorts()); (void)printf("\n\\noindent$\\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)); /*jj sprintf(s,"%s & \\cong & %s & %s \\\\",a,b,c);*/ 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 *ppProdComp(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 \\times %s",a,b); 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 *ppProd2(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 \\times %s",a,b); return s; } char *ppFmat(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"%s \\longrightarrow %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(6,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, int compact) { char *s; if (strcmp(d,"")) { s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+strlen(d)+strlen(e)+255,sizeof(char)); if(compact) sprintf(s,"%s:%s \\\\ %s(%s) \\deff \n\\PRE %s \n\\IN %s \n\\ERP",a,c,a,b,d,e); else 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)); if(compact) sprintf(s,"%s:%s \\\\ %s(%s) \\deff %s %s",a,c,a,b,d,e); else 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, int compact) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); if(compact == -1) sprintf(s,"%s \\deff %s",a,c); else if(compact) sprintf(s,"%s(%s) \\deff %s",a,b,c); else 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," %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,"CONC")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\n\\conc (%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)+35,sizeof(char)); if (strlen(b) > 10) { sprintf(s,"\n%s\\left(%s\\right)",a,b); } else { 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 *ppExpInfix(char *a,char *b, char *c) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+ strlen(c)+15,sizeof(char)); sprintf(s,"\n%s %s %s",a,b,c); 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 \\wedge %s",a,b); return s; } char *ppNlOr(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s," %s \\ or\\ %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," %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(a,"")) { s = (char *)calloc(strlen(b)+15,sizeof(char)); sprintf(s,"\\enlist{%s}",b); } else { s = (char *)calloc(strlen(a)+strlen(b)+15,sizeof(char)); sprintf(s,"\\enlist{%s,%s}",a,b); } return s; } char *ppSeqAppend(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+25,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(a,"")) { s = (char *)calloc(strlen(a)+15+strlen(b),sizeof(char)); sprintf(s,"%s",b); } 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( %s \\right)",a); return s; } char *mynl(char *a) { char *s; s = (char *)calloc(strlen(a)+15,sizeof(char)); sprintf(s," %s \\\\ ",a); return s; } char *myarray(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\\hspace{-2mm}\\begin{array}[t]{l}\n%s\n\\end{array}",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(a,"")) { s = (char *)calloc(strlen(b)+255,sizeof(char)); sprintf(s,"%s",b); } else { s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); /* sprintf(s,"\\begin{array}{cc}\n %s & %s \n\\end{array}",a,b); */ sprintf(s,"%s %s",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)"); */ sprintf(s,""); 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)+355,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(strdup("")); } char *ppADD() { return(strdup("+"));} char *ppMUL() { return(strdup(" \\times "));} char *ppPLUS() { return(strdup("+"));} /* problems with \and char *ppAND() { return(strdup("$\\and$"));} */ char *ppAND() { return(strdup(" \\wedge "));} /* problems with \or char *ppOR() { return(strdup("$\\or$"));} */ char *ppOR() { return(strdup(" \\vee "));} char *ppSTRCAT() { return(strdup("$\\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)",b,c); else if (!strcmp(a,"append")) sprintf(s,"\\conc_{%s}(%s)",b,c); else if (!strcmp(a,"+") && !strcmp(b,"0")) sprintf(s,"\\sum %s", c); else if (!strcmp(a," \\times ") && !strcmp(b,"1")) sprintf(s,"\\prod %s", c); else sprintf(s,"%s-red(%s,%s)",a,b,c); return s; } void ppBeginFunc(int i) { if(i) (void)printf("\n\\noindent$\\begin{array}{l}\n"); else (void)printf("\n\\begin{equation}\\begin{array}{l}\n"); } void ppBeginObj() { (void)printf("\n$\\begin{array}{l}\n"); } void ppEndObj() { (void)printf("\n\\end{array}$\\\\\n\n"); } void ppEndFunc(int i) { if(i) (void)printf("\n\\end{array}$\n\n\\traco\n"); else (void)printf("\n\\end{array}\\end{equation}\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; } char *ppIfCaseOther(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n%s \\\\ \n\\OTHERWISE \\VALUE %s \n\\ESAC\n",a,b); 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\\hbox{-set} ",a); return s; } char *ppFSeqExp(char *a) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); //sprintf(s,"\n%s\\!-\\!seq ",a); sprintf(s,"\n%s^* ",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 *ppFracExp(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+25,sizeof(char)); sprintf(s," {%s \\over %s} ",a,b); 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 *b) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n%s\\ is\\!-\\!\\!<> \\VALUE %s",a,b); return s; } char *ppIsExpSeq(char *a,char *b,char *c,char *d) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n%s\\ is\\!-\\!\\!<%s:%s> \\VALUE %s",a,b,c,d); return s; } char *ppIsExpEmptySet(char *a, char *b) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n %s\\ is\\!-\\!\\!\\{\\} \\VALUE %s",a,b); return s; } char *ppIsExpSet(char *a,char *b,char *c,char *d) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+255,sizeof(char)); sprintf(s,"\n %s\\ is\\!-\\!\\!\\{%s:%s\\} \\VALUE %s",a,b,c,d); return s; } char *ppIsExpEmptyFF(char *a, char *b) { char *s; s = (char *)calloc(strlen(a)+255,sizeof(char)); sprintf(s,"\n %s\\ is\\!-\\!\\![] \\VALUE %s",a,b); return s; } char *ppIsExpFF(char *a,char *b,char *c,char *d,char *e) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+strlen(c)+strlen(d)+255,sizeof(char)); sprintf(s,"\n %s\\ is\\!-\\!\\!<%s \\hookrightarrow %s : %s> \\VALUE %s",a,b,c,d,e); return s; } char *ppInv(char *a,char *b) { char *s; s = (char *)calloc(strlen(a)+strlen(b)+255,sizeof(char)); sprintf(s,"\n\\\\ \\ \\hfill\\INV{%s}\\!\\!\\!\\!& \\deff &\\!\\!\\!\\!%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)); if(strcmp(a,"ANY") == 0 ) { strcpy(s,"any");} else if(strcmp(a,"INT") == 0 ) { strcpy(s,"int");} else if(strcmp(a,"STR") == 0 ) { strcpy(s,"str");} else if(strcmp(a,"NIL") == 0 ) { strcpy(s,"\\perp");} else { 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; } @endif