/* func3-2.c algo3-6.c和algo3-7.c要调用的函数 */
char Precede(SElemType t1,SElemType t2)
{ /* 根据教科书表3.1,判断t1,t2两符号的优先关系('#'用'\n'代替) */
char f;
switch(t2)
{
case '+':
case '-':if(t1=='('||t1=='\n')
f='<'; /* t1<t2 */
else
f='>'; /* t1>t2 */
break;
case '*':
case '/':if(t1=='*'||t1=='/'||t1==')')
f='>'; /* t1>t2 */
else
f='<'; /* t1<t2 */
break;
case '(':if(t1==')')
{
printf("括号不匹配\n");
exit(ERROR);
}
else
f='<'; /* t1<t2 */
break;
case ')':switch(t1)
{
case '(':f='='; /* t1=t2 */
break;
case'\n':printf("缺乏左括号\n");
exit(ERROR);
default :f='>'; /* t1>t2 */
}
break;
case'\n':switch(t1)
{
case'\n':f='='; /* t1=t2 */
3.2.5 表达式求解
最新推荐文章于 2022-05-23 02:23:41 发布