[전산] 프로그래밍 DSP 관련 C소스
본 자료는 4페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
해당 자료는 4페이지 까지만 미리보기를 제공합니다.
4페이지 이후부터 다운로드 후 확인할 수 있습니다.

본문내용

ur) == L) {
while(priority(peer().what,cur) == L)
post[p_posi++] = pop();
if(priority(peer().what,cur) == E)
post[p_posi++] = pop();
added(in[i_posi]);
}
else return -1;
}
post[p_posi].what = END;
post[p_posi].value= 0;
return 0;
}
//priority
int priority(int left,int right)
{
int table[8][8] = {
{N,R,R,R,R,R,R,N},
{L,N,L,L,L,L,N,L},
{L,R,R,L,L,L,R,L},
{L,R,R,L,R,L,R,L},
{L,R,R,L,R,L,R,L},
{L,R,R,R,R,L,R,L},
{N,R,R,R,R,R,R,E},
{L,N,N,L,L,L,N,L},
};
for(int i=0; i<8; i++)
for(int j=0; j<8; j++)
if(left == i && right == j)
return(table[i][j]);
return 0;
}
//calculate postfix..
int calcul_postfix(TOKEN *post)
{
int a,b;
TOKEN temp;
initial_stack();
for(int i=0; post[i].what != END; i++)
{
switch(post[i].what) {
case NUMBER :
added(post[i]);
break;
case SIGN :
a = pop().value;
temp.what = NUMBER;
temp.value = (post[i].value == '-') ? -a : a;
added(temp);
break;
default :
switch(post[i].value) {
case '*' :
b = pop().value;
a = pop().value;
temp.what = NUMBER;
temp.value = a * b;
added(temp);
break;
case '/' :
b = pop().value;
a = pop().value;
temp.what = NUMBER;
temp.value = a / b;
added(temp);
break;
case '^' :
b = pop().value;
a = pop().value;
temp.what = NUMBER;
temp.value = power(a,b);
added(temp);
break;
case '+' :
b = pop().value;
a = pop().value;
temp.what = NUMBER;
temp.value = a + b;
added(temp);
break;
case '-' :
b = pop().value;
a = pop().value;
temp.what = NUMBER;
temp.value = a - b;
added(temp);
break;
case '(' :
case ')' :
break;
}
}
}
return pop().value;
}
//operator ^
int power(int a, int b)
{
int value = 1;
if(b==0) return value;
for(int i=0 ;i < b; i++)
value *= a;
return value;
}
//postfix printing..
void print_postfix(TOKEN* post)
{
for (int i=0 ; post[i].what != END;i++)
switch(post[i].what){
case R_PAR :
case L_PAR :
break;
case NUMBER :
cout< break;
case SIGN :
cout<<'('<<(char)post[i].value<<')'<<" ";
break;
default :
cout<<(char)post[i].value<<" ";
break;
}
cout< }
//sub-routin
inline int addsub(int x)
{
return((x == '+' || x == '-') ? 1 : 0);
}
inline int muldiv(int x)
{
return((x == '*' || x == '/') ? 1 : 0);
}
inline int power(int x)
{
return((x == '^') ? 1 : 0);
}
Output
Input the infix [(q)uit] : 1*2+3
Postfix expression : 1 2 * 3 +
Result : 5
Input the infix [(q)uit] : 1+2*3
Postfix expression : 1 2 3 * +
Result : 7
Input the infix [(q)uit] : 1*(2+3)
Postfix expression : 1 2 3 + *
Result : 5
Input the infix [(q)uit] : 1+2*(3+4)+1
Postfix expression : 1 2 3 4 + * + 1 +
Result : 16
Input the infix [(q)uit] : -1+(-3)*4+6
Postfix expression : 1 (-) 3 (-) 4 * + 6 +
Result : -7
Input the infix [(q)uit] : 5+3*2+4^2
Postfix expression : 5 3 2 * + 4 2 ^ +
Result : 27
Input the infix [(q)uit] : +--+- 2 +- + - -+ 3
Postfix expression : 2 (-) (+) (-) (-) (+) 3 (+) (-) (-) (+) (-) +
Result : -5
Input the infix [(q)uit] : (5*4)/(2*2)
Postfix expression : 5 4 * 2 2 * /
Result : 5
Input the infix [(q)uit] : 1s2+3^2
Postfix expression : Error
Input the infix [(q)uit] : 1#2+3
Postfix expression : Error

키워드

C,   DSP,   계산기,   소스,   C언어
  • 가격2,300
  • 페이지수12페이지
  • 등록일2002.09.22
  • 저작시기2002.09
  • 파일형식한글(hwp)
  • 자료번호#203775
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니