#define NSTRNG 5 struct strent strtbl[NSTRNG] = {
{0, VAR | STRING, 0},
{0, VAR | STRING, 0},
{0, VAR | STRING, 0},
{0, VAR | STRING, 0},
{"\0",ILLEG,0},
};
/* Help messages */ #if INTHELP staticchar *intmsg[] = { "?", "Unkown symbol", "Expression ends in illegal operator", "Precede ( by operator", ")( is illegal", "Unmatched )", "Missing )", "Illegal left hand side", "Missing symbol", "Must assign to a variable", "Divide by zero", "Missing symbol", "Missing operator", "Precede quantity by operator", "Quantity preceded by )", "Function syntax", "Too many function args", "No more temps", "Arg list"
}; #endif
/* the symbol table of key words */ struct funent keytbl[] = {
{"\0", ILLEG, 0}
}; #endif
void zgets(), init();
/* Number of decimals to display */ #define DEFDIS 70 staticint ndigits = DEFDIS;
/* Menu stack */ struct funent *menstk[5] = {&funtbl[0], NULL, NULL, NULL, NULL}; int menptr = 0;
/* Take file stack */
FILE *takstk[10] = {0}; int takptr = -1;
/* size of the expression scan list: */ #define NSCAN 20
/* previous token, saved for syntax checking: */ struct symbol *lastok = 0;
/* variables used by parser: */ staticchar str[128] = {0}; int uposs = 0; /* possible unary operator */ staticlongdouble qnc; char lc[40] = { '\n' }; /* ASCII string of token symbol */ staticchar line[LINLEN] = { '\n','\0' }; /* input command line */ staticchar maclin[LINLEN] = { '\n','\0' }; /* macro command */ char *interl = line; /* pointer into line */ externchar *interl; staticint maccnt = 0; /* number of times to execute macro command */ staticint comptr = 0; /* comma stack pointer */ staticlongdouble comstk[5]; /* comma argument stack */ staticint narptr = 0; /* pointer to number of args */ staticint narstk[5] = {0}; /* stack of number of function args */
/* main() */
/* Entire program starts here */
int main()
{
/* the scan table: */
/* array of pointers to symbols which have been parsed: */ struct symbol *ascsym[NSCAN];
/* current place in ascsym: */ registerstruct symbol **as;
/* array of attributes of operators parsed: */ int ascopr[NSCAN];
/* current place in ascopr: */ registerint *ao;
#if LARGEMEM /* array of precedence levels of operators: */ long asclev[NSCAN]; /* current place in asclev: */ long *al; long symval; /* value of symbol just parsed */ #else int asclev[NSCAN]; int *al; int symval; #endif
longdouble acc; /* the accumulator, for arithmetic */ int accflg; /* flags accumulator in use */ longdouble val; /* value to be combined into accumulator */ registerstruct symbol *psym; /* pointer to symbol just parsed */ struct varent *pvar; /* pointer to an indirect variable symbol */ struct funent *pfun; /* pointer to a function symbol */ struct strent *pstr; /* pointer to a string symbol */ int att; /* attributes of symbol just parsed */ int i; /* counter */ int offset; /* parenthesis level */ int lhsflg; /* kluge to detect illegal assignments */ struct symbol *parser(); /* parser returns pointer to symbol */ int errcod; /* for syntax error printout */
/* Perform general initialization */
init();
menstk[0] = &funtbl[0];
menptr = 0;
cmdhlp(); /* print out list of symbols */
/* Return here to get next command line to execute */
getcmd:
/* initialize registers and mutable symbols */
accflg = 0; /* Accumulator not in use */
acc = 0.0L; /* Clear the accumulator */
offset = 0; /* Parenthesis level zero */
comptr = 0; /* Start of comma stack */
narptr = -1; /* Start of function arg counter stack */
psym = (struct symbol *)&contbl[0]; for( i=0; i<NCONST; i++ )
{
psym->attrib = CONST; /* clearing the busy bit */
++psym;
}
psym = (struct symbol *)&temp[0]; for( i=0; i<NTEMP; i++ )
{
psym->attrib = VAR | TEMP; /* clearing the busy bit */
++psym;
}
/* List of scanned symbols is empty: */
as = &ascsym[0];
*as = 0;
--as; /* First item in scan list is Beginning of Line operator */
ao = &ascopr[0];
*ao = oprtbl[0].attrib & 0xf; /* BOL */ /* value of first item: */
al = &asclev[0];
*al = oprtbl[0].sym;
lhsflg = 0; /* illegal left hand side flag */
psym = &oprtbl[0]; /* pointer to current token */
/* get next token from input string */
gettok:
lastok = psym; /* last token = current token */
psym = parser(); /* get a new current token */ /*printf( "%s attrib %7o value %7o\n", psym->spel, psym->attrib & 0xffff,
psym->sym );*/
/* Examine attributes of the symbol returned by the parser */
att = psym->attrib; if( att == ILLEG )
{
errcod = 1; goto synerr;
}
/* Push functions onto scan list without analyzing further */ if( att & FUNC )
{ /* A command is a function whose argument is *apointertotherestoftheinputline. *Asecondargumentisalsopassed:theaddress *ofthelasttokenparsed.
*/ if( att & COMMAN )
{
pfun = (struct funent *)psym;
( *(pfun->fun))( interl, lastok );
abmac(); /* scrub the input line */ goto getcmd; /* and ask for more input */
}
++narptr; /* offset to number of args */
narstk[narptr] = 0;
i = lastok->attrib & 0xffff; /* attrib=short, i=int */ if( ((i & OPR) == 0)
|| (i == (OPR | RPAREN))
|| (i == (OPR | FUNC)) )
{
errcod = 15; goto synerr;
}
/* deal with operators */ if( att & OPR )
{
att &= 0xf; /* expression cannot end with an operator other than *(,),BOL,orafunction
*/ if( (att == RPAREN) || (att == EOL) || (att == EOE))
{
i = lastok->attrib & 0xffff; /* attrib=short, i=int */ if( (i & OPR)
&& (i != (OPR | RPAREN))
&& (i != (OPR | LPAREN))
&& (i != (OPR | FUNC))
&& (i != (OPR | BOL)) )
{
errcod = 2; goto synerr;
}
}
++lhsflg; /* any operator but ( and = is not a legal lhs */
/* operator processing, continued */
switch( att )
{ case EOE:
lhsflg = 0; break; case LPAREN: /* ( must be preceded by an operator of some sort. */ if( ((lastok->attrib & OPR) == 0) )
{
errcod = 3; goto synerr;
} /* also, a preceding ) is illegal */ if( (unsignedshort )lastok->attrib == (OPR|RPAREN))
{
errcod = 4; goto synerr;
} /* Begin looking for illegal left hand sides: */
lhsflg = 0;
offset += RPAREN; /* new parenthesis level */ goto gettok; case RPAREN:
offset -= RPAREN; /* parenthesis level */ if( offset < 0 )
{
errcod = 5; /* parenthesis error */ goto synerr;
} goto gettok; case EOL: if( offset != 0 )
{
errcod = 6; /* parenthesis error */ goto synerr;
} break; case EQU: if( --lhsflg ) /* was incremented before switch{} */
{
errcod = 7; goto synerr;
} case UMINUS: case COMP: goto pshopr; /* evaluate right to left */ default: ;
}
/* evaluate expression whenever precedence is not increasing */
symval = psym->sym + offset;
while( symval <= *al )
{ /* if just starting, must fill accumulator with last *thingontheline
*/ if( (accflg == 0) && (as >= ascsym) && (((*as)->attrib & FUNC) == 0 ))
{
pvar = (struct varent *)*as; /* if(pvar->attrib&STRING) strcpy((char*)&acc,(char*)pvar->value); else
*/
acc = *pvar->value;
--as;
accflg = 1;
}
/* handle beginning of line type cases, where the symbol *listascsym[]maybeempty.
*/ switch( *ao )
{ case BOL: /* printf( "%.16e\n", (double )acc ); */ #if NE == 6
e64toasc( &acc, str, 100 ); #else
e113toasc( &acc, str, 100 ); #endif
printf( "%s\n", str ); goto getcmd; /* all finished */ case UMINUS:
acc = -acc; goto nochg; /* caseCOMP: acc=~acc; gotonochg;
*/ default: ;
} /* Now it is illegal for symbol list to be empty, *becausewearegoingtoneedasymbolbelow.
*/ if( as < &ascsym[0] )
{
errcod = 8; goto synerr;
} /* get attributes and value of current symbol */
att = (*as)->attrib;
pvar = (struct varent *)*as; if( att & FUNC )
val = 0.0L; else
{ /* if(att&STRING) strcpy((char*)&val,(char*)pvar->value); else
*/
val = *pvar->value;
}
/* Expression evaluation, continued. */
switch( *ao )
{ case FUNC:
pfun = (struct funent *)*as; /* Call the function with appropriate number of args */
i = narstk[ narptr ];
--narptr; switch(i)
{ case0:
acc = ( *(pfun->fun) )(acc); break; case1:
acc = ( *(pfun->fun) )(acc, comstk[comptr-1]); break; case2:
acc = ( *(pfun->fun) )(acc, comstk[comptr-2],
comstk[comptr-1]); break; case3:
acc = ( *(pfun->fun) )(acc, comstk[comptr-3],
comstk[comptr-2], comstk[comptr-1]); break; default:
errcod = 16; goto synerr;
}
comptr -= i;
accflg = 1; /* in case at end of line */ break; case EQU: if( ( att & TEMP) || ((att & VAR) == 0) || (att & STRING) )
{
errcod = 9; goto synerr; /* can only assign to a variable */
}
pvar = (struct varent *)*as;
*pvar->value = acc; break; case PLUS:
acc = acc + val; break; case MINUS:
acc = val - acc; break; case MULT:
acc = acc * val; break; case DIV: if( acc == 0.0L )
{ /* divzer:
*/
errcod = 10; goto synerr;
}
acc = val / acc; break; /* caseMOD: if(acc==0) gotodivzer; acc=val%acc;break; caseLOR: acc|=val;break; caseLXOR: acc^=val;break; caseLAND: acc&=val;break;
*/ case EOE: if( narptr < 0 )
{
errcod = 18; goto synerr;
}
narstk[narptr] += 1;
comstk[comptr++] = acc; /* printf( "\ncomptr: %d narptr: %d %d\n", comptr, narptr, acc );*/
acc = val; break;
}
/* expression evaluation, continued */
/* Pop evaluated tokens from scan list: */ /* make temporary variable not busy */ if( att & TEMP )
(*as)->attrib &= ~BUSY; if( as < &ascsym[0] ) /* can this happen? */
{
errcod = 11; goto synerr;
}
--as;
nochg:
--ao;
--al; if( ao < &ascopr[0] ) /* can this happen? */
{
errcod = 12; goto synerr;
} /* If precedence level will now increase, then */ /* save accumulator in a temporary location */ if( symval > *al )
{ /* find a free temp location */
pvar = &temp[0]; for( i=0; i<NTEMP; i++ )
{ if( (pvar->attrib & BUSY) == 0) goto temfnd;
++pvar;
}
errcod = 17;
printf( "no more temps\n" );
pvar = &temp[0]; goto synerr;
temfnd:
pvar->attrib |= BUSY;
*pvar->value = acc; /*printf( "temp %d\n", acc );*/
accflg = 0;
++as; /* push the temp onto the scan list */
*as = (struct symbol *)pvar;
}
} /* End of evaluation loop */
/* Push operator onto scan list when precedence increases */
ans = -2.0; if( x == y )
{
printf( "x == y " );
ans = 0.0;
} if( x < y )
{
printf( "x < y" );
ans = -1.0;
} if( x > y )
{
printf( "x > y" );
ans = 1.0;
} return( ans );
}
longdouble zstdtrl(k,t) longdouble k, t;
{ int ki; longdouble y;
ki = k;
y = stdtrl(ki,t); return(y);
}
longdouble zstdtril(k,t) longdouble k, t;
{ int ki; longdouble y;
ki = k;
y = stdtril(ki,t); return(y);
}
#ifdef NANS longdouble zisnan(x) longdouble x;
{ longdouble y; int k;
k = isnanl(x);
y = k; return(y);
} longdouble zisfinite(x) longdouble x;
{ longdouble y; int k;
k = isfinitel(x);
y = k; return(y);
} longdouble zsignbit(x) longdouble x;
{ longdouble y; int k;
k = signbitl(x);
y = k; return(y);
} #endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.