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

📄 scan.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	@(#)scan.c 1.1 92/07/30 SMI	*//* *	Microassembler scanner for FPA *		scan.c	1.1	30 May 1985    */#include "micro.h"#include <stdio.h>#include <ctype.h>#define scansp(c)  while(isspace(c = *curpos)) curpos++#define scanb(c) scansp(c); if (c == ',' ){c = nextc(); scansp(c);} else#define nextc()     (*++curpos)#define peekc()     (*curpos)#define MAXSYMBOL 256#define MAXLINE 1024int curlineno;char *curfilename;char *curpos;char *curline;char inputline[MAXLINE];/* The following 2 lines added by PWC to count lines of ucode. */extern NODE n[NNODE];extern NODE *curnode;extern short curaddr;extern RAMNODE ram[NINST];extern Boolean aseq();extern Boolean aweitek();extern Boolean adata();extern Boolean arecreg();extern Boolean aram();extern Boolean aptr();extern char   *strcpy();Booleannewline(){    /* glom a new input line.     * clobber comments. do     * continuation-line collection, as well.     */    register char *  maxpos = inputline + sizeof inputline - 1;    register char *cp;    char *end;    register c;    int len;    cp = inputline;restart:    curlineno++;    do {	c = getchar();	if (c == '&') {		while ( getchar() != '\n' );		goto restart;	}	*cp++ = c;    } while ( c != '\n' && c != EOF && cp < maxpos );    if ( c == EOF ) return False;    end = cp;    *cp = '\0';    if (cp == maxpos){	error("Sorry, line(s) too long");	goto process;    }process:    curpos = inputline;    len = end-inputline;    curline = (char*)malloc(len+2);    if (curline == 0) {	error("unable to get sufficient storage\n");	return False;    }    strcpy( curline, inputline );    return True;}char *scansym( ){    static char stuff[MAXSYMBOL];    register char *cp;    register char c;    Boolean ok = True;    cp = stuff;    curpos -= 1; /*back up to get a running start*/    while( ok ){	while (isalnum(*cp++ = c = nextc()));	switch(c){	case '.':	case '_':	case '\\':	    continue;	default:	    ok = False;	}    }    *--cp = '\0';    return( stuff );}intgetnum( ){    register char c = *curpos;    register int val, base;    int sign;    sign = 1;    if (c == '-') {	sign = -1;	c = nextc();    } else if (c == '+') {	c = nextc();    }    val = c - '0';    base = (val==0)? 010 : 10;    c = nextc();    if ( val == 0 && (c == 'x' || c == 'X') ){	base = 0x10;	c = nextc();    }    while(isxdigit(c)){	val *= base;	if( isdigit(c) )	    val += c -'0';	else if (islower(c))	    val += c -'a' + 10;	else	    val += c -'A' + 10;	c = nextc();    }    if (sign == -1) {	val = -val;    }    return( val );}Booleanseqpart (name)	char    *name;{	register char      c;	register RESERVED *rp;	register char     *cp;	int      brnch = 040;           /* default next */	int      state = 4;             /* default */	int      latch = 0;	int	 restore = 0;	int      offset;	SYMTYPE  which = NEITHER;	int	 num   = 0;	static   char buff[MAXSYMBOL];	char	*labl = buff;#define CHEK    if(c==';') {c=nextc(); scanb(c); return ASEQ;} \		rp = resw_lookup( cp = scansym( ) ); \		if ( rp == 0 ) goto wbotch;#define ASEQ 	aseq(brnch, which, num, labl, state, latch, restore)	if ( name == 0 && peekc() == ';') {   /* no seq field */		c = nextc();		scanb(c);		return ASEQ;	}start:	rp = resw_lookup( cp = name );	if ( rp == 0 ) goto wbotch;	if ( rp->type == Branch1) {		brnch = rp->value1;		scanb(c);		if ( rp->value2 == 2 ) {		    curnode->jumpop = True;		    if ( isdigit(c) || c == '.' ) goto address;		    if ( isalpha(c) ) {			rp = resw_lookup(cp = scansym());			if ( rp == 0 ) {			    which = ALPHA;			    strcpy (labl, cp);			    scanb(c);			    CHEK;			}		    } else goto botch;		} else {		    CHEK		}	}	if ( rp->type == Branch2 ) {		brnch += rp->value1;	address:		curnode->jumpop = True;		scanb(c);		if (isdigit(c)) {            		which = NUMBER;            		num = getnum( );            		scanb(c);        	} else if (isalpha(c)) {            		which = ALPHA;			strcpy (labl, scansym( ));            		scanb(c);        	} else if (c == '.') {            		which = NUMBER;            		offset = 0;            		c = nextc();            		scanb(c);            		if (c == '+') {                		c = nextc();                		scanb(c);                		offset = getnum();                		scanb(c);            		} else if (c == '-') {				c = nextc();                		scanb(c);                		offset = -getnum();                		scanb(c);			}             		num = curaddr - 1 + offset;        	} else goto botch;		CHEK	}	if ( rp->type == State ) {		state = rp->value1;		scanb(c);		CHEK	}	if ( rp->type == Latch && rp->value2 == 1 ) {		latch = rp->value1;		scanb(c);		CHEK		if ( rp->type == Latch && rp->value2 == 2 ) {			if (rp->value1 == 1)				restore = 1;			else				latch += rp->value1;			scanb(c);			CHEK		}	}	if ( rp->type == Latch && rp->value2 == 3 ) {		latch += rp->value1;		scanb(c);		if ( c == ';' ) {			c = nextc();			scanb(c);			return ASEQ;		}	}wbotch :	error ("%s found in seq_state field", cp );	return False;botch:	error ("seq_state field syntax error, character %c is not expected", c);	return False;#undef ASEQ#undef CHEK}Booleanweitekpart ( ) {	register char c;	register RESERVED *rp;	char     *cp;	int	 foo;	int      lplus = 0, 		 func  = 0, 		 csl   = 0, 		 csux  = 0, 		 u     = 0, 		 woe   = 0;#define CHEK    if(c==';') {c=nextc(); scanb(c); return AWEITEK;} \		rp = resw_lookup( cp = scansym( ) ); \		if ( rp == 0 ) goto wbotch;#define AWEITEK aweitek(lplus, func, csl, csux, u, woe)	scanb(c);	if ( c == ';' ) {    /* no weitek field */		c = nextc();		scanb(c);		return AWEITEK;	}	rp = resw_lookup(cp=scansym( ));	if ( rp == 0 ) goto wbotch;	if (rp->type != Loadctrl && rp->type != Mode) goto csux_l;	if (rp->type == Loadctrl ) {		lplus = rp->value1;		if (rp->value2 == 0) {			scanb(c);			if (c == ';') {				error("function expected");				return False;			} else {				CHEK				if ( rp->type == Function ) {					func = rp->value1;					scanb(c);					if (c == ';') {						error("csl control expected");						return False;					} else {						CHEK					}        			} else {					error("function expected");					return False;				}			}			scanb(c);			goto csl_l;		}		scanb(c);		if (c == ';') {			error("csl control expected");			return False;		} else {			CHEK		}		goto csl_l;	}	if ( rp->type == Mode) {  /*LMODE*/		scanb(c);		lplus = rp->value1;		func = rp->value2;		if ( func == 0x40 ) {			if (c == ';') {				error("csl control expected");				return False;			} else {				CHEK			}			goto csl_l;		}		if ( isdigit(c) ) {			foo = getnum( );			if ( foo > 0x10 || foo < 0 ) {				error ("number %d is out of range for the mode field", foo );				return False;			}			func += foo;		} else goto wbotch;		scanb(c);		if (c == ';') {			error("csl control expected");			return False;		} else {			CHEK		}	}csl_l:	if ( rp->type == Csl ) {		csl = rp->value1;		scanb(c);                CHEK	} else {		error("csl control expected");		return False;	}csux_l:	if ( rp->type == Csux ) {		csux = rp->value1;		scanb(c);		if (c == ';') {			error("u+ control expected");			return False;		} else {			CHEK		}		if ( rp->type == U ) {			u = rp->value1;			scanb(c);                	CHEK		} else {			error("u+ control expected");			return False;		}	}	if ( rp->type == Woe ) {		woe = rp->value1;		scanb(c);                if ( c == ';' ) {			c = nextc();			scanb(c);			return AWEITEK;		}	}	error ("WeitekInst syntax error, character %c is not expected", c);	return False;wbotch :	error ("%s found in WeitekInst field", cp );	return False;#undef CHEK#undef AWEITEK}Booleandatapart( ){	register char c;	register RESERVED *rp;	char    *cp;	int      dctrl = 0;#define ADATA   adata(dctrl)#define CHEK    if(c==';') {c=nextc(); scanb(c); return ADATA;} \		rp = resw_lookup( cp = scansym( ) ); \		if ( rp == 0 ) goto wbotch;	scanb(c);	if ( c == ';' ) {    /* no datamuxing field */		c = nextc();		scanb(c);		return ADATA;	}	rp = resw_lookup(cp=scansym( ));	if ( rp == 0 ) goto wbotch;	if (rp->type == Datactrl ) {		dctrl = rp->value1;		scanb(c);		if ( rp->value2 == 0 ) goto end;		CHEK		if (rp->type == Datactrl && rp->value1 == 021 ) { /* dtor */			dctrl += 1;			scanb(c);		end:			if (c == ';') {				c = nextc();				scanb(c);				return ADATA;			}		}	}	error ("datamuxing syntax error, character %c is not expected", c);	return False;wbotch :	error ("%s found in datamuxing field", cp );	return False;#undef ADATA#undef CHEK}Booleanrecpart ( ){	register char c;	register RESERVED *rp;	char    *cp;	int      recreg = 0;	

⌨️ 快捷键说明

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