1: #include <stdio.h> 2: #include "as.yh" 3: #define NCPS 24 4: #define LIBNAME " .LIBRARY /DB0:[C]JEQL.MLB/\n" 5: #define TRUE 1 6: #define FALSE 0 7: #define clearl() (*strpnt=0,fputs(strbuf,stdout),strpnt=strbuf) 8: FILE *tmpfil; 9: FILE *relfil; 10: FILE *txtfil; 11: char yytext[NCPS+2]; 12: char sname[8]; 13: char strbuf[512]; 14: char *strpnt = strbuf; 15: int pending; 16: int index; 17: int lineno; 18: int curval; 19: int skipspace; 20: int coffset; 21: int yylval; 22: long intval; 23: int anyerrs; 24: int sawname; 25: int saveit; 26: /*define yylex() (fprintf(stderr,"yylex returns %d\n",saveit=oyylex()),saveit)*/ 27: #define yylex() oyylex() 28: 29: main(argc,argv) 30: register char **argv; 31: { 32: int nameflag = 0;char namebuf[16]; register int i; 33: if(--argc>0) { 34: freopen(*++argv,"r",stdin); 35: nameflag = 1; 36: } 37: if(--argc>0) 38: freopen(argv[1],"w",stdout); 39: if(nameflag) { 40: register char *base = *argv; 41: 42: while(*base++); /* Find end */ 43: while(--base>=*argv && *base!='/'); /* find last slash */ 44: base++; /* set base */ 45: for(i = 0; i < 16 && base[i] && base[i]!='.';) 46: namebuf[i++]=((base[i] >= 'a' && base[i] <= 'z') 47: ? (base[i] + 'A' -'a') : base[i]); 48: namebuf[i] = 0; 49: printf("\t.TITLE\t%s\n",namebuf); 50: printf(LIBNAME); 51: } 52: 53: 54: loop: 55: for(;;) { 56: i = yylex(); 57: again: 58: switch(i) { 59: 60: case NL: 61: clearl(); 62: break; 63: 64: case NAME: 65: sawname = 1; 66: break; 67: 68: case CM: case SP: 69: sawname = 0; 70: 71: case LP: 72: fixlength(); 73: break; 74: 75: case 0: 76: goto done; 77: 78: } 79: } 80: done: printf(" .END\n"); 81: } 82: 83: fixlength(){ 84: register char *cp = strpnt; 85: if(sawname==0) return; 86: while(*--cp != ' ' && *cp != '\t' && *cp != ',' && *cp!='@') { 87: cp[2] = *cp; 88: if(cp <= strbuf) yyerror("Bad ( construction"); 89: } 90: cp++; 91: *cp++ = 'L'; 92: *cp++ = '^'; 93: strpnt += 2; 94: } 95: 96: static long mask[] = { 97: 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8, 98: 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80, 99: 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800, 100: 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000, 101: 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000, 102: 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000, 103: 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000, 104: 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000, 105: }; 106: 107: short type[] = { 108: EOF, 109: SP, 0, 0, 0, 0, 0, 0, 0, 110: 0, SP, NL, 0, 0, SP, 0, 0, 111: 0, 0, 0, 0, 0, 0, 0, 0, 112: 0, 0, 0, 0, 0, 0, 0, 0, 113: SP, 0, 0, SH, LITOP, REG, AND, SQ, 114: LP, RP, MUL, PLUS, CM, MINUS, ALPH, DIV, 115: DIG, DIG, DIG, DIG, DIG, DIG, DIG, DIG, 116: DIG, DIG, COLON, SEMI, LSH, 0, RSH, 0, 117: 0, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, 118: ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, 119: ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, 120: ALPH, ALPH, ALPH, LB, 0, RB, XOR, ALPH, 121: 0, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, 122: ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, 123: ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, ALPH, 124: ALPH, ALPH, ALPH, 0, IOR, 0, TILDE, 0, 125: }; 126: 127: oyylex() 128: { 129: register val; 130: register base; 131: register char *cp; 132: struct symtab *op; 133: static double fltval; 134: char fltchr[64]; 135: int minflag = FALSE; 136: 137: loop: 138: switch(yylval = (type+1)[val = getchar()]) { 139: 140: case SH: 141: copy(';'); 142: while ((val = getchar()) != '\n' && val>0) 143: copy(val); 144: copy(val); 145: val = NL; 146: goto ret; 147: 148: 149: case EOF: 150: val = 0; 151: goto ret; 152: 153: case ALPH: 154: cp = yytext; 155: if(val=='_') val = getchar(); 156: do { 157: if (cp <= &yytext[NCPS]) 158: *cp++ = val; 159: copy(val); 160: } while ((type+1)[val=getchar()]==ALPH || (type+1)[val]==DIG 161: || (type+1)[val]==LITOP); 162: *cp = '\0'; 163: if(skipspace) 164: for(;(type+1)[val]==SP; val = getchar()) 165: copy(val); 166: ungetc(val, stdin); 167: if(*yytext!='.') 168: return(val=NAME); 169: else if(strcmp(yytext,".byte")==0) 170: return(IBYTE); 171: else if(strcmp(yytext,".word")==0) 172: return(IWORD); 173: else if(strcmp(yytext,".long")==0) 174: return(ILONG); 175: else 176: return(NAME); 177: 178: case MINUS: 179: copy(val); 180: switch ((type+1)[val = getchar()]) { 181: case LP: 182: copy(val); 183: return(val = MP); 184: case DIG: 185: break; 186: default: 187: ungetc(val,stdin); 188: return(val = MINUS); 189: } 190: minflag = TRUE; 191: case DIG: 192: intval = val-'0'; 193: if (val=='0') { 194: val = getchar(); 195: if (val=='x' || val=='X') { 196: base = 16; 197: copy('^'); 198: copy('X'); 199: } else if (val=='d' || val=='D' || val=='f' || val=='F') { 200: char *p = fltchr; 201: double atof(); 202: while (p < &fltchr[63] && ((val=getchar())=='.' 203: || val=='e' || val=='d' || val=='E' || val=='D' 204: || val=='-' || val=='+' || (type+1)[val]==DIG)) 205: copy(val),*p++ = val; 206: ungetc(val, stdin); 207: *p++ = '\0'; 208: fltval = atof(fltchr); 209: val = FLTNUM; 210: goto ret; 211: } else { 212: ungetc(val, stdin); 213: base = 8; 214: if((type+1)[val]!=DIG) { 215: copy('0'); 216: val = INT; 217: yylval = 0; 218: goto ret; 219: } 220: copy('^'); 221: copy('O'); 222: } 223: } else 224: copy(val),base = 10; 225: while ((type+1)[val=getchar()]==DIG 226: || (base==16 && (val>='a' && val<='f'||val>='A' && val<='F'))) { 227: copy(val); 228: if (base==8) 229: intval <<= 3; 230: else if (base==10) 231: intval *= 10; 232: else 233: intval <<= 4; 234: if (val>='a' && val<='f') 235: val -= 'a' - 10 - '0'; 236: else if (val>='A' && val<='F') 237: val -= 'A' - 10 - '0'; 238: intval += val-'0'; 239: } 240: ungetc(val, stdin); 241: val = INT; 242: if(minflag) intval = -intval; 243: goto ret; 244: 245: 246: case MUL: 247: copy('@'); 248: goto ret; 249: 250: case LITOP: 251: copy('#'); 252: goto ret; 253: 254: case SQ: 255: if ((yylval = getchar()) == '\n') 256: lineno++; 257: intval = yylval; 258: sprintf(strpnt,"%d",intval); 259: for(;(strpnt<&strbuf[512])&& *strpnt; strpnt++); 260: val = INT; 261: goto ret; 262: 263: case 0: 264: yyerror("Illegal character"); 265: val = NOCHAR; 266: goto ret; 267: 268: case SP: 269: if(skipspace) { 270: copy(val); 271: goto loop; 272: } 273: 274: default: 275: copy(val); 276: val = yylval; 277: goto ret; 278: } 279: ret: 280: return(val); 281: } 282: 283: yyerror(s, a) 284: char *s; 285: { 286: if (anyerrs==0) 287: fprintf(stderr, "Assembler:\n"); 288: anyerrs++; 289: fprintf(stderr, "line %d: ", lineno); 290: fprintf(stderr, s, a); 291: fprintf(stderr, "\n"); 292: } 293: 294: copy(p) 295: register p; 296: { 297: if(p>='a'&&p<='z') 298: p += 'A' - 'a'; 299: if(strpnt<strbuf+512) 300: *strpnt++=(p); 301: return(p); 302: }