lex.c.2
上传用户:upcnvip
上传日期:2007-01-06
资源大小:474k
文件大小:36k
- if (cp != closing)
- return 0;
- strlist_remove((Strlist **)rctable[i].ptr, namebuf);
- } else {
- if (!isspace(*cp) && *cp != '=')
- return 0;
- skipspc(cp);
- if (*cp == '=') {
- cp++;
- skipspc(cp);
- }
- if (chgmode == '=' || isspace(chgmode))
- strlist_remove((Strlist **)rctable[i].ptr, namebuf);
- sp = strlist_append((Strlist **)rctable[i].ptr, namebuf);
- if (tempopt)
- strlist_insert(&tempoptionlist, namebuf)->value = i;
- cp2 = namebuf;
- while (*cp && cp != closing && !isspace(*cp))
- *cp2++ = *cp++;
- *cp2++ = 0;
- skipspc(cp);
- if (cp != closing)
- return 0;
- sp->value = (long)stralloc(namebuf);
- }
- inbufptr = after;
- if (lex_initialized)
- handle_nameof(); /* as good a place to do this as any! */
- return 1;
- case 3: /* Synonym parameter */
- if (isspace(*cp) || *cp == '=' ||
- *cp == '+' || *cp == '-') {
- chgmode = *cp++;
- skipspc(cp);
- cp2 = namebuf;
- while (isalnum(*cp) || *cp == '_' ||
- *cp == '$' || *cp == '%')
- *cp2++ = *cp++;
- *cp2++ = 0;
- if (!*namebuf)
- return 0;
- skipspc(cp);
- if (!pascalcasesens)
- upc(namebuf);
- sym = findsymbol(namebuf);
- if (chgmode == '-') {
- if (cp != closing)
- return 0;
- sym->flags &= ~SSYNONYM;
- inbufptr = after;
- return 1;
- }
- if (*cp == '=') {
- cp++;
- skipspc(cp);
- }
- cp2 = namebuf;
- while (isalnum(*cp) || *cp == '_' ||
- *cp == '$' || *cp == '%')
- *cp2++ = *cp++;
- *cp2++ = 0;
- skipspc(cp);
- if (cp != closing)
- return 0;
- sym->flags |= SSYNONYM;
- if (!pascalcasesens)
- upc(namebuf);
- if (*namebuf)
- strlist_append(&sym->symbolnames, "===")->value =
- (long)findsymbol(namebuf);
- else
- strlist_append(&sym->symbolnames, "===")->value=0;
- inbufptr = after;
- return 1;
- }
- return 0;
- }
- return 0;
- }
- return 0;
- }
- Static void comment(starparen)
- int starparen; /* 0={ }, 1=(* *), 2=C comments*/
- {
- register char ch;
- int nestcount = 1, startlnum = inf_lnum, trailing;
- int i, cmtindent, cmtindent2;
- char *cp;
- cp = inbuf;
- while (isspace(*cp))
- cp++;
- trailing = (*cp != '{' && ((*cp != '(' && *cp != '/') || cp[1] != '*'));
- cmtindent = inbufindent;
- cmtindent2 = cmtindent + 1 + (starparen != 0);
- cp = inbufptr;
- while (isspace(*cp))
- cmtindent2++, cp++;
- cp = curtokbuf;
- for (;;) {
- ch = *inbufptr++;
- switch (ch) {
- case '}':
- if ((!starparen || nestedcomments == 0) &&
- starparen != 2 &&
- --nestcount <= 0) {
- *cp = 0;
- if (!commenting_flag)
- commentline(trailing ? CMT_TRAIL : CMT_POST);
- return;
- }
- break;
- case '{':
- if (nestedcomments == 1 && starparen != 2)
- nestcount++;
- break;
- case '*':
- if ((*inbufptr == ((starparen == 2) ? '/' : ')') &&
- (starparen || nestedcomments == 0)) &&
- --nestcount <= 0) {
- inbufptr++;
- *cp = 0;
- if (!commenting_flag)
- commentline(trailing ? CMT_TRAIL : CMT_POST);
- return;
- }
- break;
- case '(':
- if (*inbufptr == '*' && nestedcomments == 1 &&
- starparen != 2) {
- *cp++ = ch;
- ch = *inbufptr++;
- nestcount++;
- }
- break;
- case 0:
- *cp = 0;
- if (commenting_flag)
- saveinputcomment(inbufptr-1);
- else
- commentline(CMT_POST);
- trailing = 0;
- getline();
- i = 0;
- for (;;) {
- if (*inbufptr == ' ') {
- inbufptr++;
- i++;
- } else if (*inbufptr == 't') {
- inbufptr++;
- i++;
- if (intabsize)
- i = (i / intabsize + 1) * intabsize;
- } else
- break;
- }
- cp = curtokbuf;
- if (*inbufptr) {
- if (i == cmtindent2 && !starparen)
- cmtindent--;
- cmtindent2 = -1;
- if (i >= cmtindent) {
- *cp++ = ' 02';
- i -= cmtindent;
- } else {
- *cp++ = ' 03';
- }
- while (--i >= 0)
- *cp++ = ' ';
- } else
- *cp++ = ' 03';
- continue;
- case EOFMARK:
- error(format_d("Runaway comment from line %d", startlnum));
- return; /* unnecessary */
- }
- *cp++ = ch;
- }
- }
- char *getinlinepart()
- {
- char *cp, *buf;
- for (;;) {
- if (isspace(*inbufptr)) {
- inbufptr++;
- } else if (!*inbufptr) {
- getline();
- } else if (*inbufptr == '{') {
- inbufptr++;
- comment(0);
- } else if (*inbufptr == '(' && inbufptr[1] == '*') {
- inbufptr += 2;
- comment(1);
- } else
- break;
- }
- cp = inbufptr;
- while (isspace(*cp) || isalnum(*cp) ||
- *cp == '_' || *cp == '$' ||
- *cp == '+' || *cp == '-' ||
- *cp == '<' || *cp == '>')
- cp++;
- if (cp == inbufptr)
- return "";
- while (isspace(cp[-1]))
- cp--;
- buf = format_s("%s", inbufptr);
- buf[cp-inbufptr] = 0; /* truncate the string */
- inbufptr = cp;
- return buf;
- }
- Static int getflag()
- {
- int res = 1;
- gettok();
- if (curtok == TOK_IDENT) {
- res = (strcmp(curtokbuf, "OFF") != 0);
- gettok();
- }
- return res;
- }
- char getchartok()
- {
- if (!*inbufptr) {
- warning("Unexpected end of line [236]");
- return ' ';
- }
- if (isspace(*inbufptr)) {
- warning("Whitespace not allowed here [237]");
- return ' ';
- }
- return *inbufptr++;
- }
- char *getparenstr(buf)
- char *buf;
- {
- int count = 0;
- char *cp;
- if (inbufptr < buf) /* this will get most bad cases */
- error("Can't handle a line break here");
- while (isspace(*buf))
- buf++;
- cp = buf;
- for (;;) {
- if (!*cp)
- error("Can't handle a line break here");
- if (*cp == '(')
- count++;
- if (*cp == ')')
- if (--count < 0)
- break;
- cp++;
- }
- inbufptr = cp + 1;
- while (cp > buf && isspace(cp[-1]))
- cp--;
- return format_ds("%.*s", (int)(cp - buf), buf);
- }
- void leadingcomments()
- {
- for (;;) {
- switch (*inbufptr++) {
- case 0:
- getline();
- break;
- case ' ':
- case 't':
- case 26:
- /* ignore whitespace */
- break;
- case '{':
- if (!parsecomment(1, 0)) {
- inbufptr--;
- return;
- }
- break;
- case '(':
- if (*inbufptr == '*') {
- inbufptr++;
- if (!parsecomment(1, 1)) {
- inbufptr -= 2;
- return;
- }
- break;
- }
- /* fall through */
- default:
- inbufptr--;
- return;
- }
- }
- }
- void get_C_string(term)
- int term;
- {
- char *cp = curtokbuf;
- char ch;
- int i;
- while ((ch = *inbufptr++)) {
- if (ch == term) {
- *cp = 0;
- curtokint = cp - curtokbuf;
- return;
- } else if (ch == '\') {
- if (isdigit(*inbufptr)) {
- i = (*inbufptr++) - '0';
- if (isdigit(*inbufptr))
- i = i*8 + (*inbufptr++) - '0';
- if (isdigit(*inbufptr))
- i = i*8 + (*inbufptr++) - '0';
- *cp++ = i;
- } else {
- ch = *inbufptr++;
- switch (tolower(ch)) {
- case 'n':
- *cp++ = 'n';
- break;
- case 't':
- *cp++ = 't';
- break;
- case 'v':
- *cp++ = 'v';
- break;
- case 'b':
- *cp++ = 'b';
- break;
- case 'r':
- *cp++ = 'r';
- break;
- case 'f':
- *cp++ = 'f';
- break;
- case '\':
- *cp++ = '\';
- break;
- case ''':
- *cp++ = ''';
- break;
- case '"':
- *cp++ = '"';
- break;
- case 'x':
- if (isxdigit(*inbufptr)) {
- if (isdigit(*inbufptr))
- i = (*inbufptr++) - '0';
- else
- i = (toupper(*inbufptr++)) - 'A' + 10;
- if (isdigit(*inbufptr))
- i = i*16 + (*inbufptr++) - '0';
- else if (isxdigit(*inbufptr))
- i = i*16 + (toupper(*inbufptr++)) - 'A' + 10;
- *cp++ = i;
- break;
- }
- /* fall through */
- default:
- warning("Strange character in C string [238]");
- }
- }
- } else
- *cp++ = ch;
- }
- *cp = 0;
- curtokint = cp - curtokbuf;
- warning("Unterminated C string [239]");
- }
- void begincommenting(cp)
- char *cp;
- {
- if (!commenting_flag) {
- commenting_ptr = cp;
- }
- commenting_flag++;
- }
- void saveinputcomment(cp)
- char *cp;
- {
- if (commenting_ptr)
- sprintf(curtokbuf, "%.*s", (int)(cp - commenting_ptr), commenting_ptr);
- else
- sprintf(curtokbuf, "