markz@ssc.UUCP (Mark Zenier) (12/04/90)
---- Cut Here and feed the following to sh ---- #!/bin/sh # This is part 03 of Frankasm/Base # ============= fryylex.c ============== if test -f 'fryylex.c' -a X"$1" != X"-c"; then echo 'x - skipping fryylex.c (File already exists)' else echo 'x - extracting fryylex.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'fryylex.c' && X/* XHEADER: ; XTITLE: Frankenstein Cross Assemblers; XVERSION: 2.0; XDESCRIPTION: " Reconfigurable Cross-assembler producing Intel (TM) X Hex format object records. "; XKEYWORDS: cross-assemblers, 1805, 2650, 6301, 6502, 6805, 6809, X 6811, tms7000, 8048, 8051, 8096, z8, z80; XSYSTEM: UNIX, MS-Dos ; XFILENAME: fryylex.c; XWARNINGS: "This software is in the public domain. X Any prior copyright claims are relinquished. X X This software is distributed with no warranty whatever. X The author takes no responsibility for the consequences X of its use. X X Yacc (or Bison) required to compile." ; XSEE-ALSO: as*.y (yacc input files); XAUTHORS: Mark Zenier; XCOMPILERS: Microport Sys V/AT, ATT Yacc, Turbo C V1.5, Bison (CUG disk 285) X (previous versions Xenix, Unisoft 68000 Version 7, Sun 3); X*/ X X X/* X description lexical analyzer for framework cross assembler X usage Framework cross assembler, Unix X history September 13, 1987 X September 14, 1990 Dosify, 6 char unique names X October, 1990 hand carved scanner X*/ X X#include <stdio.h> X#include "frasmdat.h" X#include "fraytok.h" X X#ifndef DEBUG X#define DEBUG 0 X#endif X X extern YYSTYPE yylval; X X enum symflag {Symopcode, Symsym} whichsym = Symopcode; X X FILE *yyin; X X char finbuff[INBUFFSZ] = "L:"; X /* initialization nonreusable, wiped out by pass 2 */ X static char *frainptr = &finbuff[2]; X /* point to null byte after L: on start up */ X enum readacts nextreadact = Nra_normal; X X Xfrareadrec() X/* X description read a line, on end of file, pop the include file X stack. X return FALSE got a line X TRUE end of input X*/ X{ X while( fgets(&finbuff[2], INBUFFSZ -2, yyin) == (char *)NULL) X { X if(currfstk == 0) X { X return TRUE; X } X else X { X fclose(yyin); X yyin = infilestk[--currfstk].fpt; X fprintf(intermedf, "X:%s\n",infilestk[currfstk].fnm); X } X } X return FALSE; X} X Xstatic int currtok=0; /* subscript of next token to return */ Xstatic int intokcnt=0; /* number of tokens in queue */ X Xstatic struct X{ X char *textstrt, *textend; X YYSTYPE lvalv; X int tokv; X enum {Yetprint, Yetsymbol, Yetreserved, Yetopcode, X Yetconstant, Yetstring, Yetunprint, Yetinvalid } errtype; X} scanqueue[INBUFFSZ], *lasttokfetch, *nexttokload; X Xstatic char tempstrpool[2*INBUFFSZ]; Xstatic char *tptrstr; X X#define CXC00_SKIP 0 X#define CXC01_SPACE 1 X#define CXC02_NL 2 X#define CXC03_LETTER 3 X#define CXC04_QUOTE 4 X#define CXC05_OTHER 5 X#define CXC06_DOLLAR 6 X#define CXC07_PERCENT 7 X#define CXC08_APP 8 X#define CXC09_BIN 9 X#define CXC10_OCT 10 X#define CXC11_DEC 11 X#define CXC12_SEMIC 12 X#define CXC13_LT 13 X#define CXC14_EQ 14 X#define CXC15_GT 15 X#define CXC16_AT 16 X#define CXC17_HEXU 17 X#define CXC18_B 18 X#define CXC19_D 19 X#define CXC20_H 20 X#define CXC21_OQ 21 X#define CXC22_HEXL 22 X#define CXC23_BL 23 X#define CXC24_DL 24 X#define CXC25_BSLASH 25 X#define NUMCHARSETS 26 X Xstatic char chartrantab[128] = { X/* 00 nul soh stx etx*/ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 04 eot enq ack bel*/ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 08 bs ht nl vt */ CXC00_SKIP, CXC01_SPACE, CXC02_NL, CXC00_SKIP, X/* 0c np cr so si */ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 10 dle dc1 dc2 dc3*/ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 14 dc4 nak syn etb*/ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 18 can em sub esc*/ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 1c fs gs rs us */ CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, CXC00_SKIP, X/* 20 sp ! " # */ CXC01_SPACE, CXC03_LETTER, CXC04_QUOTE, CXC05_OTHER, X/* 24 $ % & ' */ CXC06_DOLLAR, CXC07_PERCENT, CXC03_LETTER, CXC08_APP, X/* 28 ( ) * + */ CXC05_OTHER, CXC05_OTHER, CXC05_OTHER, CXC05_OTHER, X/* 2c , - . / */ CXC05_OTHER, CXC05_OTHER, CXC05_OTHER, CXC05_OTHER, X/* 30 0 1 2 3 */ CXC09_BIN, CXC09_BIN, CXC10_OCT, CXC10_OCT, X/* 34 4 5 6 7 */ CXC10_OCT, CXC10_OCT, CXC10_OCT, CXC10_OCT, X/* 38 8 9 : ; */ CXC11_DEC, CXC11_DEC, CXC05_OTHER, CXC12_SEMIC, X/* 3c < = > ? */ CXC13_LT, CXC14_EQ, CXC15_GT, CXC05_OTHER, X/* 40 @ A B C */ CXC16_AT, CXC17_HEXU, CXC18_B, CXC17_HEXU, X/* 44 D E F G */ CXC19_D, CXC17_HEXU, CXC17_HEXU, CXC03_LETTER, X/* 48 H I J K */ CXC20_H, CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, X/* 4c L M N O */ CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, CXC21_OQ, X/* 50 P Q R S */ CXC03_LETTER, CXC21_OQ, CXC03_LETTER, CXC03_LETTER, X/* 54 T U V W */ CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, X/* 58 X Y Z [ */ CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, CXC05_OTHER, X/* 5c \ ] ^ _ */ CXC25_BSLASH, CXC05_OTHER, CXC03_LETTER, CXC03_LETTER, X/* 60 ` a b c */ CXC05_OTHER, CXC22_HEXL, CXC23_BL, CXC22_HEXL, X/* 64 d e f g */ CXC24_DL, CXC22_HEXL, CXC22_HEXL, CXC03_LETTER, X/* 68 h i j k */ CXC20_H, CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, X/* 6c l m n o */ CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, CXC21_OQ, X/* 70 p q r s */ CXC03_LETTER, CXC21_OQ, CXC03_LETTER, CXC03_LETTER, X/* 74 t u v w */ CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, X/* 78 x y z { */ CXC03_LETTER, CXC03_LETTER, CXC03_LETTER, CXC05_OTHER, X/* 7c vb } ~ del*/ CXC05_OTHER, CXC05_OTHER, CXC03_LETTER, CXC00_SKIP } ; X X X#if DEBUG X Xstatic char * statelab[] = { X " 0 start of label", X " 1 comment", X " 2 label", X " 3 rest of line", X " 4 symbol", X " 5 dollar", X " 6 hex dollar", X " 7 at sign", X " 8 octal at", X " 9 percent", X "10 bin percent", X "11 quote string", X "12 appos. string", X "13 greater than", X "14 less than", X "15 base 2 maybe", X "16 base 8 maybe", X "17 base 10 maybe", X "18 hex", X "19 found b ", X "20 found d", X "21 bslash quote", X "22 bslash appos", X }; X Xstatic char *actlab[] = { X " 0 skip/no op", X " 1 load EOL token", X " 2 start string", X " 3 process label", X " 4 save string char", X " 5 load single char token", X " 6 load EQ token", X " 7 process symbol", X " 8 load $ token", X " 9 setup for $hex", X "10 accumulate 0-9 constant", X "11 accumulate A-F constant", X "12 accumulate a-f constant", X "13 load Constant token", X "14 load @ token", X "15 setup for @octal", X "16 setup for %binary", X "17 load % token", X "18 load String token", X "19 load GE token", X "20 load GT token", X "21 load LE token", X "22 load NE token", X "23 load LT token", X "24 save numeric char 0-9", X "25 save numeric char A-F", X "26 save numeric char a-f", X "27 convert numeric string base 2", X "28 convert numeric string base 8", X "29 convert numeric string base 10", X "30 convert numeric string base 16", X "31 save numeric 0xb", X "32 save numeric 0xd", X "33 set text start", X "34 token choke" X }; X X#endif /* DEBUG */ X Xstatic struct X{ X char action; X char nextstate; X char contin; X} *thisact, characttab [23][NUMCHARSETS] = X{ X/* X STATE 0 = {start of label} X*/ X { X /* SKIP */ /* SPACE */ /* NL */ /* LETTER */ X /* QUOTE */ /* OTHER */ /* DOLLAR */ /* PERCENT */ X /* APP */ /* BIN */ /* OCT */ /* DEC */ X /* SEMIC */ /* LT */ /* EQ */ /* GT */ X /* AT */ /* HEXU */ /* B */ /* D */ X /* H */ /* OQ */ /* HEXL */ /* BL */ X /* DL */ /* BSLASH */ X {0, 0, FALSE}, {0, 3, FALSE}, {1, 0, FALSE}, {2, 2, TRUE}, X {2,11, FALSE}, {5, 3, FALSE}, {33, 5, FALSE}, {33, 9, FALSE}, X {2,12, FALSE}, {2,15, TRUE}, {2,16, TRUE}, {2,17, TRUE}, X {0, 1, FALSE}, {0,14, FALSE}, {6, 3, FALSE}, {0,13, FALSE}, X {33, 7, FALSE}, {2, 2, TRUE}, {2, 2, TRUE}, {2, 2, TRUE}, X {2, 2, TRUE}, {2, 2, TRUE}, {2, 2, TRUE}, {2, 2, TRUE}, X {2, 2, TRUE}, {5, 3, FALSE} X }, X X/* X STATE 1 = {comment} X*/ X { X {0, 1, FALSE}, {0, 1, FALSE}, {1, 0, FALSE}, {0, 1, FALSE}, X {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, X {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, X {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, X {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, X {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, {0, 1, FALSE}, X {0, 1, FALSE}, {0, 1, FALSE} X }, X X/* X STATE 2 = {label} X*/ X { X {0, 2, FALSE}, {3, 3, FALSE}, {3, 3, TRUE}, {4, 2, FALSE}, X {3, 3, TRUE}, {3, 3, TRUE}, {3, 3, TRUE}, {3, 3, TRUE}, X {3, 3, TRUE}, {4, 2, FALSE}, {4, 2, FALSE}, {4, 2, FALSE}, X {3, 1, FALSE}, {3,14, FALSE}, {3, 3, TRUE}, {3,13, FALSE}, X {3, 3, TRUE}, {4, 2, FALSE}, {4, 2, FALSE}, {4, 2, FALSE}, X {4, 2, FALSE}, {4, 2, FALSE}, {4, 2, FALSE}, {4, 2, FALSE}, X {4, 2, FALSE}, {3, 3, TRUE} X }, X X/* X STATE 3 = {rest of line} X*/ X { X {0, 3, FALSE}, {0, 3, FALSE}, {1, 0, FALSE}, {2, 4, TRUE}, X {2,11, FALSE}, {5, 3, FALSE}, {33, 5, FALSE}, {33, 9, FALSE}, X {2,12, FALSE}, {2,15, TRUE}, {2,16, TRUE}, {2,17, TRUE}, X {0, 1, FALSE}, {0,14, FALSE}, {6, 3, FALSE}, {0,13, FALSE}, X {33, 7, FALSE}, {2, 4, TRUE}, {2, 4, TRUE}, {2, 4, TRUE}, X {2, 4, TRUE}, {2, 4, TRUE}, {2, 4, TRUE}, {2, 4, TRUE}, X {2, 4, TRUE} , {5, 3, FALSE} X }, X X/* X STATE 4 = {symbol} X*/ X { X {0, 4, FALSE}, {7, 3, FALSE}, {7, 3, TRUE}, {4, 4, FALSE}, X {7, 3, TRUE}, {7, 3, TRUE}, {7, 3, TRUE}, {7, 3, TRUE}, X {7, 3, TRUE}, {4, 4, FALSE}, {4, 4, FALSE}, {4, 4, FALSE}, X {7, 1, FALSE}, {7,14, FALSE}, {7, 3, TRUE}, {7,13, FALSE}, X {7, 3, TRUE}, {4, 4, FALSE}, {4, 4, FALSE}, {4, 4, FALSE}, X {4, 4, FALSE}, {4, 4, FALSE}, {4, 4, FALSE}, {4, 4, FALSE}, X {4, 4, FALSE}, {7, 3, TRUE} X }, X X/* X STATE 5 = {dollar} X*/ X { X {0, 5, FALSE}, {8, 3, FALSE}, {8, 3, TRUE}, {8, 3, TRUE}, X {8, 3, TRUE}, {8, 3, TRUE}, {8, 3, TRUE}, {8, 3, TRUE}, X {8, 3, TRUE}, {9, 6, TRUE}, {9, 6, TRUE}, {9, 6, TRUE}, X {8, 1, FALSE}, {8,14, FALSE}, {8, 3, TRUE}, {8,13, FALSE}, X {8, 3, TRUE}, {9, 6, TRUE}, {9, 6, TRUE}, {9, 6, TRUE}, X {8, 3, TRUE}, {8, 3, TRUE}, {9, 6, TRUE}, {9, 6, TRUE}, X {9, 6, TRUE} , {8, 3, TRUE} X }, X X/* X STATE 6 = {dollar hex} X*/ X X { X {0, 6, FALSE}, {13, 3, FALSE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {10, 6, FALSE}, {10, 6, FALSE}, {10, 6, FALSE}, X {13, 1, FALSE}, {13,14, FALSE}, {13, 3, TRUE}, {13,13, FALSE}, X {13, 3, TRUE}, {11, 6, FALSE}, {11, 6, FALSE}, {11, 6, FALSE}, X {13, 3, TRUE}, {13, 3, TRUE}, {12, 6, FALSE}, {12, 6, FALSE}, X {12, 6, FALSE}, {13, 3, TRUE} X }, X/* X STATE 7 = {at sign} X*/ X { X {0, 7, FALSE}, {14, 3, FALSE}, {14, 3, TRUE}, {14, 3, TRUE}, X {14, 3, TRUE}, {14, 3, TRUE}, {14, 3, TRUE}, {14, 3, TRUE}, X {14, 3, TRUE}, {15, 8, TRUE}, {15, 8, TRUE}, {14, 3, TRUE}, X {14, 1, FALSE}, {14,14, FALSE}, {14, 3, TRUE}, {14,13, FALSE}, X {14, 3, TRUE}, {14, 3, TRUE}, {14, 3, TRUE}, {14, 3, TRUE}, X {14, 3, TRUE}, {14, 3, TRUE}, {14, 3, TRUE}, {14, 3, TRUE}, X {14, 3, TRUE}, {14, 3, TRUE} X }, X X/* X STATE 8 = {at octal} X*/ X { X {0, 8, FALSE}, {13, 3, FALSE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {10, 8, FALSE}, {10, 8, FALSE}, {13, 3, TRUE}, X {13, 1, FALSE}, {13,14, FALSE}, {13, 3, TRUE}, {13,13, FALSE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE} X }, X X/* X STATE 9 = {percent} X*/ X { X {0, 9, FALSE}, {17, 3, FALSE}, {17, 3, TRUE}, {17, 3, TRUE}, X {17, 3, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, X {17, 3, TRUE}, {16,10, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, X {17, 1, FALSE}, {17,14, FALSE}, {17, 3, TRUE}, {17,13, FALSE}, X {17, 3, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, X {17, 3, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, {17, 3, TRUE}, X {17, 3, TRUE}, {17, 3, TRUE} X }, X X/* X STATE 10 = {percent binary} X*/ X { X {0,10, FALSE}, {13, 3, FALSE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {10,10, FALSE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 1, FALSE}, {13,14, FALSE}, {13, 3, TRUE}, {13,13, FALSE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, {13, 3, TRUE}, X {13, 3, TRUE}, {13, 3, TRUE} X }, X X/* X STATE 11 = {quote string} X*/ X { X {0,11, FALSE}, {4,11, FALSE}, {34, 3, TRUE}, {4,11, FALSE}, X {18, 3, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,21, FALSE} X }, X X/* X STATE 12 = {app string} X*/ X { X {0,12, FALSE}, {4,12, FALSE}, {34, 3, TRUE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {18, 3, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,22, FALSE} X }, X X/* X STATE 13 = {greater than} X*/ X { X {0,13, FALSE}, {20, 3, FALSE}, {20, 3, TRUE}, {20, 3, TRUE}, X {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, X {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, X {20, 1, FALSE}, {20,14, FALSE}, {19, 3, FALSE}, {20,13, FALSE}, X {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, X {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, {20, 3, TRUE}, X {20, 3, TRUE}, {20, 3, TRUE} X }, X X/* X STATE 14 = {less than} X*/ X { X {0,14, FALSE}, {23, 3, FALSE}, {23, 3, TRUE}, {23, 3, TRUE}, X {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, X {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, X {23, 1, FALSE}, {23,14, FALSE}, {21, 3, FALSE}, {22,13, FALSE}, X {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, X {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, {23, 3, TRUE}, X {23, 3, TRUE}, {23, 3, TRUE} X }, X X/* X STATE 15 = {base 2 maybe} X*/ X { X {0,15, FALSE}, {29, 3, FALSE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {24,15, FALSE}, {24,16, FALSE}, {24,17, FALSE}, X {29, 1, FALSE}, {29,14, FALSE}, {29, 3, TRUE}, {29,13, FALSE}, X {29, 3, TRUE}, {25,18, FALSE}, {0,19, FALSE}, {0,20, FALSE}, X {30, 3, FALSE}, {28, 3, FALSE}, {26,18, FALSE}, {0,19, FALSE}, X {0,20, FALSE}, {29, 3, TRUE} X }, X X/* X STATE 16 = {base 8 maybe} X*/ X { X {0,16, FALSE}, {29, 3, FALSE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {24,16, FALSE}, {24,16, FALSE}, {24,17, FALSE}, X {29, 1, FALSE}, {29,14, FALSE}, {29, 3, TRUE}, {29,13, FALSE}, X {29, 3, TRUE}, {25,18, FALSE}, {25,18, FALSE}, {0,20, FALSE}, X {30, 3, FALSE}, {28, 3, FALSE}, {26,18, FALSE}, {26,18, FALSE}, X {0,20, FALSE}, {29, 3, TRUE} X }, X X/* X STATE 17 = {base10 maybe} X*/ X { X {0,17, FALSE}, {29, 3, FALSE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {24,17, FALSE}, {24,17, FALSE}, {24,17, FALSE}, X {29, 1, FALSE}, {29,14, FALSE}, {29, 3, TRUE}, {29,13, FALSE}, X {29, 3, TRUE}, {25,18, FALSE}, {25,18, FALSE}, {0,20, FALSE}, X {30, 3, FALSE}, {34, 3, FALSE}, {26,18, FALSE}, {26,18, FALSE}, X {0,20, FALSE}, {29, 3, TRUE} X }, X X/* X STATE 18 = {hex} X*/ X { X {0,18, FALSE}, {34, 3, FALSE}, {34, 3, TRUE}, {34, 3, TRUE}, X {34, 3, TRUE}, {34, 3, TRUE}, {34, 3, TRUE}, {34, 3, TRUE}, X {34, 3, TRUE}, {24,18, FALSE}, {24,18, FALSE}, {24,18, FALSE}, X {34, 1, FALSE}, {34,14, FALSE}, {34, 3, TRUE}, {34,13, FALSE}, X {34, 3, TRUE}, {25,18, FALSE}, {25,18, FALSE}, {25,18, FALSE}, X {30, 3, FALSE}, {34, 3, TRUE}, {26,18, FALSE}, {26,18, FALSE}, X {26,18, FALSE}, {34, 3, TRUE} X }, X X/* X STATE 19 = {bin or hex} X*/ X { X {0,19, FALSE}, {27, 3, FALSE}, {27, 3, TRUE}, {27, 3, TRUE}, X {27, 3, TRUE}, {27, 3, TRUE}, {27, 3, TRUE}, {27, 3, TRUE}, X {27, 3, TRUE}, {31,18, TRUE}, {31,18, TRUE}, {31,18, TRUE}, X {27, 1, FALSE}, {27,14, FALSE}, {27, 3, TRUE}, {27,13, FALSE}, X {27, 3, TRUE}, {31,18, TRUE}, {31,18, TRUE}, {31,18, TRUE}, X {31,18, TRUE}, {27, 3, TRUE}, {31,18, TRUE}, {31,18, TRUE}, X {31,18, TRUE}, {27, 3, TRUE} X }, X X/* X STATE 20 = {dec or hex} X*/ X { X {0,20, FALSE}, {29, 3, FALSE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, {29, 3, TRUE}, X {29, 3, TRUE}, {32,18, TRUE}, {32,18, TRUE}, {32,18, TRUE}, X {29, 1, FALSE}, {29,14, FALSE}, {29, 3, TRUE}, {29,13, FALSE}, X {29, 3, TRUE}, {32,18, TRUE}, {32,18, TRUE}, {32,18, TRUE}, X {32,18, TRUE}, {29, 3, TRUE}, {32,18, TRUE}, {32,18, TRUE}, X {32,18, TRUE}, {29, 3, TRUE} X }, X X/* X STATE 21 = {bslash quote} X*/ X { X {0,21, FALSE}, {4,11, FALSE}, {34, 3, TRUE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, {4,11, FALSE}, X {4,11, FALSE}, {4,11, FALSE} X }, X X/* X STATE 22 = {bslash appos} X*/ X { X {0,22, FALSE}, {4,12, FALSE}, {34, 3, TRUE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, {4,12, FALSE}, X {4,12, FALSE}, {4,12, FALSE} X } X}; X X#define YEXL 32 Xstatic char yytext[YEXL]; X Xstatic char *erryytextex(type) X int type; X{ X char * strptr, *endptr; X int charcnt; X X strptr = (lasttokfetch -> textstrt) - 1; X if(type == STRING) X { X endptr = (lasttokfetch -> textend) - 1; X if(*endptr == '\n') X endptr --; X } X else X { X endptr = (lasttokfetch -> textend) - 2; X } X X for(charcnt = 0; (strptr <= endptr) && charcnt < (YEXL - 1); charcnt ++) X { X yytext[charcnt] = *strptr++; X } X yytext[charcnt] = '\0'; X} X Xint yylex() X{ X int scanstate; X char *thistokstart; X register char nextchar; X int charset; X long consaccum, consbase; X X X X if(currtok >= intokcnt) X { X switch(nextreadact) X { X case Nra_new: /* access next file */ X fprintf(intermedf, "F:%s\n", infilestk[++currfstk].fnm); X yyin = infilestk[currfstk].fpt; X nextreadact = Nra_normal; X case Nra_normal: X if(frareadrec()) X { X /* EOF */; X return 0; X } X break; X X case Nra_end: /* pop file and access previous */ X if(currfstk > 0) X { X fclose(yyin); X yyin = infilestk[--currfstk].fpt; X fprintf(intermedf, "X:%s\n", X infilestk[currfstk].fnm); X if(frareadrec()) X { X /* EOF */; X return 0; X } X else X { X nextreadact = Nra_normal; X } X } X else X { X /* EOF */; X return 0; X } X break; X } X X if(listflag) X { X fputs(finbuff, intermedf); X } X else X { X fputs("L:\n", intermedf); X } X X /* Scan a line */ X X frainptr = &finbuff[2]; X X currtok = intokcnt = 0; X nexttokload = & scanqueue[0]; X X tptrstr = &tempstrpool[0]; X scanstate = 0; X whichsym = Symopcode; X X while( (nextchar = *frainptr++) != '\0' ) X { X charset = chartrantab[nextchar & 0x7f]; X do { X thisact = & characttab [scanstate][charset]; X X#if DEBUG X if(isprint(nextchar)) X printf("%c ", nextchar); X else X printf("0x%2.2x ", nextchar); X printf("%-18s %-33s %-11s %2.2d\n", X statelab[scanstate], X actlab[thisact -> action], X thisact -> contin ? "Continue" : "Swallow", X thisact -> nextstate); X#endif X X switch(thisact -> action) X { X case 0: /* skip/no op */ X break; X X case 1: /* load EOL token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = EOL; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 2: /* start string */ X thistokstart = tptrstr; X nexttokload -> textstrt = frainptr; X break; X X case 3: /* process label */ X { X struct symel *tempsym; X X *tptrstr++ = '\0'; X tempsym = symbentry(thistokstart, SYMBOL); X if((tempsym -> seg) != SSG_RESV) X { X nexttokload -> tokv = LABEL; X nexttokload -> errtype = Yetsymbol; X nexttokload -> lvalv.symb = tempsym; X } X else X { X nexttokload -> tokv = tempsym -> tok; X nexttokload -> errtype = Yetreserved; X nexttokload -> lvalv.intv = tempsym -> value; X } X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X } X break; X X case 4: /* save string char */ X *tptrstr++ = nextchar; X break; X X case 5: /* load single char token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = nextchar; X nexttokload -> errtype = Yetprint; X nexttokload++; X intokcnt++; X break; X X case 6: /* load EQ token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = KEOP_EQ; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 7: /* process symbol */ X { X register struct symel *symp; X register char *ytp; X int tempov; X X *tptrstr++ = '\0'; X if(whichsym == Symopcode) X { X for(ytp = thistokstart; *ytp != '\0'; X ytp++) X { X if(islower(*ytp)) X { X *ytp = toupper(*ytp); X } X } X nexttokload -> lvalv.intv X = tempov = findop(thistokstart); X nexttokload -> tokv = X optab[tempov].token; X nexttokload -> errtype = Yetopcode; X whichsym = Symsym; X } X else X { X symp = symbentry(thistokstart,SYMBOL); X if(symp -> seg != SSG_RESV) X { X nexttokload -> lvalv.symb = symp; X nexttokload -> errtype = Yetsymbol; X } X else X { X nexttokload -> lvalv.intv X = symp->value; X nexttokload -> errtype = Yetreserved; X } X X nexttokload -> tokv = symp -> tok; X } X X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X } X break; X X case 8: /* load $ token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = '$'; X nexttokload -> errtype = Yetprint; X nexttokload++; X intokcnt++; X break; X X case 9: /* setup for $hex */ X consbase = 16; X consaccum = 0; X break; X X case 10: /* accumulate 0-9 constant */ X consaccum = (consaccum * consbase) X + (nextchar - '0'); X break; X X case 11: /* accumulate A-F constant */ X consaccum = (consaccum * consbase) X + (nextchar - 'A' + 10); X break; X X case 12: /* accumulate a-f constant */ X consaccum = (consaccum * consbase) X + (nextchar - 'a' + 10); X break; X X case 13: /* load Constant token */ X nexttokload -> lvalv.longv = X consaccum; X nexttokload -> tokv = CONSTANT; X nexttokload -> errtype = Yetconstant; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X break; X X case 14: /* load @ token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = '@'; X nexttokload -> errtype = Yetprint; X nexttokload++; X intokcnt++; X break; X X case 15: /* setup for @octal */ X consbase = 8; X consaccum = 0; X break; X X case 16: /* setup for %binary */ X consbase = 2; X consaccum = 0; X break; X X case 17: /* load % token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = '%'; X nexttokload -> errtype = Yetprint; X nexttokload++; X intokcnt++; X break; X X case 18: /* load String token */ X *tptrstr++ = '\0'; X nexttokload -> lvalv.strng = X thistokstart; X nexttokload -> tokv = STRING; X nexttokload -> errtype = Yetstring; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X break; X X case 19: /* load GE token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = KEOP_GE; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 20: /* load GT token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = KEOP_GT; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 21: /* load LE token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = KEOP_LE; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 22: /* load NE token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = KEOP_NE; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 23: /* load LT token */ X nexttokload -> lvalv.longv = 0; X nexttokload -> tokv = KEOP_LT; X nexttokload -> errtype = Yetunprint; X nexttokload++; X intokcnt++; X break; X X case 24: /* save numeric char 0-9 */ X *tptrstr++ = nextchar - '0'; X break; X X case 25: /* save numeric char A-F */ X *tptrstr++ = nextchar - 'A' + 10; X break; X X case 26: /* save numeric char a-f */ X *tptrstr++ = nextchar - 'a' + 10; X break; X X case 27: /* convert numeric string base 2 */ X { X consaccum = 0; X while(thistokstart < tptrstr) X { X consaccum = (consaccum * 2) + *thistokstart++; X } X nexttokload -> lvalv.longv = consaccum; X nexttokload -> tokv = CONSTANT; X nexttokload -> errtype = Yetconstant; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X } X break; X X case 28: /* convert numeric string base 8 */ X { X consaccum = 0; X while(thistokstart < tptrstr) X { X consaccum = (consaccum * 8) + *thistokstart++; X } X nexttokload -> lvalv.longv = consaccum; X nexttokload -> tokv = CONSTANT; X nexttokload -> errtype = Yetconstant; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X } X break; X X case 29: /* convert numeric string base 10 */ X { X consaccum = 0; X while(thistokstart < tptrstr) X { X consaccum = (consaccum * 10) + *thistokstart++; X } X nexttokload -> lvalv.longv = consaccum; X nexttokload -> tokv = CONSTANT; X nexttokload -> errtype = Yetconstant; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X } X break; X X case 30: /* convert numeric string base 16 */ X { X consaccum = 0; X while(thistokstart < tptrstr) X { X consaccum = (consaccum * 16) + *thistokstart++; X } X nexttokload -> lvalv.longv = consaccum; X nexttokload -> tokv = CONSTANT; X nexttokload -> errtype = Yetconstant; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X } X break; X X case 31: /* save numeric 0xb */ X *tptrstr++ = 0xb; X break; X X case 32: /* save numeric 0xd */ X *tptrstr++ = 0xd; X break; X X case 33: /* set text start */ X nexttokload -> textstrt = frainptr; X break; X X case 34: /* token choke */ X nexttokload -> lvalv.longv = 0L; X nexttokload -> tokv = KTK_invalid; X nexttokload -> errtype = Yetinvalid; X nexttokload -> textend = frainptr; X nexttokload++; X intokcnt++; X break; X } X X scanstate = thisact -> nextstate; X X } while( thisact -> contin); X } X X if(intokcnt <= 0) X { /* no tokens in line (comment or whitespace overlength) */ X scanqueue[0].tokv = EOL; X scanqueue[0].errtype = Yetunprint; X scanqueue[0].lvalv.longv = 0; X intokcnt = 1; X } X X if(scanstate != 0) X { /* no EOL */ X fraerror("Overlength/Unterminated Line"); X } X } X lasttokfetch = &scanqueue[currtok++]; X yylval = lasttokfetch -> lvalv; X return lasttokfetch -> tokv; X} X X Xyyerror(str) X char *str; X/* X description first pass - output a parser error to intermediate file X*/ X{ X char * taglab; X X switch(lasttokfetch -> errtype) X { X case Yetprint: X if( ! isprint(lasttokfetch -> tokv)) X { X fprintf(intermedf, X "E: ERROR - %s at/before character \"^%c\"\n", X str, PRINTCTRL(lasttokfetch -> tokv)); X } X else X { X fprintf(intermedf, X "E: ERROR - %s at/before character \"%c\"\n", X str, lasttokfetch -> tokv ); X } X break; X X case Yetsymbol: X case Yetreserved: X case Yetopcode: X case Yetconstant: X erryytextex(SYMBOL); X fprintf(intermedf, "E: ERROR - %s at/before token \"%s\" \n", X str, yytext); X break; X X case Yetinvalid: X erryytextex(SYMBOL); X fprintf(intermedf, "E: ERROR - %s at invalid token \"%s\" \n", X str, yytext); X break; X X case Yetstring: X erryytextex(STRING); X fprintf(intermedf, "E: ERROR - %s at/before string %s \n", X str, yytext); X break; X X case Yetunprint: X switch(lasttokfetch -> tokv) X { X case EOL: X taglab = "End of Line"; X break; X case KEOP_EQ: X taglab = "\"=\""; X break; X case KEOP_GE: X taglab = "\">=\""; X break; X case KEOP_GT: X taglab = "\">\""; X break; X case KEOP_LE: X taglab = "\"<=\""; X break; X case KEOP_NE: X taglab = "\"<>\""; X break; X case KEOP_LT: X taglab = "\"<\""; X break; X default: X taglab = "Undeterminable Symbol"; X break; X } X fprintf(intermedf, "E: ERROR - %s at/before %s\n", X str, taglab); X break; X X default: X fprintf(intermedf, "E: ERROR - %s - undetermined yyerror type\n", X str); X break; X } X X errorcnt++; X} SHAR_EOF true || echo 'restore of fryylex.c failed' fi # ============= getopt.h ============== if test -f 'getopt.h' -a X"$1" != X"-c"; then echo 'x - skipping getopt.h (File already exists)' else echo 'x - extracting getopt.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'getopt.h' && X X X/* XHEADER: ; XTITLE: Frankenstein Cross Assemblers; XVERSION: 2.0; XDESCRIPTION: " Reconfigurable Cross-assembler producing Intel (TM) X Hex format object records. "; XSYSTEM: UNIX, MS-Dos ; XFILENAME: getopt.h; XWARNINGS: "This is some ancient code I found on a version 7 system X when I was running the original port. Asking for help from X the original authors is not advised. (Especially after X the hack job I did on it. Mark Zenier.) " ; XSEE-ALSO: frasmain.c; XAUTHORS: Keith Bostic, Rich $alz; X*/ X/* X** This is a public domain version of getopt(3). X** Bugs, fixes to: X** Keith Bostic X** ARPA: keith@seismo X** UUCP: seismo!keith X** Added NO_STDIO, opterr handling, Rich $alz (mirror!rs). X X Framework Cross Assembler X use strchr X remove NO_STDIO code X Mark Zenier Specialized Systems Consultants, Inc. X*/ X X/* X** Error macro. Maybe we want stdio, maybe we don't. X** The (undocumented?) variable opterr tells us whether or not X** to print errors. X*/ X X#define tell(s) \ X if (opterr) \ X (void)fputs(*nargv, stderr), \ X (void)fputs(s,stderr), \ X (void)fputc(optopt, stderr), \ X (void)fputc('\n', stderr) X X X X/* Global variables. */ Xstatic char EMSG[] = ""; Xint opterr = 1; /* undocumented error-suppressor*/ Xint optind = 1; /* index into argv vector */ Xint optopt; /* char checked for validity */ Xchar *optarg; /* arg associated with option */ X X Xgetopt(nargc, nargv, ostr) X int nargc; X char **nargv; X char *ostr; X{ X static char *place = EMSG; /* option letter processing */ X register char *oli; /* option letter list index */ X X if (!*place) /* update scanning pointer */ X { X if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) X return(EOF); X if (*place == '-') /* found "--" */ X { X optind++; X return(EOF); X } X } X /* option letter okay? */ X if ((optopt = *place++) == ':' || (oli = strchr(ostr, optopt)) == NULL) X { X if (!*place) X optind++; X tell(": illegal option -- "); X goto Bad; X } X if (*++oli != ':') /* don't need argument */ X { X optarg = NULL; X if (!*place) X optind++; X } X else /* need an argument */ X { X if (*place) X optarg = place; /* no white space */ X else X if (nargc <= ++optind) X { X place = EMSG; X tell(": option requires an argument -- "); X goto Bad; X } X else X optarg = nargv[optind]; /* white space */ X place = EMSG; X optind++; X } X return(optopt); /* dump back option letter */ XBad: X return('?'); X} X SHAR_EOF true || echo 'restore of getopt.h failed' fi # ============= makefile.dos ============== if test -f 'makefile.dos' -a X"$1" != X"-c"; then echo 'x - skipping makefile.dos (File already exists)' else echo 'x - extracting makefile.dos (Text)' sed 's/^X//' << 'SHAR_EOF' > 'makefile.dos' && X# X# HEADER: ; X# TITLE: Frankenstein Cross Assemblers; X# VERSION: 2.0; X# SYSTEM: MS-DOS; X# FILENAME: makefile (dos); X# DESCRIPTION: "Reconfigurable Cross-assembler producing Intel (TM) X# Hex format object records. "; X# KEYWORDS: cross-assemblers, 1805, 2650, 6301, 6502, 6805, 6809, X# 6811, tms7000, 8048, 8051, 8096, z8, z80; X# WARNINGS: "the bison simple parser, simple.prs in the version X# used, must be accessable. X# X# The version of bison used produces output files named X# {name}.c and {name}.h as opposed to the original X# {name}.tab.[ch]. X# X# This software is in the public domain. X# Any prior copyright claims are relinquished. X# X# This software is distributed with no warranty whatever. X# The author takes no responsibility for the consequences X# of its use. X# X# Yacc (or Bison) required to compile." ; X# AUTHORS: Mark Zenier; X# COMPILERS: Turbo C v 1.5, Bison (Cug disk 285, January 1989); X# X# usage X# make -DTARGET=as1805 X# X# X# Conditional Compilation Flags X# X# DOSTMP use the current directory for temporary intermediate X# file X# NOGETOPT use the getopt.h file X# USEINDEX redefine the strchr() library function to use X# the older equivalent name index() X# NOSTRING use internal definitions if the <string.h> include X# file does not exist X# X XCFLAGS = XYACCLEXLIB = XLEXNEEDS = XMAINNEEDS = -DDOSTMP -DNOGETOPT XMAINDEPENDS = getopt.h X X X$(TARGET) : frasmain.obj frapsub.obj fryylex.obj $(TARGET).obj fraosub.obj X tcc $(CFLAGS) -e$(TARGET) frasmain.obj frapsub.obj\ X fraosub.obj fryylex.obj $(TARGET).obj $(YACCLEXLIB) X del fraytok.h X Xfrasmain.obj : frasmain.c frasmdat.h $(MAINDEPENDS) X tcc $(CFLAGS) $(MAINNEEDS) -c frasmain.c X Xfryylex.obj : fryylex.c fraytok.h frasmdat.h X tcc $(CFLAGS) $(LEXNEEDS) -c fryylex.c X X$(TARGET).c $(TARGET).h : $(TARGET).y X bison -d $(TARGET).y X Xfraytok.h : $(TARGET).h X copy $(TARGET).h fraytok.h X X$(TARGET).obj : $(TARGET).c frasmdat.h fragcon.h X tcc $(CFLAGS) -c $(TARGET).c X Xfrapsub.obj : frapsub.c fragcon.h frasmdat.h fraeuni.h fraebin.h X tcc $(CFLAGS) -c frapsub.c X Xfraosub.obj : fraosub.c frasmdat.h fragcon.h fraeuni.h fraebin.h X tcc $(CFLAGS) -c fraosub.c X SHAR_EOF true || echo 'restore of makefile.dos failed' fi # ============= makeone.bat ============== if test -f 'makeone.bat' -a X"$1" != X"-c"; then echo 'x - skipping makeone.bat (File already exists)' else echo 'x - extracting makeone.bat (Text)' sed 's/^X//' << 'SHAR_EOF' > 'makeone.bat' && Xmake -DTARGET=%1 X%1 -l test.out %1.tst Xfc test.out %1.tut SHAR_EOF true || echo 'restore of makeone.bat failed' fi exit 0