static void tl_getword(int first, int (*tst)(int)) { int i=0; int c; yytext[i++] = (char ) first; c = tl_Getchar(); while (c != -1 && tst(c)) { yytext[i++] = (char) c; c = tl_Getchar(); } /* while (tst(c = tl_Getchar())) * yytext[i++] = c; */ yytext[i] = '\0'; tl_UnGetchar(); }
static void read_upto_closing(int z) { char c, want = (z == '{') ? '}' : ')'; int i = 0, nesting = 0; c = tl_Getchar(); while ((c != want || nesting > 0) && c != -1 && i < 2047) /* yytext is 2048 */ { yytext[i++] = c; if (c == z) { nesting++; } if (c == want) { nesting--; } c = tl_Getchar(); } yytext[i] = '\0'; }
static void getword(int first, int (*tst)(int),int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell) { int i=0; char c; miscell->yytext[i++]= (char ) first; while (tst(c = tl_Getchar(cnt, hasuform, uform))) miscell->yytext[i++] = c; miscell->yytext[i] = '\0'; tl_UnGetchar(cnt); }
static void getword(int first, int (*tst)(int)) { int i=0; char c; yytext_ltl2ba[i++]= (char ) first; while (tst(c = tl_Getchar())) yytext_ltl2ba[i++] = c; yytext_ltl2ba[i] = '\0'; tl_UnGetchar(); }
static int follow(int tok, int ifyes, int ifno, int *cnt, size_t hasuform, char *uform, int *tl_yychar, Miscellaneous *miscell) { int c; char buf[32]; if ((c = tl_Getchar(cnt, hasuform, uform)) == tok) return ifyes; tl_UnGetchar(cnt); *tl_yychar = c; sprintf(buf, "expected '%c'", tok); tl_yyerror(buf, cnt, uform, tl_yychar, miscell); /* no return from here */ return ifno; }
static int follow(int tok, int ifyes, int ifno) { int c; char buf[32]; extern int tl_yychar; if ((c = tl_Getchar()) == tok) return ifyes; tl_UnGetchar(); tl_yychar = c; sprintf(buf, "expected '%c'", tok); tl_yyerror(buf); /* no return from here */ return ifno; }
static void mtl_con(int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell, int *tl_yychar) { char c; c = tl_Getchar(cnt, hasuform, uform); if (c == '_') { miscell->dp_taliro_param.LTL = 0; miscell->TimeCon = getbounds(cnt, hasuform, uform, miscell, tl_yychar); } else { miscell->TimeCon = miscell->zero2inf; tl_UnGetchar(cnt); } }
void tl_parse(void) { Node *n = tl_formula(); if (tl_verbose) { printf("formula: "); dump(n); printf("\n"); } if (tl_Getchar() != -1) { tl_yyerror("syntax error"); tl_errs++; return; } trans(n); }
static int tl_lex(int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell, int *tl_yychar) { int c,ii; do { c = tl_Getchar(cnt, hasuform, uform); miscell->yytext[0] = (char ) c; miscell->yytext[1] = '\0'; if (c <= 0) { Token(';'); } } while (c == ' '); /* '\t' is removed in tl_main.c */ /* get the truth constants true and false and predicates */ if (islower(c)) { getword(c, isalnum_,cnt, hasuform, uform, miscell); if (strcmp("true", miscell->yytext) == 0) { Token(TRUE); } if (strcmp("false", miscell->yytext) == 0) { Token(FALSE); } miscell->tl_yylval = tl_nn(PREDICATE,ZN,ZN,miscell); miscell->type_temp = PREDICATE; miscell->tl_yylval->sym = tl_lookup(miscell->yytext, miscell); /* match predicate index*/ for(ii = 0; ii < miscell->dp_taliro_param.nPred; ii++) { if(miscell->predMap[ii].str != NULL) { if(strcmp(miscell->tl_yylval->sym->name, miscell->predMap[ii].str)==0) { if(miscell->parMap[ii].str == NULL){ miscell->pList.pindex[ii] = PRED; }else{ miscell->pList.pindex[ii] = PREDPAR; } } } } return PREDICATE; } /* get temporal operators */ if (c == '<') { c = tl_Getchar(cnt, hasuform, uform); if (c == '>') { miscell->tl_yylval = tl_nn(EVENTUALLY,ZN,ZN,miscell); miscell->type_temp = EVENTUALLY; mtl_con(cnt, hasuform, uform, miscell,tl_yychar); return EVENTUALLY; } if (c != '-') { tl_UnGetchar(cnt); tl_yyerror("expected '<>' or '<->'", cnt, uform, tl_yychar, miscell); } c = tl_Getchar(cnt, hasuform, uform); if (c == '>') { Token(EQUIV); } tl_UnGetchar(cnt); tl_yyerror("expected '<->'", cnt, uform, tl_yychar, miscell); } switch (c) { case '/' : c = follow('\\', AND, '/', cnt, hasuform, uform, tl_yychar, miscell); break; case '\\': c = follow('/', OR, '\\', cnt, hasuform, uform, tl_yychar, miscell); break; case '&' : c = follow('&', AND, '&', cnt, hasuform, uform, tl_yychar, miscell); break; case '|' : c = follow('|', OR, '|', cnt, hasuform, uform, tl_yychar, miscell); break; case '[' : c = mtl_follow(']', ALWAYS, '[', cnt, hasuform, uform, miscell, tl_yychar); break; case '-' : c = follow('>', IMPLIES, '-', cnt, hasuform, uform, tl_yychar, miscell); break; case '!' : c = NOT; break; case 'U' : miscell->type_temp = U_OPER; mtl_con(cnt, hasuform, uform, miscell,tl_yychar); c = U_OPER; break; case 'R' : miscell->type_temp = V_OPER; mtl_con(cnt, hasuform, uform, miscell,tl_yychar); c = V_OPER; break; case 'X' : miscell->type_temp = NEXT; mtl_con(cnt, hasuform, uform, miscell,tl_yychar); c = NEXT; break; case 'W' : miscell->type_temp = WEAKNEXT; mtl_con(cnt, hasuform, uform, miscell, tl_yychar); c = WEAKNEXT; break; default : break; } Token(c); }
Interval getbounds(int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell, int *tl_yychar) { char cc; Interval time; /* remove spaces */ do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); if (cc!='[' && cc!='(') { tl_UnGetchar(cnt); tl_yyerror("expected '(' or '[' after _", cnt, uform, tl_yychar, miscell); tl_exit(0); } /* is interval closed? */ if (cc=='[') time.l_closed = 1; else time.l_closed = 0; /* remove spaces */ do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); /* get lower bound */ /* Peer reviewed on 2013.11.08 by Dokhanchi, Adel */ miscell->TimeCon.l_par=0; miscell->TimeCon.u_par=0; miscell->lbd = true; time.lbd = getnumber(cc, cnt, hasuform, uform, tl_yychar, miscell); /* Peer reviewed on 2013.11.08 by Dokhanchi, Adel */ time.l_par = miscell->TimeCon.l_par; /*time.u_par = miscell->TimeCon.u_par;*/ if (e_le(time.lbd,miscell->zero,&(miscell->dp_taliro_param))) { tl_UnGetchar(cnt); tl_yyerror("past time operators are not allowed - only future time intervals.", cnt, uform, tl_yychar, miscell); tl_exit(0); } /* remove spaces */ do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); if (cc!=',') { tl_UnGetchar(cnt); tl_yyerror("timing constraints must have the format <num1,num2>.", cnt, uform, tl_yychar, miscell); tl_exit(0); } /* remove spaces */ do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); /* get upper bound */ miscell->lbd = false; time.ubd = getnumber(cc, cnt, hasuform, uform, tl_yychar, miscell); /* Peer reviewed on 2013.11.08 by Dokhanchi, Adel time.l_par = miscell->TimeCon.l_par;*/ time.u_par = miscell->TimeCon.u_par; if (e_ge(time.lbd,time.ubd,&(miscell->dp_taliro_param))) { tl_UnGetchar(cnt); tl_yyerror("timing constraints must have the format <num1,num2> with num1 <= num2.", cnt, uform, tl_yychar, miscell); tl_exit(0); } /* remove spaces */ do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); if (cc!=']' && cc!=')') { tl_UnGetchar(cnt); tl_yyerror("timing constraints must have the format <num1,num2>, where > is from the set {),]}", cnt, uform, tl_yychar, miscell); tl_exit(0); } /* is interval closed? */ if (cc==']') time.u_closed = 1; else time.u_closed = 0; return(time); }
Number getnumber(char cc, int *cnt, size_t hasuform, char *uform, int *tl_yychar, Miscellaneous *miscell) /* get a number from input string */ { /* Peer reviewed on 2013.07.22 by Dokhanchi, Adel */ int sign = 1; int ii = 0; int jj = 0; char strnum[80]; Number num; char temp[80]; int match = 0; if (cc=='-') { sign = -1; do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); } else if (cc == '+') { do { cc = tl_Getchar(cnt, hasuform, uform); } while (cc == ' '); } if (cc=='i') { cc = tl_Getchar(cnt, hasuform, uform); if (cc=='n') { cc = tl_Getchar(cnt, hasuform, uform); if (cc=='f') { if (miscell->dp_taliro_param.ConOnSamples) { num.numi.inf = sign; num.numi.i_num = 0; tl_UnGetchar(cnt); tl_yyerror("Constraints on the number of samples is not supported by Polarity", cnt, uform, tl_yychar, miscell); tl_exit(0); } else { num.numf.inf = sign; num.numf.f_num = 0.0; } } else { tl_UnGetchar(cnt); tl_yyerror("expected a number or a (-)inf in timing constraints!", cnt, uform, tl_yychar, miscell); tl_exit(0); } } else { tl_UnGetchar(cnt); tl_yyerror("expected a number or a (-)inf in timing constraints!", cnt, uform, tl_yychar, miscell); tl_exit(0); } } else if (('0'<=cc && cc<='9') || cc=='.') { strnum[ii++] = cc; for (cc = tl_Getchar(cnt, hasuform, uform); cc!=' '&& cc!=',' && cc!=']' && cc!=')'; cc = tl_Getchar(cnt, hasuform, uform)) { if (ii>=80) { tl_UnGetchar(cnt); tl_yyerror("numeric constants must have length less than 80 characters.", cnt, uform, tl_yychar, miscell); tl_exit(0); } strnum[ii++] = cc; } tl_UnGetchar(cnt); strnum[ii] = '\0'; if (miscell->dp_taliro_param.ConOnSamples) { num.numi.inf = 0; num.numi.i_num = sign*atoi(strnum); tl_UnGetchar(cnt); tl_yyerror("Constraints on the number of samples is not supported by Polarity", cnt, uform, tl_yychar, miscell); tl_exit(0); } else { num.numf.inf = 0; num.numf.f_num = (double)sign*atof(strnum); } } else { temp[jj++] = cc; for (cc = tl_Getchar(cnt, hasuform, uform); cc!=' '&& cc!=',' && cc!=']' && cc!=')'; cc = tl_Getchar(cnt, hasuform, uform)) { if (ii>=80) { tl_UnGetchar(cnt); tl_yyerror("numeric constants must have length less than 80 characters.", cnt, uform, tl_yychar, miscell); tl_exit(0); } temp[jj++] = cc; } tl_UnGetchar(cnt); temp[jj] = '\0'; for(ii = 0; ii < miscell->dp_taliro_param.nPred; ii++) { if(miscell->parMap[ii].str != NULL && miscell->predMap[ii].str == NULL) { if(strcmp(temp, miscell->parMap[ii].str)==0) { miscell->parMap[ii].type = miscell->type_temp; match = 1; miscell->pList.pindex[ii] = PAR; if(miscell->parMap[ii].value != NULL) { miscell->parMap[ii].with_value = true; if (miscell->dp_taliro_param.ConOnSamples) { num.numi.inf = 0; num.numi.i_num = sign*(int)(*(miscell->parMap[ii].value)); tl_UnGetchar(cnt); tl_yyerror("Constraints on the number of samples is not supported by Polarity", cnt, uform, tl_yychar, miscell); tl_exit(0); } else { num.numf.inf = 0; num.numf.f_num = (double)sign*(*(miscell->parMap[ii].value)); } } else { miscell->parMap[ii].with_value = false; if (miscell->dp_taliro_param.ConOnSamples) { num.numi.inf = 0; num.numi.i_num = sign*(int)(miscell->parMap[ii].Range[0]); tl_UnGetchar(cnt); tl_yyerror("Constraints on the number of samples is not supported by Polarity", cnt, uform, tl_yychar, miscell); tl_exit(0); } else { num.numf.inf = 0; num.numf.f_num = (double)sign*(miscell->parMap[ii].Range[0]); } } if(miscell->lbd) { miscell->TimeCon.l_par = 1; } else { miscell->TimeCon.u_par = 1; } } } } if(match == 0) { tl_UnGetchar(cnt); tl_yyerror("expected a number or inf or a paramter or parameter not matched", cnt, uform, tl_yychar, miscell); tl_exit(0); } } return(num); }
static int tl_lex(void) { int c; do { c = tl_Getchar(); yytext_ltl2ba[0] = (char ) c; yytext_ltl2ba[1] = '\0'; if (c <= 0) { Token(';'); } } while (c == ' '); /* '\t' is removed in tl_main.c */ if (islower(c)) { getword(c, isalnum_); if (strcmp("true", yytext_ltl2ba) == 0) { Token(TRUE); } if (strcmp("false", yytext_ltl2ba) == 0) { Token(FALSE); } tl_yylval = tl_nn(PREDICATE,ZN,ZN); tl_yylval->sym = tl_lookup(yytext_ltl2ba); return PREDICATE; } if (c == '<') { c = tl_Getchar(); if (c == '>') { Token(EVENTUALLY); } if (c != '-') { tl_UnGetchar(); tl_yyerror("expected '<>' or '<->'"); } c = tl_Getchar(); if (c == '>') { Token(EQUIV); } tl_UnGetchar(); tl_yyerror("expected '<->'"); } switch (c) { case '/' : c = follow('\\', AND, '/'); break; case '\\': c = follow('/', OR, '\\'); break; case '&' : c = follow('&', AND, '&'); break; case '|' : c = follow('|', OR, '|'); break; case '[' : c = follow(']', ALWAYS, '['); break; case '-' : c = follow('>', IMPLIES, '-'); break; case '!' : c = NOT; break; case 'U' : c = U_OPER; break; case 'V' : c = V_OPER; break; #ifdef NXT case 'X' : c = NEXT; break; #endif default : break; } Token(c); }
static int tl_lex(void) { int c; do { c = tl_Getchar(); yytext[0] = (char ) c; yytext[1] = '\0'; if (c <= 0) { Token(';'); } } while (c == ' '); /* '\t' is removed in tl_main.c */ if (c == '{' || c == '(') /* new 6.0.0 */ { if (is_predicate(c)) { read_upto_closing(c); tl_yylval = tl_nn(PREDICATE,ZN,ZN); if (!tl_yylval) { fatal("unexpected error 4", (char *) 0); } tl_yylval->sym = tl_lookup(yytext); return PREDICATE; } } if (c == '}') { tl_yyerror("unexpected '}'"); } if (islower(c)) { tl_getword(c, isalnum_); if (strcmp("true", yytext) == 0) { Token(TRUE); } if (strcmp("false", yytext) == 0) { Token(FALSE); } if (strcmp("always", yytext) == 0) { Token(ALWAYS); } if (strcmp("eventually", yytext) == 0) { Token(EVENTUALLY); } if (strcmp("until", yytext) == 0) { Token(U_OPER); } #ifdef NXT if (strcmp("next", yytext) == 0) { Token(NEXT); } #endif if (strcmp("c_expr", yytext) == 0) { Token(CEXPR); } if (strcmp("not", yytext) == 0) { Token(NOT); } tl_yylval = tl_nn(PREDICATE,ZN,ZN); if (!tl_yylval) { fatal("unexpected error 5", (char *) 0); } tl_yylval->sym = tl_lookup(yytext); return PREDICATE; } if (c == '<') { c = tl_Getchar(); if (c == '>') { Token(EVENTUALLY); } if (c != '-') { tl_UnGetchar(); tl_yyerror("expected '<>' or '<->'"); } c = tl_Getchar(); if (c == '>') { Token(EQUIV); } tl_UnGetchar(); tl_yyerror("expected '<->'"); } switch (c) { case '/' : c = tl_follow('\\', AND, '/'); break; case '\\': c = tl_follow('/', OR, '\\'); break; case '&' : c = tl_follow('&', AND, '&'); break; case '|' : c = tl_follow('|', OR, '|'); break; case '[' : c = tl_follow(']', ALWAYS, '['); break; case '-' : c = tl_follow('>', IMPLIES, '-'); break; case '!' : c = NOT; break; case 'U' : c = U_OPER; break; case 'V' : c = V_OPER; break; #ifdef NXT case 'X' : c = NEXT; break; #endif default : break; } Token(c); }
static int tl_lex(void) { int c; do { c = tl_Getchar(); yytext[0] = (char ) c; yytext[1] = '\0'; if (c <= 0) { Token(';'); } } while (c == ' '); /* '\t' is removed in tl_main.c */ if (islower(c)) { getword(c, isalnum_); if (strcmp("true", yytext) == 0) { Token(TRUE); } if (strcmp("false", yytext) == 0) { Token(FALSE); } tl_yylval = tl_nn(PREDICATE,ZN,ZN); tl_yylval->sym = tl_lookup(yytext); return PREDICATE; } if (c == '<') { c = tl_Getchar(); if (c == '>') { // #ifndef TIMED // Token(EVENTUALLY); // #else c = tl_Getchar(); if (c=='_') { float* tmp=(float *) malloc(sizeof(float)*2); tmp=tl_GetIntvl(tmp); Token_t(EVENTUALLY_I,tmp); } else { tl_UnGetchar(); Token(EVENTUALLY); } // #endif } if (c != '-') { tl_UnGetchar(); // #ifdef TIMED tl_yyerror("expected '<>' or '<->' or '<>_' for -DTIMED flag"); // #else // tl_yyerror("expected '<>' or '<->' without DTIMED flag"); // #endif } c = tl_Getchar(); if (c == '>') { Token(EQUIV); } tl_UnGetchar(); tl_yyerror("expected '<->'"); } if (c == '[') { c = tl_Getchar(); if (c == ']') { // #ifndef TIMED // Token(ALWAYS); // #else c = tl_Getchar(); if (c=='_') { float* tmp=(float *)malloc(sizeof(float)*2); tmp=tl_GetIntvl(tmp); Token_t(ALWAYS_I,tmp); } else { tl_UnGetchar(); Token(ALWAYS); } // #endif }else { tl_UnGetchar(); tl_yyerror("expected '[]' or '[]_'"); } } if (c == 'U') { #ifndef TIMED Token(U_OPER); #else c = tl_Getchar(); if (c=='_') { float* tmp=malloc(sizeof(float)*2); tmp=tl_GetIntvl(tmp); Token_t(U_I,tmp); } else { tl_UnGetchar(); Token(U_OPER); } #endif } switch (c) { case '/' : c = follow('\\', AND, '/'); break; case '\\': c = follow('/', OR, '\\'); break; case '&' : c = follow('&', AND, '&'); break; case '|' : c = follow('|', OR, '|'); break; // case '[' : c = follow(']', ALWAYS, '['); break; case '-' : c = follow('>', IMPLIES, '-'); break; case '!' : c = NOT; break; // case 'U' : c = U_OPER; break; case 'V' : c = V_OPER; break; #ifdef NXT case 'X' : c = NEXT; break; #endif default : break; } Token(c); }