%{ #define YY_DECL char* yylex() void; char* strdup(); int in_sequence = 0; /*--( Analizador Léxico )------------------------------------------*/ /* char *versao_lex="@(#) Versao <%M%%I%(%E%)>"; char *str_save(char *s) { char *strcpy(); return (strcpy((char *)malloc(strlen(s)+1),s)); } void comentario(); void poe_directo(); #include #if INTERACTIVE || FUNC #ifndef PIPE #if !FUNC #include #endif /*!FUNC */ /* #undef YY_INPUT #define YY_INPUT(buf,result,max_size) \ { \ int c = jjgetc( yyin ); \ result = c == EOF ? 0 : 1; \ buf[0] = (char) c; \ } static char* line_read = (char *)NULL; #ifdef FUNC extern char * S_GLOBI; static int jjgetc(FILE *fp) { static int p=0; if(line_read == (char *)NULL) { line_read=S_GLOBI; p=0; } if(*(line_read+p) == '\0') return EOF; else return(*(line_read+(p++))); } #else /* FUNC */ /* int do_gets() { int ret; if(line_read != (char *)NULL) { free (line_read); line_read=(char *) NULL; } if(setjmp( xljmpbuf )) { exit(1); } ret=(int)(line_read = readline("?- ")); if(line_read && *line_read) add_history(line_read); return(ret); } static int jjgetc(FILE* fp) { static int p=0; if((line_read == (char *)NULL) || (*(line_read+p) == '\0') ) { if(do_gets()== EOF) return EOF; p = 0; return 10; } else return(*(line_read+(p++))); } #endif /* FUNC*/ /* #else /*PIPE */ /* #undef YY_INPUT /* #define YY_INPUT(buf,result,max_size) \ { \ int c = getchar(); \ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ } #endif /*PIPE */ /* #endif /* INTERACTIVE */ int contachav; char mboxstr[200]; %} char buffer[15]; char* lvalue = NULL; INT ([+-]?[0-9]+) NUMBER ([+-]?[0-9]+\.[0-9]+) STR (\"([^\"\n]|\\\")*\") BOOL (true|false) SIMBOLO ([a-zA-Z0-9\$\_\!áéíóúàâêôãõçÁÉÍÓÚÀÂÊÔÃÕÇ]+) QUOTE (\') CONS ({INT}|{REAL}|{STR}|{BOOL}|{QUOTE}{SIMBOLO}) %option yylineno %x metoo com pod mbox %o 5000 %a 4000 %p 3200 %% %{ /*--( Codigo METOO )---------------------------------------------------*/ %} ^metoo { BEGIN metoo; } ^endmetoo { BEGIN 0; } .* { /* poe_directo(yytext); [TODO]*/ } \n { #ifdef FLEX_SCANNER /* yylineno++; */ #endif } %{ /*--( Includes )-------------------------------------------------------*/ %} ^#include { return strcpy(buffer,"INCLUDE"); } ^#debugon { return strcpy(buffer,"DEBUGON"); } ^#debugoff { return strcpy(buffer,"DEBUGOFF"); } ^#includemetoo { return strcpy(buffer,"INCLUDEM"); } %{ /*--( Constantes: Int. String Bool Quote )-----------------------------*/ %} {INT} { lvalue = strdup(yytext); return strcpy(buffer,"INTEGER"); } {NUMBER} { lvalue = strdup(yytext); return strcpy(buffer,"INTEGER"); } {STR} { lvalue = strdup(yytext); return strcpy(buffer,"STRING"); } {BOOL} { lvalue = strdup(yytext); return strcpy(buffer,"BOOL"); } {QUOTE}{SIMBOLO} { lvalue = strdup(yytext); return strcpy(buffer,"CONSTANTE"); } %{ /*--( Palavras reservadas )--------------------------------------------*/ %} let return strcpy(buffer,"LET"); in return strcpy(buffer,"IN"); notin return strcpy(buffer,"NOTIN"); if return strcpy(buffer,"IF"); then return strcpy(buffer,"THEN"); else return strcpy(buffer,"ELSE"); otherwise return strcpy(buffer,"OTHER"); lambda return strcpy(buffer,"LAMBDA"); inv return strcpy(buffer,"INV"); PRE|pre return strcpy(buffer,"PRE"); U return strcpy(buffer,"UNION"); "&&"|\/\\ return strcpy(buffer,"AND"); "||"|\\\/ return strcpy(buffer,"OR"); "=>" return strcpy(buffer,"IMPLICA"); \* return strcpy(buffer,"INTER"); or return strcpy(buffer,"OR2"); NIL return strcpy(buffer,"NIL"); MODEL return strcpy(buffer,"MODEL"); ENDMODEL return strcpy(buffer,"ENDMODEL"); TYPE return strcpy(buffer,"TYPE"); ENDTYPE return strcpy(buffer,"ENDTYPE"); \*FUNC|\*fun { lvalue = strdup(yytext); return strcpy(buffer, "FUNCAO"); } FUNC|func { lvalue = strdup(""); return strcpy(buffer, "FUNCAO"); } STATE|state return strcpy(buffer,"ESTADO"); RETURN(S)?|return(s)? return strcpy(buffer,"RETUR"); all|ALL return strcpy(buffer,"ALL"); exist|EXIST return strcpy(buffer,"EXIST"); exist1|EXIST1 return strcpy(buffer,"EXIST1"); \^\-orio return strcpy(buffer,"CONCATORIO"); \-orio return strcpy(buffer,"ORIO"); \-red return strcpy(buffer,"ORIO"); \-list return strcpy(buffer,"LIST"); \-seq return strcpy(buffer,"LIST"); \-set return strcpy(buffer,"SET"); is\- return strcpy(buffer,"IS"); in\- return strcpy(buffer,"TIN"); out\- return strcpy(buffer,"TOUT"); id\- return strcpy(buffer,"ID"); \:\: return strcpy(buffer,"P4"); \=\= return strcpy(buffer,"EQ"); \\ return strcpy(buffer,"BSLASH"); \~ return strcpy(buffer,"NOT"); \+ return strcpy(buffer,"PLUS"); \+\+ return strcpy(buffer,"STRCAT"); \.\+ return strcpy(buffer,"ADD"); \.\- return strcpy(buffer,"SUB"); \.\* return strcpy(buffer,"MUL"); \.\/ return strcpy(buffer,"DIV"); \<\-\> return strcpy(buffer,"RELACAO"); \<\- return strcpy(buffer,"PERTENCE"); _o_ return strcpy(buffer,"COMP"); _x_|×|\>\< return strcpy(buffer,"FPROD"); _\+_ return strcpy(buffer,"FADD"); \-\|\-_ return strcpy(buffer,"FADD"); _c return strcpy(buffer,"CONSF"); \-\> return strcpy(buffer,"SETA"); \-\>\* return strcpy(buffer,"FSETA"); \-\-\> return strcpy(buffer,"SSETA"); \*\-\> return strcpy(buffer,"FSETA2"); \>\= return strcpy(buffer,"GEQ"); \<\= return strcpy(buffer,"LEQ"); \!\= return strcpy(buffer,"NEQ"); \[\* return strcpy(buffer,"RELBEGIN"); \*\] return strcpy(buffer,"RELEND"); quit\. return strcpy(buffer,"QUIT"); \*\= { lvalue = strdup(yytext); return strcpy(buffer,"="); } !nl return strcpy(buffer,"NEWLINE"); !caixa\( return strcpy(buffer,"BEGINARRAY"); %{ /*--( Simbolos )-------------------------------------------------------*/ %} do { lvalue = strdup("progn"); return strcpy(buffer, "SIMB"); } bool|BOOL return strcpy(buffer,"TBOOL"); {SIMBOLO} { lvalue = strdup(yytext); return strcpy(buffer, "SIMB");} {QUOTE} return strcpy(buffer,"QUOTE"); %{ /*--( Comentarios )----------------------------------------------------*/ %} nyavail\{ { BEGIN mbox; contachav = 1; strcpy(mboxstr,"\\mbox{");} \} { strcat(mboxstr,yytext); if(--contachav == 0) { BEGIN 0; lvalue = strdup(mboxstr); return strcpy(buffer, "NYAVAIL");} } \{ { contachav++; strcat(mboxstr,yytext); } \||\\\\|\n { strcat(mboxstr, "}\\\\\\mbox{" ); } . { strcat(mboxstr,yytext); } ^= { BEGIN pod;} ^=cut { BEGIN 0;} .|\n ; \= { lvalue = strdup(""); return strcpy(buffer,"="); } \/\* { BEGIN com;} \*\/ { BEGIN 0;} .|\n ; ^\;.* { /* comentario(yytext); [TODO] */ } ^\#\!.* { /* comentario(yytext); [TODO] */ } %{ /*--( outros )---------------------------------------------------------*/ %} \n { #ifdef FLEX_SCANNER /* yylineno++; */ #endif } " "|" " ; > { if (in_sequence) return strcpy(buffer,">"); else return strcpy(buffer,"GT"); } . { return strcpy(buffer,yytext); } %% int pwrap(void) { return 1; } int plexlineno(void) { return plineno; } char* plextext(void) { if (lvalue) { char* t = lvalue; lvalue = NULL; return t; } return ptext; } int plexinit(char* file) { yyin = fopen(file,"r"); return (yyin?1:0); } void set_in_sequence(int v) { in_sequence = v; } int get_in_sequence(void) { return in_sequence; }