int main(int argc, char const *argv[]) { time_t t; srand((unsigned) time(&t)); int shift = rand() % 1000000; printf("In parseval's theorem, LHS - RHS = %lf\n", parseval(argv[1],argv[2])); rshift(argv[1],argv[3], shift); return 0; }
// compilation d'une variable // [name] -> 0 int Compiler::parsevar() { int k; int hasvalue = 0; if (!parser->next(0)) { PRINTF(m)(LOG_COMPILER,"Compiler : ';;' expected (found EOF)\n"); return MTLERR_SN; } if (!strcmp(parser->token,"=")) { if (k=parseval()) return k; hasvalue = 1; } else { parser->giveback(); if (k=STACKPUSH(m,NIL)) return k; if (k=createnodetype(TYPENAME_WEAK)) return k; } // [val type name] if (k=parser->parsekeyword(";;")) return k; int val=INTTOVAL(nblabels(globals)); if (k=addlabel(globals,STRSTART(VALTOPNT(STACKGET(m,2))),val,STACKGET(m,1))) return k; // enregistrement d'une nouvelle globale // on crée le bloc fonction newref=MALLOCCLEAR(m,REF_LENGTH); if (!newref) return MTLERR_OM; TABSET(m,newref,REF_TYPE,STACKPULL(m)); TABSET(m,newref,REF_VAL,STACKPULL(m)); TABSET(m,newref,REF_NAME,STACKPULL(m)); TABSET(m,newref,REF_CODE,INTTOVAL(CODE_VAR)); // la variable vient d'être créé, elle n'est donc ni utilisée ni modifiée encore TABSET(m,newref,REF_USED,INTTOVAL(0)); TABSET(m,newref,REF_SET,INTTOVAL(hasvalue)); TABSET(m,newref,REF_USED_IN_IFDEF,INTTOVAL(0)); TABSET(m,newref,REF_PACKAGE,val); if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newref] addreftopackage(newref,newpackage); STACKDROP(m); outputbuf->reinit(); outputbuf->printf("Compiler : var %s : ",STRSTART(VALTOPNT(TABGET(newref,REF_NAME)))); echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE))); PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart()); return 0; }
// compilation d'une constante (const var = val;;) // [name] -> 0 int Compiler::parseconst() { int k; if (k=parser->parsekeyword("=")) return k; if (k=parseval()) return k; if (k=parser->parsekeyword(";;")) return k; int val=INTTOVAL(nblabels(globals)); if (k=addlabel(globals,STRSTART(VALTOPNT(STACKGET(m,2))),val,STACKGET(m,1))) return k; // enregistrement d'une nouvelle globale // on crée le bloc fonction newref=MALLOCCLEAR(m,REF_LENGTH); if (!newref) return MTLERR_OM; TABSET(m,newref,REF_TYPE,STACKPULL(m)); TABSET(m,newref,REF_VAL,STACKPULL(m)); TABSET(m,newref,REF_NAME,STACKPULL(m)); TABSET(m,newref,REF_CODE,INTTOVAL(CODE_CONST)); // la constante vient d'être créée, elle n'est donc pas utilisée, mais elle a une valeur TABSET(m,newref,REF_USED,INTTOVAL(0)); TABSET(m,newref,REF_SET,INTTOVAL(1)); TABSET(m,newref,REF_USED_IN_IFDEF,INTTOVAL(0)); TABSET(m,newref,REF_PACKAGE,val); if (k=STACKPUSH(m,PNTTOVAL(newref))) return MTLERR_OM; // [newref] addreftopackage(newref,newpackage); STACKDROP(m); outputbuf->reinit(); outputbuf->printf("Compiler : const %s : ",STRSTART(VALTOPNT(TABGET(newref,REF_NAME)))); echograph(outputbuf,VALTOPNT(TABGET(newref,REF_TYPE))); PRINTF(m)(LOG_COMPILER,"%s\n",outputbuf->getstart()); return 0; }
/* MDATTDEF: Process an individual attribute definition. The attribute name is parsed by the caller. Duplicate attributes are parsed, but removed from list. Returns 0 if successful, otherwise returns 1. */ int mdattdef(int adlim, /* Remaining capacity of al (in tokens).*/ int datt) /* Non-zero if a data attribute. */ { int deftype; /* Default value type: 0=not keyword. */ int errsw = 0; /* 1=semantic error; ignore att. */ int novalsw = 0; /* 1=semantic error; treat as IMPLIED. */ int attadn = (int)ADN(al); /* Save ad number of this attribute. */ struct parse *grppcb = NULL; /* PCB for name/token grp parse. */ int errcode; /* Error type returned by PARSEVAL, ANMTGRP. */ UNCH *advalsv; /* Save area for permanent value ptr. */ /* PARAMETER 1: Attribute name (parsed by caller). */ TRACEMD("1: attribute name"); if (anmget((int)ADN(al)-1, al[attadn].adname)) { errsw = 1; mderr(99, ADNAME(al,attadn), (UNCH *)0); } ADNUM(al,attadn) = ADFLAGS(al,attadn) = ADLEN(al,attadn) = 0; ADVAL(al,attadn) = 0; ADDATA(al,attadn).x = 0; ADTYPE(al,attadn) = ANMTGRP; /* PARAMETER 2: Declared value. */ parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("2: declared value"); switch (pcbmd.action) { case NAS: /* Keyword for value type. */ switch (ADTYPE(al,attadn) = (UNCH)mapsrch(dvtab, lbuf+1)) { case 0: mderr(100, ADNAME(al,attadn), lbuf+1); return 1; case ANOTEGRP: if (datt) { errsw = 1; mderr(156, (UNCH *)0, (UNCH *)0); } else if (!noteadn) noteadn = ADN(al); else { errsw = 1; mderr(101, ADNAME(al,attadn), (UNCH *)0); } grppcb = &pcbgrnm; /* NOTATION requires name grp. */ parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN);/* Get GRPO*/ break; case AID: if (datt) { errsw = 1; mderr(144, (UNCH *)0, (UNCH *)0); } else if (!idadn) idadn = attadn; else { errsw = 1; mderr(102, ADNAME(al,attadn), (UNCH *)0); } break; case AIDREF: case AIDREFS: if (datt) { errsw = 1; mderr(155, (UNCH *)0, (UNCH *)0); } break; case AENTITY: case AENTITYS: if (datt) { errsw = 1; mderr(154, (UNCH *)0, (UNCH *)0); } break; } break; case GRPS: grppcb = &pcbgrnt; /* Normal grp is name token grp. */ break; case EMD: mderr(103, ADNAME(al,attadn), (UNCH *)0); return 1; default: mderr(104, ADNAME(al,attadn), (UNCH *)0); return 1; } /* PARAMETER 2A: Name token group. */ if (grppcb != NULL) { TRACEMD("2A: name group"); switch (pcbmd.action) { case GRPS: /* Name token list. */ SET(ADFLAGS(al,attadn), AGROUP); /* Call routine to parse group, create ad entries in adl. */ errcode = anmtgrp(grppcb, al+attadn, (GRPCNT<adlim ? GRPCNT+1 : adlim+1), &al[attadn].adnum, ADN(al)); if (errcode<=0) { if (adlim < GRPCNT) mderr(111, (UNCH *)0, (UNCH *)0); else mderr(105, ADNAME(al,attadn), (UNCH *)0); return 1; } ADN(al) += ADNUM(al,attadn); /* Add grp size to total ad cnt.*/ break; default: mderr(106, ADNAME(al,attadn), (UNCH *)0); return 1; } } /* PARAMETER 3: Default value keyword. */ parsemd(lbuf, AVALCASE, (ADTYPE(al,attadn)==ACHARS) ? &pcblitr : &pcblitt, LITLEN); TRACEMD("3: default keyword"); switch (pcbmd.action) { case RNS: /* Keyword. */ deftype = mapsrch(deftab, lbuf+1); switch (deftype) { case DFIXED: /* FIXED */ SET(ADFLAGS(al,attadn), AFIXED); parsemd(lbuf, AVALCASE, (ADTYPE(al,attadn)==ACHARS) ? &pcblitr : &pcblitt, LITLEN); /* Real default. */ goto parm3x; /* Go process specified value. */ case DCURR: /* CURRENT: If ID, treat as IMPLIED. */ if (ADTYPE(al,attadn)==AID) { mderr(80, ADNAME(al,attadn), (UNCH *)0); break; } if (datt) { mderr(157, (UNCH *)0, (UNCH *)0); break; } SET(ADFLAGS(al,attadn), ACURRENT); break; case DREQ: /* REQUIRED */ SET(ADFLAGS(al,attadn), AREQ); ++reqadn; break; case DCONR: /* CONREF */ if (ADTYPE(al,attadn)==AID) { mderr(107, ADNAME(al,attadn), (UNCH *)0); break; } if (datt) { mderr(158, (UNCH *)0, (UNCH *)0); break; } SET(ADFLAGS(al,attadn), ACONREF); conradn = 1; case DNULL: /* IMPLIED */ break; default: /* Unknown keyword is an error. */ mderr(108, ADNAME(al,attadn), lbuf+1); errsw = 1; } if (errsw) { /* Ignore erroneous att. */ adlfree(al, attadn); --AN(al); ADN(al) = (UNCH)attadn-1; } return(0); default: break; } /* PARAMETER 3x: Default value (non-keyword). */ parm3x: TRACEMD("3x: default (non-keyword)"); if (ADTYPE(al,attadn)==AID) { /* If ID, treat as IMPLIED. */ mderr(81, ADNAME(al,attadn), (UNCH *)0); novalsw = 1; /* Keep parsing to keep things straight. */ } switch (pcbmd.action) { case LIT: /* Literal. */ case LITE: /* Literal. */ /* Null string (except CDATA) is error: msg and treat as IMPLIED. */ if (*lbuf == '\0' && ADTYPE(al,attadn)!=ACHARS) { mderr(82, ADNAME(al,attadn), (UNCH *)0); novalsw = 1; } break; case NAS: /* Name character string. */ case NMT: /* Name character string. */ case NUM: /* Number or number token string. */ /* The name won't have a length byte because AVALCASE was specified. */ break; case CDR: parsetkn(lbuf, NMC, LITLEN); break; case EMD: mderr(109, ADNAME(al,attadn), (UNCH *)0); return 1; default: mderr(110, ADNAME(al,attadn), (UNCH *)0); return 1; } if (errsw) { /* Ignore erroneous att. */ adlfree(al, attadn); --AN(al); ADN(al) = (UNCH)attadn-1; return(0); } if (novalsw) return(0); /* PARAMETER 3y: Validate and store default value. */ if (ADTYPE(al,attadn)==ACHARS) { UNS len = vallen(ACHARS, 0, lbuf); if (len > LITLEN) { /* Treat as implied. */ sgmlerr(224, &pcbmd, ADNAME(al,attadn), (UNCH *)0); return 0; } /* No more checking for CDATA value. */ ADNUM(al,attadn) = 0; /* CDATA is 0 tokens. */ ADVAL(al,attadn) = savestr(lbuf);/* Store default; save ptr. */ ADLEN(al,attadn) = len; ds.attdef += len; return 0; } /* Parse value and save token count (GROUP implies 1 token). */ advalsv = (UNCH *)rmalloc(ustrlen(lbuf)+2); /* Storage for tokenized value. */ errcode = parseval(lbuf, (UNS)ADTYPE(al,attadn), advalsv); if (BITOFF(ADFLAGS(al,attadn), AGROUP)) ADNUM(al,attadn) = (UNCH)tokencnt; /* If value was invalid, or was a group member that was not in the group, issue an appropriate message and set the error switch. */ if (errcode) {sgmlerr((UNS)errcode, &pcbmd, ADNAME(al,attadn), lbuf); errsw = 1;} else if ( BITON(ADFLAGS(al,attadn), AGROUP) && !amemget(&al[attadn], (int)ADNUM(al,attadn), advalsv) ) { sgmlerr(79, &pcbmd, ADNAME(al,attadn), advalsv+1); errsw = 1; } ADLEN(al,attadn) = vallen(ADTYPE(al,attadn), ADNUM(al,attadn), advalsv); if (ADLEN(al,attadn) > LITLEN) { sgmlerr(224, &pcbmd, ADNAME(al,attadn), (UNCH *)0); ADLEN(al,attadn) = 0; errsw = 1; } /* For valid tokenized value, save it and update statistics. */ if (!errsw) { ADVAL(al,attadn) = advalsv; ds.attdef += ADLEN(al,attadn); return 0; } /* If value was bad, free the value's storage and treat as IMPLIED or REQUIRED. */ frem((UNIV)advalsv); /* Release storage for value. */ ADVAL(al,attadn) = NULL; /* And make value NULL. */ return 0; }
bool aart_post::toon::parse(const char * aline, FILE *) { char c= * aline ; int itmp ; generalstring::skip(aline) ; switch (tolower(c)) { case 'c': // curvatureLine c= * aline ; switch (tolower(c)) { case 'h': // hardness if (! parseval(cline_h, aline)) return false ; break ; case 't': // threshold if (! parseval(cline_t, aline)) return false ; break ; case 'w': // width if (! parseval(cline_w, aline)) return false ; break ; default: generallog::message("unexpected attribute for curvatureLine (expected width|threshold|hardness)", GL::eWarning) ; return false ; } break ; case 't': // trickLine c= * aline ; switch (tolower(c)) { case 'h': // hardness if (! parseval(tline_h, aline)) return false ; break ; case 't': // threshold if (! parseval(tline_t, aline)) return false ; break ; case 'w': // width if (! parseval(tline_w, aline)) return false ; break ; default: generallog::message("unexpected attribute for trickLine (expected width|threshold|hardness)", GL::eWarning) ; return false ; } break ; case 'l': // lineColor itmp= atoi(aline) ; if ((itmp < 1) || (itmp > 16)) { generallog::message("lineColor out of range (1-16)", GL::eWarning) ; return false ; } generalstring::skip(aline) ; itmp -- ; if ('[' != * aline) return false ; aline ++ ; if (parsecolor(line[itmp], aline)) { luse |= (1 << itmp) ; } else return false ; break ; default: if (strncmp(aline, "# ---", 5)) ignore(aline) ; } return true ; }