|
|
1.1 root 1: /* documentation blocks:
2: bll 12/14/84 activate the option -6... in order to produce
3: the character in column 6 for comment line.
4: */
5: /*#ifndef lint
6: static char sccsid[] = "@(#)rlex.c 1.2 (Berkeley) 8/11/83";
7: #endif
8: */
9:
10: # include "r.h"
11:
12: char *keyword [] = {
13: "do",
14: "if",
15: "else",
16: "for",
17: "repeat",
18: "until",
19: "while",
20: "break",
21: "next",
22: "define",
23: "include",
24: "return",
25: "switch",
26: "case",
27: "default",
28: 0};
29:
30: int keytran[] = {
31: DO,
32: IF,
33: ELSE,
34: FOR,
35: REPEAT,
36: UNTIL,
37: WHILE,
38: BREAK,
39: NEXT,
40: DEFINE,
41: INCLUDE,
42: RETURN,
43: SWITCH,
44: CASE,
45: DEFAULT,
46: 0};
47:
48: char *fcnloc; /* spot for "function" */
49:
50: int svargc;
51: char **svargv;
52: char *curfile[10] = { "" };
53: int infptr = 0;
54: FILE *outfil = { stdout };
55: FILE *infile[10] = { stdin };
56: int linect[10];
57:
58: int contfld = CONTFLD; /* place to put continuation char */
59: int printcom = 0; /* print comments if on */
60: int hollerith = 0; /* convert "..." to 27H... if on */
61: int contchar = '&'; /* comment line started & at col 6 */
62:
63: #ifdef gcos
64: char *ratfor "tssrat";
65: int bcdrat[2];
66: char *bwkmeter ". bwkmeter ";
67: int bcdbwk[5];
68: #endif
69:
70: main(argc,argv) int argc; char **argv; {
71: int i;
72: while(argc>1 && argv[1][0]=='-') {
73: if(argv[1][1]=='6') {
74: contfld=6;
75: if (argv[1][2]!='\0')
76: contchar = argv[1][2];
77: } else if (argv[1][1] == 'C')
78: printcom++;
79: else if (argv[1][1] == 'h')
80: hollerith++;
81: argc--;
82: argv++;
83: }
84:
85: #ifdef gcos
86: if (!intss()) {
87: _fixup();
88: ratfor = "batrat";
89: }
90: ascbcd(ratfor,bcdrat,6);
91: ascbcd(bwkmeter,bcdbwk,24);
92: acdata(bcdrat[0],1);
93: acupdt(bcdbwk[0]);
94: if (!intss()) {
95: if ((infile[infptr]=fopen("s*", "r")) == NULL)
96: cant("s*");
97: if ((outfil=fopen("*s", "w")) == NULL)
98: cant("*s");
99: }
100: #endif
101:
102: svargc = argc;
103: svargv = argv;
104: if (svargc > 1)
105: putbak('\0');
106: for (i=0; keyword[i]; i++)
107: install(keyword[i], "", keytran[i]);
108: fcnloc = install("function", "", 0);
109: yyparse();
110: #ifdef gcos
111: if (!intss())
112: bexit(errorflag);
113: #endif
114: exit(errorflag);
115: }
116:
117: #ifdef gcos
118: bexit(status) {
119: /* this is the batch version of exit for gcos tss */
120: FILE *inf, *outf;
121: char c;
122:
123: fclose(stderr); /* make sure diagnostics get flushed */
124: if (status) /* abort */
125: _nogud();
126:
127: /* good: copy output back to s*, call forty */
128:
129: fclose(outfil,"r");
130: fclose(infile[0],"r");
131: inf = fopen("*s", "r");
132: outf = fopen("s*", "w");
133: while ((c=getc(inf)) != EOF)
134: putc(c, outf);
135: fclose(inf,"r");
136: fclose(outf,"r");
137: __imok();
138: }
139: #endif
140:
141: cant(s) char *s; {
142: linect[infptr] = 0;
143: curfile[infptr] = s;
144: error("can't open");
145: exit(1);
146: }
147:
148: inclstat() {
149: int c;
150: char *ps;
151: char fname[100];
152: while ((c = getchr()) == ' ' || c == '\t');
153: if (c == '(') {
154: for (ps=fname; (*ps=getchr()) != ')'; ps++);
155: *ps = '\0';
156: } else if (c == '"' || c == '\'') {
157: for (ps=fname; (*ps=getchr()) != c; ps++);
158: *ps = '\0';
159: } else {
160: putbak(c);
161: for (ps=fname; (*ps=getchr()) != ' ' &&*ps!='\t' && *ps!='\n' && *ps!=';'; ps++);
162: *ps = '\0';
163: }
164: if ((infile[++infptr] = fopen(fname,"r")) == NULL) {
165: cant(fname);
166: exit(1);
167: }
168: linect[infptr] = 0;
169: curfile[infptr] = fname;
170: }
171:
172: char str[500];
173: int nstr;
174:
175: yylex() {
176: int c, t;
177: for (;;) {
178: while ((c=gtok(str))==' ' || c=='\n' || c=='\t')
179: ;
180: yylval = c;
181: if (c==';' || c=='{' || c=='}')
182: return(c);
183: if (c==EOF)
184: return(0);
185: yylval = (int) str;
186: if (c == DIG)
187: return(DIGITS);
188: t = lookup(str)->ydef;
189: if (t==DEFINE)
190: defstat();
191: else if (t==INCLUDE)
192: inclstat();
193: else if (t > 0)
194: return(t);
195: else
196: return(GOK);
197: }
198: }
199:
200: int dbg = 0;
201:
202: yyerror(p) char *p; {;}
203:
204:
205: defstat() {
206: int c,i,val,t,nlp;
207: extern int nstr;
208: extern char str[];
209: while ((c=getchr())==' ' || c=='\t');
210: if (c == '(') {
211: t = '(';
212: while ((c=getchr())==' ' || c=='\t');
213: putbak(c);
214: }
215: else {
216: t = ' ';
217: putbak(c);
218: }
219: for (nstr=0; c=getchr(); nstr++) {
220: if (type[c] != LET && type[c] != DIG)
221: break;
222: str[nstr] = c;
223: }
224: putbak(c);
225: str[nstr] = '\0';
226: if (c != ' ' && c != '\t' && c != '\n' && c != ',') {
227: error("illegal define statement");
228: return;
229: }
230: val = nstr+1;
231: if (t == ' ') {
232: while ((c=getchr())==' ' || c=='\t');
233: putbak(c);
234: for (i=val; (c=getchr())!='\n' && c!='#' && c!='\0'; i++)
235: str[i] = c;
236: putbak(c);
237: } else {
238: while ((c=getchr())==' ' || c=='\t' || c==',' || c=='\n');
239: putbak(c);
240: nlp = 0;
241: for (i=val; nlp>=0 && (c=str[i]=getchr()); i++)
242: if (c == '(')
243: nlp++;
244: else if (c == ')')
245: nlp--;
246: i--;
247: }
248: for ( ; i>0; i--)
249: if (str[i-1] != ' ' && str[i-1] != '\t')
250: break;
251: str[i] = '\0';
252: install(str, &str[val], 0);
253: }
254:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.