static Object range(CCEparsestate* state, Object sfirst, Object sstride, Object slast) { CCEslice* slice = (CCEslice*)ccecreate(CES_SLICE); unsigned long first,stride,last; /* Note: that incoming arguments are strings; we must convert to size_t; but we do know they are legal integers or NULL */ sscanf((char*)sfirst,"%lu",&first); /* always defined */ if(slast != NULL) sscanf((char*)slast,"%lu",&last); else last = first; if(sstride != NULL) sscanf((char*)sstride,"%lu",&stride); else stride = 1; /* default */ if(stride == 0) cceerror(state,"Illegal index for range stride"); if(last < first) cceerror(state,"Illegal index for range last index"); slice->first = first; slice->stride = stride; slice->stop = last + 1; slice->length = slice->stop - slice->first; slice->count = slice->length / slice->stride; #ifdef DEBUG fprintf(stderr," ce.slice: %s\n", ccetostring((CCEnode*)slice)); #endif return slice; }
static CCEparsestate* ce_parse_init(char* input, CCEconstraint* constraint) { CCEparsestate* state = NULL; if(input==NULL) { cceerror(state,"ce_parse_init: no input buffer"); } else { state = (CCEparsestate*)calloc(1,sizeof(CCEparsestate)); if(state==NULL) return (CCEparsestate*)NULL; state->errorbuf[0] = '\0'; state->errorcode = 0; ccelexinit(input,&state->lexstate); state->constraint = constraint; } return state; }
static int ccelex(YYSTYPE* lvalp, CCEparsestate* state) { CCElexstate* lexstate = state->lexstate; int token; int c; int len; char* p=lexstate->next; token = 0; ncbytesclear(lexstate->yytext); ncbytesnull(lexstate->yytext); p=lexstate->next; while(token == 0 && (c=*p)) { if(c <= ' ' || c >= '\177') {p++; continue;} if(c == '"') { int more = 1; /* We have a SCAN_STRINGCONST */ while(more && (c=*(++p))) { switch (c) { case '"': p++; more=0; break; case '\\': c=*(++p); switch (c) { case 'r': c = '\r'; break; case 'n': c = '\n'; break; case 'f': c = '\f'; break; case 't': c = '\t'; break; case 'x': { int d1,d2; c = '?'; ++p; d1 = tohex(*p++); if(d1 < 0) { cceerror(state,"Illegal \\xDD in SCAN_STRING"); } else { d2 = tohex(*p++); if(d2 < 0) { cceerror(state,"Illegal \\xDD in SCAN_STRING"); } else { c=(((unsigned int)d1)<<4) | (unsigned int)d2; } } } break; default: break; } break; default: break; } ceaddyytext(lexstate,c); } token=SCAN_STRINGCONST; } else if(strchr(numchars1,c) != NULL) { /* we might have a SCAN_NUMBERCONST */ int isnumber = 0; char* yytext; char* endpoint; ceaddyytext(lexstate,c); for(p++;(c=*p);p++) { if(strchr(numcharsn,c) == NULL) break; ceaddyytext(lexstate,c); } /* See if this is a number */ ncbytesnull(lexstate->yytext); yytext = ncbytescontents(lexstate->yytext); (void)strtoll(yytext,&endpoint,10); if(*yytext != '\0' && *endpoint == '\0') isnumber = 1; else { (void)strtod(yytext,&endpoint); if(*yytext != '\0' && *endpoint == '\0') isnumber = 1; /* maybe */ } /* A number followed by an id char is assumed to just be a funny id */ if(isnumber && (*p == '\0' || strchr(wordcharsn,*p) == NULL)) { token = SCAN_NUMBERCONST; } else { /* Now, if the funny word has a "." in it, we have to back up to that dot */ char* dotpoint = strchr(yytext,'.'); if(dotpoint != NULL) { p = dotpoint; *dotpoint = '\0'; } token = SCAN_WORD; } } else if(strchr(wordchars1,c) != NULL) { /* we have a SCAN_WORD */ ceaddyytext(lexstate,c); for(p++;(c=*p);p++) { if(strchr(wordcharsn,c) == NULL) break; ceaddyytext(lexstate,c); } token=SCAN_WORD; } else { /* we have a single char token */ token = c; ceaddyytext(lexstate,c); p++; } } lexstate->next = p; len = ncbyteslength(lexstate->yytext); if(len > MAX_TOKEN_LENGTH) len = MAX_TOKEN_LENGTH; strncpy(lexstate->lasttokentext,ncbytescontents(lexstate->yytext),len); lexstate->lasttokentext[len] = '\0'; lexstate->lasttoken = token; #ifdef PARSEDEBUG if(ccedebug) dumptoken(lexstate); #endif /*Put return value onto Bison stack*/ if(ncbyteslength(lexstate->yytext) == 0) *lvalp = NULL; else { *lvalp = ncbytesdup(lexstate->yytext); nclistpush(lexstate->reclaim,(ncelem)*lvalp); } return token; }