Category : C Source Code
Archive   : CINTERP.ZIP
Filename : CALC.SCI
int Stack[10], Stackptr, Stacktop;
calc()
{
char line[80];
char c;
Stacktop = 10;
while(1)
{
puts("-> ");
Lineptr = line;
c = gets( line );
if(c)
{
if( *Lineptr=='x' )
return;
addition();
printf( "%d\n", pop() );
}
}
}
number()
{
if( isdigit( *Lineptr ) )
{
push( atoi( Lineptr ) );
while( isdigit( *Lineptr ) )
++Lineptr;
}
}
addition()
{
int num;
while(1)
{
multiplication();
if( *Lineptr=='+' )
{
++Lineptr;
multiplication();
push( pop() + pop() );
}
else if ( *Lineptr=='-' )
{
++Lineptr;
multiplication();
num = pop();
push( pop() - num );
}
else
return;
}
}
multiplication()
{
int num;
while(1)
{
number();
if( *Lineptr=='*' )
{
++Lineptr;
number();
push( pop() * pop() );
}
else if ( *Lineptr=='/' )
{
++Lineptr;
number();
num = pop();
push( pop() / num );
}
else
return;
}
}
push( n )
{
if( Stackptr
puts( "stack overflow\n" );
}
pop()
{
if( Stackptr>0 )
return Stack[ --Stackptr ];
puts( "stack underflow\n" );
}
isdigit(c){ return '0'<=c && c<='9';}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/