⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getsym.c

📁 一款拥有一定历史的C语言编译器
💻 C
📖 第 1 页 / 共 4 页
字号:
	    break;
	case 'A':
	case 'B':
	case 'C':
	case 'D':
	case 'E':
	case 'F':
	case 'G':
	case 'H':
	case 'I':
	case 'J':
	case 'K':
	case 'L':
	case 'M':
	case 'N':
	case 'O':
	case 'P':
	case 'Q':
	case 'R':
	case 'S':
	case 'T':
	case 'U':
	case 'V':
	case 'W':
	case 'X':
	case 'Y':
	case 'Z':
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':
	case 'g':
	case 'h':
	case 'i':
	case 'j':
	case 'k':
	case 'l':
	case 'm':
	case 'n':
	case 'o':
	case 'p':
	case 'q':
	case 'r':
	case 's':
	case 't':
	case 'u':
	case 'v':
	case 'w':
	case 'x':
	case 'y':
	case 'z':
	case '_':
	    getid ();
	    if (lang_option >= LANG_C99) {
		while (lastst == kw_pragma) {
		    process_pragma_operator ();
		}
	    }
	    break;
	case '+':
	    nextch ();
	    switch (*bufcur) {
	    case '+':
		lastst = tk_autoinc;
		bufcur++;
		break;
	    case '=':
		lastst = tk_asplus;
		bufcur++;
		break;
	    default:
		lastst = tk_plus;
		break;
	    }
	    break;
	case '-':
	    nextch ();
	    switch (*bufcur) {
	    case '-':
		lastst = tk_autodec;
		bufcur++;
		break;
	    case '=':
		lastst = tk_asminus;
		bufcur++;
		break;
	    case '>':
		lastst = tk_pointsto;
		bufcur++;
		break;
	    default:
		lastst = tk_minus;
		break;
	    }
	    break;
	case '*':
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_astimes;
		bufcur++;
		break;
	    default:
		lastst = tk_star;
		break;
	    }
	    break;
	case '/':
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_asdivide;
		bufcur++;
		break;
	    case '*':
		while (!end_of_file) {
		    symstart = bufcur;
		    nextch ();
		    if (*bufcur == (CHAR) '*') {
			nextch ();
			if (*bufcur == (CHAR) '/') {
			    bufcur++;
			    goto restart;   /*lint !e801*/  /* use of goto is deprecated */
			}
		    }
		}
		break;
	    case '/':
		if (lang_option >= LANG_C99) {
		    while (!end_of_file) {
			if (*bufcur == (CHAR) '\n') {
			    new_line ();
			    goto restart;   /*lint !e801*/  /* use of goto is deprecated */
			}
			nextch ();
		    }
		    break;
		}
		/*lint -fallthrough */
	    default:
		lastst = tk_divide;
		break;
	    }
	    break;
	case '^':
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_asuparrow;
		bufcur++;
		break;
	    default:
		lastst = tk_uparrow;
		break;
	    }
	    break;
	case ';':
	    lastst = tk_semicolon;
	    nextch ();
	    break;
	case ':':
	    nextch ();
	    switch (*bufcur) {
	    case '>':
		if (lang_option >= LANG_C90) {
		    lastst = tk_closebr;
		    bufcur++;
		    break;
		}
		/*lint -fallthrough */
	    default:
		lastst = tk_colon;
		break;
	    }
	    break;
	case '=':
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_eq;
		bufcur++;
		break;
	    default:
		lastst = tk_assign;
		break;
	    }
	    break;
	case '>':
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_geq;
		bufcur++;
		break;
	    case '>':
		nextch ();
		switch (*bufcur) {
		case '=':
		    lastst = tk_asrshift;
		    bufcur++;
		    break;
		default:
		    lastst = tk_rshift;
		    break;
		}
		break;
	    default:
		lastst = tk_gt;
		break;
	    }
	    break;
	case '<':
	    nextch ();
	    lastst = tk_lt;
	    switch (*bufcur) {
	    case '=':
		lastst = tk_leq;
		bufcur++;
		break;
	    case ':':
		if (lang_option >= LANG_C99) {
		    lastst = tk_openbr;
		    bufcur++;
		}
		break;
	    case '%':
		if (lang_option >= LANG_C99) {
		    lastst = tk_begin;
		    bufcur++;
		}
		break;
	    case '<':
		nextch ();
		switch (*bufcur) {
		case '=':
		    lastst = tk_aslshift;
		    bufcur++;
		    break;
		default:
		    lastst = tk_lshift;
		    break;
		}
		break;
	    default:
		break;
	    }
	    break;
	case '\'':
	    nextch ();
	    ival = (UVAL) (int) getsch (FALSE);	/* get a string char */
	    if (*bufcur == (CHAR) '\'') {
		bufcur++;
#ifndef SYNTAX_CORRECT
	    } else {
		message (ERR_CHARCONST);
#endif /* SYNTAX_CORRECT */
	    }
	    lastst = tk_iconst;
	    break;
	case '\"':
	    i = (SIZE) 0;
	    do {
		symstart = bufcur;
		nextch ();
		for (;; ++i) {
		    register int j;

		    if ((j = getsch (TRUE)) == END_STRING) {
			break;
		    }
		    if (i == strbuflen) {
			strbuflen += (SIZE) BUFLEN;
			strstart =
			    (CHAR *) realloc (strstart, (size_t) strbuflen);
		    }
		    strstart[i] = (CHAR) j;
		}
		if (*bufcur == (CHAR) '\"') {
		    nextch ();
#ifndef SYNTAX_CORRECT
		} else {
		    message (ERR_STRINGCONST);
#endif /* SYNTAX_CORRECT */
		}
		skip_space ();
	    } while (*bufcur == (CHAR) '\"' && (lang_option >= LANG_C90));

	    /*
	     *      By looking up the string in the spelling table we ensure
	     *      that the same strings will return the same pointer ... thus
	     *      removing the necessity for comparing strings elsewhere in
	     *      the compiler.
	     */
	    lastsym = found (strstart, i, FALSE);
	    lastsymlen = (SIZE) i;
	    lastst = tk_sconst;
	    break;
	case '!':
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_neq;
		bufcur++;
		break;
	    default:
		lastst = tk_not;
		break;
	    }
	    break;
	case '%':
	    lastst = tk_mod;
	    nextch ();
	    switch (*bufcur) {
	    case '=':
		lastst = tk_asmod;
		bufcur++;
		break;
	    case '>':
		if (lang_option >= LANG_C99) {
		    lastst = tk_end;
		    bufcur++;
		}
		break;
	    default:
		break;
	    }
	    break;
	case '~':
	    nextch ();
	    lastst = tk_compl;
	    break;
	case '.':
	    nextch ();
	    switch (*bufcur) {
	    case '0':
	    case '1':
	    case '2':
	    case '3':
	    case '4':
	    case '5':
	    case '6':
	    case '7':
	    case '8':
	    case '9':
#ifdef FLOAT_SUPPORT
#ifndef FLOAT_BOOTSTRAP
		rval = F_zero;
#endif /* FLOAT_BOOTSTRAP */
#endif /* FLOAT_SUPPORT */
		getfrac ();
		switch (*bufcur) {
		case 'e':
		case 'E':
		    nextch ();
		    getexp ();
		    break;
		default:
		    break;
		}
		if (lastst == tk_rconst) {
		    switch (*bufcur) {
		    case 'f':
		    case 'F':
			lastst = tk_fconst;
			bufcur++;
			break;
		    case 'l':
		    case 'L':
			lastst = tk_lrconst;
			bufcur++;
			break;
		    default:
			break;
		    }
		}
		break;
	    case '.':
		nextch ();
		switch (*bufcur) {
		case '.':
		    lastst = tk_ellipsis;
		    bufcur++;
		    break;
		default:
#ifndef SYNTAX_CORRECT
		    message (ERR_PUNCT, "..");
#endif /* SYNTAX_CORRECT */
		    continue;
		}
		break;
	    default:
		lastst = tk_dot;
		break;
	    }
	    break;
	case ',':
	    lastst = tk_comma;
	    nextch ();
	    break;
	case '&':
	    nextch ();
	    switch (*bufcur) {
	    case '&':
		lastst = tk_land;
		bufcur++;
		break;
	    case '=':
		lastst = tk_asand;
		bufcur++;
		break;
	    default:
		lastst = tk_and;
		break;
	    }
	    break;
	case '|':
	    nextch ();
	    switch (*bufcur) {
	    case '|':
		lastst = tk_lor;
		bufcur++;
		break;
	    case '=':
		lastst = tk_asor;
		bufcur++;
		break;
	    default:
		lastst = tk_or;
		break;
	    }
	    break;
	case '(':
	    lastst = tk_openpa;
	    nextch ();
	    break;
	case ')':
	    lastst = tk_closepa;
	    nextch ();
	    break;
	case '[':
	    lastst = tk_openbr;
	    nextch ();
	    break;
	case ']':
	    lastst = tk_closebr;
	    nextch ();
	    break;
	case '{':
	    lastst = tk_begin;
	    nextch ();
	    break;
	case '}':
	    lastst = tk_end;
	    nextch ();
	    break;
	case '?':
	    lastst = tk_hook;
	    nextch ();
	    break;
	case '\032':
	    /*
	     *      Some DOS editors leave a Control-Z character at the
	     *      end of the file.   Just to be nice we will ignore
	     *      this invalid character provided it really is the last
	     *      character!
	     */
	    if (end_of_file && (bufcur[1] == '\0')) {
		lastst = tk_eof;
		break;
	    }
#ifndef SYNTAX_CORRECT
	    message ((MSGNUM)
		     (is_print (*bufcur) ? ERR_ILLCHAR : ERR_ILLXCHAR),
		     (int) *bufcur);
#endif /* SYNTAX_CORRECT */
	    bufcur++;
	    continue;		/* get a real token */
	case '\0':
	    /*
	     *      There is always a zero byte at the end of the input buffer
	     *      so we have either just read a zero byte or have just
	     *      fallen off the end of the input buffer!
	     */
	    if (end_of_file) {
		lastst = tk_eof;
		break;
	    }
	    if (bufcur >= buflimit) {
		nextline ();
		continue;
	    }
	    /*lint -fallthrough */
	default:
#ifndef SYNTAX_CORRECT
	    message ((MSGNUM)
		     (is_print (*bufcur) ? ERR_ILLCHAR : ERR_ILLXCHAR),
		     (int) *bufcur);
#endif /* SYNTAX_CORRECT */
	    bufcur++;
	    continue;		/* get a real token */
	}
	if (error_resync) {
	    error_resync--;
	}
	errorloop = FALSE;
	return;
    }
}

/*
 *	needpunc() - checks current token
 *
 *	Checks that the current token is the token specified by the
 *	parameter 'p'.	If it is the expected token then it moves onto
 *	the next token, otherwise it outputs an error message.
 */
void needpunc P1 (TOKEN, p)
{
    if (lastst == p) {
	getsym ();
#ifndef SYNTAX_CORRECT
    } else {
	if (lastst != tk_eof) {
	    CHAR    ch = *bufcur;

	    *bufcur = (CHAR) '\0';
	    message (ERR_PUNCT, symstart);
	    *bufcur = ch;
	} else {
	    message (ERR_EOF);
	    exit (EXIT_FAILURE);
	}
#endif /* SYNTAX_CORRECT */
    }
}

/*
 *	is_label() - is current identifier a label
 *
 *	The is_label() routine "peeks" ahead in the input buffer to see
 *	if the identifier is followed by the ":" token.
 */
BOOL is_label P1 (TOKEN, p)
{
    if (p != tk_id) {
	return FALSE;
    }
    skip_space ();
    return (*bufcur == (CHAR) ':');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -