示例#1
0
static Node *tl_level(int nr)
{	
	int i; Node *ptr = ZN;
	Interval LocInter;

	if (nr < 0)
		return tl_factor();

	ptr = tl_level(nr-1);
again:
	for (i = 0; i < 4; i++)
		if (tl_yychar == prec[nr][i])
		{	
			if (nr==0 && (i==0 || i==1))
				LocInter = TimeCon;
			tl_yychar = tl_yylex();
			ptr = tl_nn(prec[nr][i],ptr,tl_level(nr-1));
			if (nr==0 && (i==0 || i==1))
				ptr->time = LocInter;
			if(tl_simp_log) 
				ptr = bin_simpler(ptr);
			else 
				ptr = bin_minimal(ptr);
			goto again;
		}
	if (!ptr) tl_yyerror("syntax error");
#if 0
	printf("level %d:	", nr);
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}
static Node *
tl_level(int nr)
{	int i; Node *ptr = ZN;

	if (nr < 0)
		return tl_factor();

	ptr = tl_level(nr-1);
again:
	for (i = 0; i < 4; i++)
		if (tl_yychar == prec[nr][i])
		{	tl_yychar = tl_yylex();
			ptr = tl_nn(prec[nr][i],
				ptr, tl_level(nr-1));
			ptr = bin_simpler(ptr);
			goto again;
		}
	if (!ptr) tl_yyerror("syntax error");
#if 0
	printf("level %d:	", nr);
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}
示例#3
0
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;
}
示例#4
0
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;
}
示例#5
0
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);
}
示例#6
0
void
tl_balanced(void)
{	int i;
	int k = 0;

	for (i = 0; i < hasuform; i++)
	{	if (uform[i] == '(')
		{	k++;
		} else if (uform[i] == ')')
		{	k--;
	}	}
	if (k != 0)
	{	tl_errs++;
		tl_yyerror("parentheses not balanced");
	}
}
示例#7
0
static Node *tl_level(int nr, int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell, int *tl_yychar)
{	
	int i; Node *ptr = ZN;
	Interval LocInter;
	int tl_simp_log_p = 0;
	static int	prec[2][4] = {
	{ U_OPER,  V_OPER, 0, 0},  /* left associative */
	{ OR, AND, IMPLIES, EQUIV, },	/* left associative */
};


	if (nr < 0)
		return tl_factor(cnt, hasuform, uform, miscell, tl_yychar);

	ptr = tl_level(nr-1, cnt, hasuform, uform, miscell, tl_yychar);
again:
	for (i = 0; i < 4; i++)
		if ((*tl_yychar) == prec[nr][i])
		{	
			if (nr==0 && (i==0 || i==1))
				LocInter = miscell->TimeCon;
			(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
			ptr = tl_nn(prec[nr][i],ptr,tl_level(nr-1, cnt, hasuform, uform, miscell, tl_yychar), miscell);
			if (nr==0 && (i==0 || i==1))
				ptr->time = LocInter;
			if(tl_simp_log_p) 
				ptr = bin_simpler(ptr,miscell,cnt,uform, tl_yychar);
			else 
				ptr = bin_minimal(ptr,miscell,cnt,uform, tl_yychar);
			goto again;
		}
	if (!ptr) tl_yyerror("syntax error", cnt, uform, tl_yychar, miscell);
#if 0
	printf("level %d:	", nr);
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}
示例#8
0
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);

}
示例#9
0
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);
}
示例#10
0
static Node *
tl_factor(void)
{	Node *ptr = ZN;

	switch (tl_yychar) {
	case '(':
		ptr = tl_formula();
		if (tl_yychar != ')')
			tl_yyerror("expected ')'");
		tl_yychar = tl_yylex();
		break;
	case NOT:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		ptr->lft = tl_factor();
		if (!ptr->lft)
		{	fatal("malformed expression", (char *) 0);
		}
		ptr = push_negation(ptr);
		break;
	case ALWAYS:
		tl_yychar = tl_yylex();
		ptr = tl_factor();
#ifndef NO_OPT
		if (ptr->ntyp == FALSE
		||  ptr->ntyp == TRUE)
			break;	/* [] false == false */

		if (ptr->ntyp == V_OPER)
		{	if (ptr->lft->ntyp == FALSE)
				break;	/* [][]p = []p */

			ptr = ptr->rgt;	/* [] (p V q) = [] q */
		}
#endif
		ptr = tl_nn(V_OPER, False, ptr);
		break;
#ifdef NXT
	case NEXT:
		tl_yychar = tl_yylex();
		ptr = tl_factor();
		if (ptr->ntyp == TRUE)
			break;	/* X true = true */
		ptr = tl_nn(NEXT, ptr, ZN);
		break;
#endif
	case CEXPR:
		tl_yychar = tl_yylex();
		ptr = tl_factor();
		if (ptr->ntyp != PREDICATE)
		{	tl_yyerror("expected {...} after c_expr");
		}
		ptr = tl_nn(CEXPR, ptr, ZN);
		break;
	case EVENTUALLY:
		tl_yychar = tl_yylex();

		ptr = tl_factor();
#ifndef NO_OPT
		if (ptr->ntyp == TRUE
		||  ptr->ntyp == FALSE)
			break;	/* <> true == true */

		if (ptr->ntyp == U_OPER
		&&  ptr->lft->ntyp == TRUE)
			break;	/* <><>p = <>p */

		if (ptr->ntyp == U_OPER)
		{	/* <> (p U q) = <> q */
			ptr = ptr->rgt;
			/* fall thru */
		}
#endif
		ptr = tl_nn(U_OPER, True, ptr);

		break;
	case PREDICATE:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		break;
	case TRUE:
	case FALSE:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		break;
	}
	if (!ptr) tl_yyerror("expected predicate");
#if 0
	printf("factor:	");
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}
示例#11
0
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);
}
示例#12
0
static Node *tl_factor(void)
{	
	Node *ptr = ZN;

	switch (tl_yychar) 
	{
	case '(':
		ptr = tl_formula();
		if (tl_yychar != ')')
			tl_yyerror("expected ')'");
		tl_yychar = tl_yylex();
		goto simpl;

	case NOT:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		ptr->lft = tl_factor();
		ptr = push_negation(ptr);
		goto simpl;

	case ALWAYS:
		ptr = tl_nn(V_OPER, False, ptr);
		ptr->time = TimeCon;
		tl_yychar = tl_yylex();
		ptr->rgt = tl_factor();
		if(tl_simp_log) 
		{	/* must be modified! */
			if (ptr->ntyp == V_OPER)
			{	
				if (ptr->lft->ntyp == FALSE)
					break;	/* [][]p = []p */
				ptr = ptr->rgt;	/* [] (p V q) = [] q */
			}
		}
		goto simpl;

	case NEXT:
		ptr = tl_nn(NEXT, ZN, ZN);
		ptr->time = TimeCon;
		tl_yychar = tl_yylex();
		ptr->lft = tl_factor();
		goto simpl;

	case WEAKNEXT:
		ptr = tl_nn(WEAKNEXT, ZN, ZN);
		ptr->time = TimeCon;
		tl_yychar = tl_yylex();
		ptr->lft = tl_factor();
		goto simpl;

	case EVENTUALLY:
		ptr = tl_nn(U_OPER, True, ZN);
		ptr->time = TimeCon;
		tl_yychar = tl_yylex();
		ptr->rgt = tl_factor();
		if(tl_simp_log) 
		{	/* this must be modified */
			if (ptr->ntyp == U_OPER	&&  ptr->lft->ntyp == TRUE)		    
				break;	/* <><>p = <>p */
			if (ptr->ntyp == U_OPER)
			{	/* <> (p U q) = <> q */
				ptr = ptr->rgt;
				/* fall thru */
			}
		}
/*		goto simpl;

	case IMPLIES:
		ptr = tl_nn(OR, Not(ptr->lft), ptr->rgt);
		goto simpl;

	case EQUIV:
		a = tl_nn(AND,dupnode(ptr->lft),dupnode(ptr->rgt));
		b = tl_nn(AND,Not(ptr->lft),Not(ptr->rgt));
		ptr = tl_nn(OR, a, b); */

	simpl:
		if (tl_simp_log) 
		  ptr = bin_simpler(ptr);
		break;

	case PREDICATE:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		break;

	case TRUE:
	case FALSE:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		break;
	}
	if (!ptr) tl_yyerror("expected predicate");
#if 0
	printf("factor:	");
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}
示例#13
0
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);
}
示例#14
0
文件: lex.c 项目: yzh89/MITL2Timed
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);
}
示例#15
0
文件: parse.c 项目: MengGuo/P_MAS_TG
static Node *
tl_factor(void)
{	Node *ptr = ZN;

	switch (tl_yychar) {
	case '(':
		ptr = tl_formula();
		if (tl_yychar != ')')
			tl_yyerror("expected ')'");
		tl_yychar = tl_yylex();
		goto simpl;
	case NOT:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		ptr->lft = tl_factor();
		ptr = push_negation(ptr);
		goto simpl;
	case ALWAYS:
		tl_yychar = tl_yylex();

		ptr = tl_factor();

		if(tl_simp_log) {
		  if (ptr->ntyp == FALSE
		      ||  ptr->ntyp == TRUE)
		    break;	/* [] false == false */
		  
		  if (ptr->ntyp == V_OPER)
		    {	if (ptr->lft->ntyp == FALSE)
		      break;	/* [][]p = []p */
		    
		    ptr = ptr->rgt;	/* [] (p V q) = [] q */
		    }
		}

		ptr = tl_nn(V_OPER, False, ptr);
		goto simpl;
#ifdef NXT
	case NEXT:
		tl_yychar = tl_yylex();

		ptr = tl_factor();

		if ((ptr->ntyp == TRUE || ptr->ntyp == FALSE)&& tl_simp_log)
			break;	/* X true = true , X false = false */

		ptr = tl_nn(NEXT, ptr, ZN);
		goto simpl;
#endif
	case EVENTUALLY:
		tl_yychar = tl_yylex();

		ptr = tl_factor();

		if(tl_simp_log) {
		  if (ptr->ntyp == TRUE
		      ||  ptr->ntyp == FALSE)
		    break;	/* <> true == true */

		  if (ptr->ntyp == U_OPER
		      &&  ptr->lft->ntyp == TRUE)
		    break;	/* <><>p = <>p */

		  if (ptr->ntyp == U_OPER)
		    {	/* <> (p U q) = <> q */
		      ptr = ptr->rgt;
		      /* fall thru */
		    }
		}

		ptr = tl_nn(U_OPER, True, ptr);
	simpl:
		if (tl_simp_log) 
		  ptr = bin_simpler(ptr);
		break;
	case PREDICATE:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		break;
	case TRUE:
	case FALSE:
		ptr = tl_yylval;
		tl_yychar = tl_yylex();
		break;
	}
	if (!ptr) tl_yyerror("expected predicate");
#if 0
	printf("factor:	");
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}
示例#16
0
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);
}
示例#17
0
static Node *tl_factor(int *cnt, size_t hasuform, char *uform, Miscellaneous *miscell, int *tl_yychar)
{	
	Node *ptr = ZN;
	int tl_simp_log_p = 0;


	switch ((*tl_yychar)) 
	{
	case '(':
		ptr = tl_formula(cnt, hasuform, uform, miscell, tl_yychar);
		if ((*tl_yychar) != ')')
			tl_yyerror("expected ')'", cnt, uform, tl_yychar, miscell);
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		goto simpl;

	case NOT:
		ptr = miscell->tl_yylval;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		ptr->lft = tl_factor(cnt, hasuform, uform, miscell, tl_yychar);
		ptr = push_negation(ptr, miscell, cnt, uform, tl_yychar);
		goto simpl;

	case ALWAYS:
		ptr = tl_nn(ALWAYS, False, ZN, miscell);
		ptr->time = miscell->TimeCon;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		ptr->rgt = tl_factor(cnt, hasuform, uform, miscell, tl_yychar);
		goto simpl;

	case NEXT:
		ptr = tl_nn(NEXT, ZN, ZN, miscell);
		ptr->time = miscell->TimeCon;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		ptr->lft = tl_factor(cnt, hasuform, uform, miscell, tl_yychar);
		goto simpl;

	case WEAKNEXT:
		ptr = tl_nn(WEAKNEXT, ZN, ZN, miscell);
		ptr->time = miscell->TimeCon;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		ptr->lft = tl_factor(cnt, hasuform, uform, miscell, tl_yychar);
		goto simpl;

	case EVENTUALLY:
		ptr = tl_nn(EVENTUALLY, True, ZN, miscell);
		ptr->time = miscell->TimeCon;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		ptr->rgt = tl_factor(cnt, hasuform, uform, miscell, tl_yychar);

		goto simpl;

/*	case IMPLIES:
		ptr = tl_nn(OR, Not(ptr->lft), ptr->rgt);
		goto simpl;

/*	case EQUIV:
		a = tl_nn(AND,dupnode(ptr->lft),dupnode(ptr->rgt));
		b = tl_nn(AND,Not(ptr->lft),Not(ptr->rgt));
		ptr = tl_nn(OR, a, b); */

	simpl:
		if (tl_simp_log_p) 
		  ptr = bin_simpler(ptr,miscell,cnt,uform, tl_yychar);
		break;

	case PREDICATE:
		ptr = miscell->tl_yylval;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		break;

	case TRUE:
	case FALSE:
		ptr = miscell->tl_yylval;
		(*tl_yychar) = tl_yylex(cnt, hasuform, uform, miscell, tl_yychar);
		break;
	}
	if (!ptr) tl_yyerror("expected predicate", cnt, uform, tl_yychar, miscell);
#if 0
	printf("factor:	");
	tl_explain(ptr->ntyp);
	printf("\n");
#endif
	return ptr;
}