basic.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. /* A recursive-descent parser generated by peg 0.1.1 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define YYRULECOUNT 22
  6. # include <stdio.h>
  7. typedef struct line line;
  8. struct line
  9. {
  10. int number;
  11. int length;
  12. char *text;
  13. };
  14. line *lines= 0;
  15. int numLines= 0;
  16. int pc= -1, epc= -1;
  17. int batch= 0;
  18. int nextline(char *buf, int max);
  19. # define min(x, y) ((x) < (y) ? (x) : (y))
  20. # define YY_INPUT(buf, result, max_size) \
  21. { \
  22. if ((pc >= 0) && (pc < numLines)) \
  23. { \
  24. line *linep= lines+pc++; \
  25. result= min(max_size, linep->length); \
  26. memcpy(buf, linep->text, result); \
  27. } \
  28. else \
  29. result= nextline(buf, max_size); \
  30. }
  31. union value {
  32. int number;
  33. char *string;
  34. int (*binop)(int lhs, int rhs);
  35. };
  36. # define YYSTYPE union value
  37. int variables[26];
  38. void accept(int number, char *line);
  39. void save(char *name);
  40. void load(char *name);
  41. void type(char *name);
  42. int lessThan(int lhs, int rhs) { return lhs < rhs; }
  43. int lessEqual(int lhs, int rhs) { return lhs <= rhs; }
  44. int notEqual(int lhs, int rhs) { return lhs != rhs; }
  45. int equalTo(int lhs, int rhs) { return lhs == rhs; }
  46. int greaterEqual(int lhs, int rhs) { return lhs >= rhs; }
  47. int greaterThan(int lhs, int rhs) { return lhs > rhs; }
  48. int input(void);
  49. int stack[1024], sp= 0;
  50. char *help;
  51. void error(char *fmt, ...);
  52. int findLine(int n, int create);
  53. #ifndef YY_VARIABLE
  54. #define YY_VARIABLE(T) static T
  55. #endif
  56. #ifndef YY_LOCAL
  57. #define YY_LOCAL(T) static T
  58. #endif
  59. #ifndef YY_ACTION
  60. #define YY_ACTION(T) static T
  61. #endif
  62. #ifndef YY_RULE
  63. #define YY_RULE(T) static T
  64. #endif
  65. #ifndef YY_PARSE
  66. #define YY_PARSE(T) T
  67. #endif
  68. #ifndef YYPARSE
  69. #define YYPARSE yyparse
  70. #endif
  71. #ifndef YYPARSEFROM
  72. #define YYPARSEFROM yyparsefrom
  73. #endif
  74. #ifndef YY_INPUT
  75. #define YY_INPUT(buf, result, max_size) \
  76. { \
  77. int yyc= getchar(); \
  78. result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
  79. yyprintf((stderr, "<%c>", yyc)); \
  80. }
  81. #endif
  82. #ifndef YY_BEGIN
  83. #define YY_BEGIN ( yybegin= yypos, 1)
  84. #endif
  85. #ifndef YY_END
  86. #define YY_END ( yyend= yypos, 1)
  87. #endif
  88. #ifdef YY_DEBUG
  89. # define yyprintf(args) fprintf args
  90. #else
  91. # define yyprintf(args)
  92. #endif
  93. #ifndef YYSTYPE
  94. #define YYSTYPE int
  95. #endif
  96. #ifndef YY_PART
  97. typedef void (*yyaction)(char *yytext, int yyleng);
  98. typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk;
  99. YY_VARIABLE(char * ) yybuf= 0;
  100. YY_VARIABLE(int ) yybuflen= 0;
  101. YY_VARIABLE(int ) yypos= 0;
  102. YY_VARIABLE(int ) yylimit= 0;
  103. YY_VARIABLE(char * ) yytext= 0;
  104. YY_VARIABLE(int ) yytextlen= 0;
  105. YY_VARIABLE(int ) yybegin= 0;
  106. YY_VARIABLE(int ) yyend= 0;
  107. YY_VARIABLE(int ) yytextmax= 0;
  108. YY_VARIABLE(yythunk *) yythunks= 0;
  109. YY_VARIABLE(int ) yythunkslen= 0;
  110. YY_VARIABLE(int ) yythunkpos= 0;
  111. YY_VARIABLE(YYSTYPE ) yy;
  112. YY_VARIABLE(YYSTYPE *) yyval= 0;
  113. YY_VARIABLE(YYSTYPE *) yyvals= 0;
  114. YY_VARIABLE(int ) yyvalslen= 0;
  115. YY_LOCAL(int) yyrefill(void)
  116. {
  117. int yyn;
  118. while (yybuflen - yypos < 512)
  119. {
  120. yybuflen *= 2;
  121. yybuf= realloc(yybuf, yybuflen);
  122. }
  123. YY_INPUT((yybuf + yypos), yyn, (yybuflen - yypos));
  124. if (!yyn) return 0;
  125. yylimit += yyn;
  126. return 1;
  127. }
  128. YY_LOCAL(int) yymatchDot(void)
  129. {
  130. if (yypos >= yylimit && !yyrefill()) return 0;
  131. ++yypos;
  132. return 1;
  133. }
  134. YY_LOCAL(int) yymatchChar(int c)
  135. {
  136. if (yypos >= yylimit && !yyrefill()) return 0;
  137. if (yybuf[yypos] == c)
  138. {
  139. ++yypos;
  140. yyprintf((stderr, " ok yymatchChar(%c) @ %s\n", c, yybuf+yypos));
  141. return 1;
  142. }
  143. yyprintf((stderr, " fail yymatchChar(%c) @ %s\n", c, yybuf+yypos));
  144. return 0;
  145. }
  146. YY_LOCAL(int) yymatchString(char *s)
  147. {
  148. int yysav= yypos;
  149. while (*s)
  150. {
  151. if (yypos >= yylimit && !yyrefill()) return 0;
  152. if (yybuf[yypos] != *s)
  153. {
  154. yypos= yysav;
  155. return 0;
  156. }
  157. ++s;
  158. ++yypos;
  159. }
  160. return 1;
  161. }
  162. YY_LOCAL(int) yymatchClass(unsigned char *bits)
  163. {
  164. int c;
  165. if (yypos >= yylimit && !yyrefill()) return 0;
  166. c= yybuf[yypos];
  167. if (bits[c >> 3] & (1 << (c & 7)))
  168. {
  169. ++yypos;
  170. yyprintf((stderr, " ok yymatchClass @ %s\n", yybuf+yypos));
  171. return 1;
  172. }
  173. yyprintf((stderr, " fail yymatchClass @ %s\n", yybuf+yypos));
  174. return 0;
  175. }
  176. YY_LOCAL(void) yyDo(yyaction action, int begin, int end)
  177. {
  178. while (yythunkpos >= yythunkslen)
  179. {
  180. yythunkslen *= 2;
  181. yythunks= realloc(yythunks, sizeof(yythunk) * yythunkslen);
  182. }
  183. yythunks[yythunkpos].begin= begin;
  184. yythunks[yythunkpos].end= end;
  185. yythunks[yythunkpos].action= action;
  186. ++yythunkpos;
  187. }
  188. YY_LOCAL(int) yyText(int begin, int end)
  189. {
  190. int yyleng= end - begin;
  191. if (yyleng <= 0)
  192. yyleng= 0;
  193. else
  194. {
  195. while (yytextlen < (yyleng - 1))
  196. {
  197. yytextlen *= 2;
  198. yytext= realloc(yytext, yytextlen);
  199. }
  200. memcpy(yytext, yybuf + begin, yyleng);
  201. }
  202. yytext[yyleng]= '\0';
  203. return yyleng;
  204. }
  205. YY_LOCAL(void) yyDone(void)
  206. {
  207. int pos;
  208. for (pos= 0; pos < yythunkpos; ++pos)
  209. {
  210. yythunk *thunk= &yythunks[pos];
  211. int yyleng= thunk->end ? yyText(thunk->begin, thunk->end) : thunk->begin;
  212. yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, yytext));
  213. thunk->action(yytext, yyleng);
  214. }
  215. yythunkpos= 0;
  216. }
  217. YY_LOCAL(void) yyCommit()
  218. {
  219. if ((yylimit -= yypos))
  220. {
  221. memmove(yybuf, yybuf + yypos, yylimit);
  222. }
  223. yybegin -= yypos;
  224. yyend -= yypos;
  225. yypos= yythunkpos= 0;
  226. }
  227. YY_LOCAL(int) yyAccept(int tp0)
  228. {
  229. if (tp0)
  230. {
  231. fprintf(stderr, "accept denied at %d\n", tp0);
  232. return 0;
  233. }
  234. else
  235. {
  236. yyDone();
  237. yyCommit();
  238. }
  239. return 1;
  240. }
  241. YY_LOCAL(void) yyPush(char *text, int count) { if (text) { } yyval += count; }
  242. YY_LOCAL(void) yyPop(char *text, int count) { if (text) { } yyval -= count; }
  243. YY_LOCAL(void) yySet(char *text, int count) { if (text) { } yyval[count]= yy; }
  244. #endif /* YY_PART */
  245. #define YYACCEPT yyAccept(yythunkpos0)
  246. YY_RULE(int) yy_digit(); /* 22 */
  247. YY_RULE(int) yy_CLOSE(); /* 21 */
  248. YY_RULE(int) yy_OPEN(); /* 20 */
  249. YY_RULE(int) yy_SLASH(); /* 19 */
  250. YY_RULE(int) yy_STAR(); /* 18 */
  251. YY_RULE(int) yy_factor(); /* 17 */
  252. YY_RULE(int) yy_MINUS(); /* 16 */
  253. YY_RULE(int) yy_term(); /* 15 */
  254. YY_RULE(int) yy_PLUS(); /* 14 */
  255. YY_RULE(int) yy_COMMA(); /* 13 */
  256. YY_RULE(int) yy_string(); /* 12 */
  257. YY_RULE(int) yy_EQUAL(); /* 11 */
  258. YY_RULE(int) yy_var(); /* 10 */
  259. YY_RULE(int) yy_var_list(); /* 9 */
  260. YY_RULE(int) yy_relop(); /* 8 */
  261. YY_RULE(int) yy_expression(); /* 7 */
  262. YY_RULE(int) yy_expr_list(); /* 6 */
  263. YY_RULE(int) yy_number(); /* 5 */
  264. YY_RULE(int) yy_CR(); /* 4 */
  265. YY_RULE(int) yy_statement(); /* 3 */
  266. YY_RULE(int) yy__(); /* 2 */
  267. YY_RULE(int) yy_line(); /* 1 */
  268. YY_ACTION(void) yy_6_relop(char *yytext, int yyleng)
  269. { if(yytext) { } if (yyleng) { }
  270. yyprintf((stderr, "do yy_6_relop\n"));
  271. yy.binop= equalTo; ;
  272. }
  273. YY_ACTION(void) yy_5_relop(char *yytext, int yyleng)
  274. { if(yytext) { } if (yyleng) { }
  275. yyprintf((stderr, "do yy_5_relop\n"));
  276. yy.binop= greaterThan; ;
  277. }
  278. YY_ACTION(void) yy_4_relop(char *yytext, int yyleng)
  279. { if(yytext) { } if (yyleng) { }
  280. yyprintf((stderr, "do yy_4_relop\n"));
  281. yy.binop= greaterEqual; ;
  282. }
  283. YY_ACTION(void) yy_3_relop(char *yytext, int yyleng)
  284. { if(yytext) { } if (yyleng) { }
  285. yyprintf((stderr, "do yy_3_relop\n"));
  286. yy.binop= lessThan; ;
  287. }
  288. YY_ACTION(void) yy_2_relop(char *yytext, int yyleng)
  289. { if(yytext) { } if (yyleng) { }
  290. yyprintf((stderr, "do yy_2_relop\n"));
  291. yy.binop= notEqual; ;
  292. }
  293. YY_ACTION(void) yy_1_relop(char *yytext, int yyleng)
  294. { if(yytext) { } if (yyleng) { }
  295. yyprintf((stderr, "do yy_1_relop\n"));
  296. yy.binop= lessEqual; ;
  297. }
  298. YY_ACTION(void) yy_1_string(char *yytext, int yyleng)
  299. { if(yytext) { } if (yyleng) { }
  300. yyprintf((stderr, "do yy_1_string\n"));
  301. yy.string = yytext; ;
  302. }
  303. YY_ACTION(void) yy_1_number(char *yytext, int yyleng)
  304. { if(yytext) { } if (yyleng) { }
  305. yyprintf((stderr, "do yy_1_number\n"));
  306. yy.number = atoi(yytext); ;
  307. }
  308. YY_ACTION(void) yy_1_var(char *yytext, int yyleng)
  309. { if(yytext) { } if (yyleng) { }
  310. yyprintf((stderr, "do yy_1_var\n"));
  311. yy.number = yytext[0] - 'a' ;
  312. }
  313. YY_ACTION(void) yy_1_factor(char *yytext, int yyleng)
  314. { if(yytext) { } if (yyleng) { }
  315. #define n yyval[-1]
  316. #define v yyval[-2]
  317. yyprintf((stderr, "do yy_1_factor\n"));
  318. yy.number = variables[v.number] ;
  319. #undef n
  320. #undef v
  321. }
  322. YY_ACTION(void) yy_3_term(char *yytext, int yyleng)
  323. { if(yytext) { } if (yyleng) { }
  324. #define r yyval[-1]
  325. #define l yyval[-2]
  326. yyprintf((stderr, "do yy_3_term\n"));
  327. yy.number = l.number ;
  328. #undef r
  329. #undef l
  330. }
  331. YY_ACTION(void) yy_2_term(char *yytext, int yyleng)
  332. { if(yytext) { } if (yyleng) { }
  333. #define r yyval[-1]
  334. #define l yyval[-2]
  335. yyprintf((stderr, "do yy_2_term\n"));
  336. l.number /= r.number ;
  337. #undef r
  338. #undef l
  339. }
  340. YY_ACTION(void) yy_1_term(char *yytext, int yyleng)
  341. { if(yytext) { } if (yyleng) { }
  342. #define r yyval[-1]
  343. #define l yyval[-2]
  344. yyprintf((stderr, "do yy_1_term\n"));
  345. l.number *= r.number ;
  346. #undef r
  347. #undef l
  348. }
  349. YY_ACTION(void) yy_4_expression(char *yytext, int yyleng)
  350. { if(yytext) { } if (yyleng) { }
  351. #define r yyval[-1]
  352. #define l yyval[-2]
  353. yyprintf((stderr, "do yy_4_expression\n"));
  354. yy.number = l.number ;
  355. #undef r
  356. #undef l
  357. }
  358. YY_ACTION(void) yy_3_expression(char *yytext, int yyleng)
  359. { if(yytext) { } if (yyleng) { }
  360. #define r yyval[-1]
  361. #define l yyval[-2]
  362. yyprintf((stderr, "do yy_3_expression\n"));
  363. l.number -= r.number ;
  364. #undef r
  365. #undef l
  366. }
  367. YY_ACTION(void) yy_2_expression(char *yytext, int yyleng)
  368. { if(yytext) { } if (yyleng) { }
  369. #define r yyval[-1]
  370. #define l yyval[-2]
  371. yyprintf((stderr, "do yy_2_expression\n"));
  372. l.number += r.number ;
  373. #undef r
  374. #undef l
  375. }
  376. YY_ACTION(void) yy_1_expression(char *yytext, int yyleng)
  377. { if(yytext) { } if (yyleng) { }
  378. #define r yyval[-1]
  379. #define l yyval[-2]
  380. yyprintf((stderr, "do yy_1_expression\n"));
  381. l.number = -l.number ;
  382. #undef r
  383. #undef l
  384. }
  385. YY_ACTION(void) yy_2_var_list(char *yytext, int yyleng)
  386. { if(yytext) { } if (yyleng) { }
  387. #define v yyval[-1]
  388. yyprintf((stderr, "do yy_2_var_list\n"));
  389. variables[v.number]= input(); ;
  390. #undef v
  391. }
  392. YY_ACTION(void) yy_1_var_list(char *yytext, int yyleng)
  393. { if(yytext) { } if (yyleng) { }
  394. #define v yyval[-1]
  395. yyprintf((stderr, "do yy_1_var_list\n"));
  396. variables[v.number]= input(); ;
  397. #undef v
  398. }
  399. YY_ACTION(void) yy_5_expr_list(char *yytext, int yyleng)
  400. { if(yytext) { } if (yyleng) { }
  401. #define e yyval[-1]
  402. yyprintf((stderr, "do yy_5_expr_list\n"));
  403. printf("\n"); ;
  404. #undef e
  405. }
  406. YY_ACTION(void) yy_4_expr_list(char *yytext, int yyleng)
  407. { if(yytext) { } if (yyleng) { }
  408. #define e yyval[-1]
  409. yyprintf((stderr, "do yy_4_expr_list\n"));
  410. printf("%d", e.number); ;
  411. #undef e
  412. }
  413. YY_ACTION(void) yy_3_expr_list(char *yytext, int yyleng)
  414. { if(yytext) { } if (yyleng) { }
  415. #define e yyval[-1]
  416. yyprintf((stderr, "do yy_3_expr_list\n"));
  417. printf("%s", e.string); ;
  418. #undef e
  419. }
  420. YY_ACTION(void) yy_2_expr_list(char *yytext, int yyleng)
  421. { if(yytext) { } if (yyleng) { }
  422. #define e yyval[-1]
  423. yyprintf((stderr, "do yy_2_expr_list\n"));
  424. printf("%d", e.number); ;
  425. #undef e
  426. }
  427. YY_ACTION(void) yy_1_expr_list(char *yytext, int yyleng)
  428. { if(yytext) { } if (yyleng) { }
  429. #define e yyval[-1]
  430. yyprintf((stderr, "do yy_1_expr_list\n"));
  431. printf("%s", e.string); ;
  432. #undef e
  433. }
  434. YY_ACTION(void) yy_16_statement(char *yytext, int yyleng)
  435. { if(yytext) { } if (yyleng) { }
  436. #define s yyval[-1]
  437. #define v yyval[-2]
  438. #define e yyval[-3]
  439. #define e2 yyval[-4]
  440. #define r yyval[-5]
  441. #define e1 yyval[-6]
  442. yyprintf((stderr, "do yy_16_statement\n"));
  443. fprintf(stderr, "%s", help); ;
  444. #undef s
  445. #undef v
  446. #undef e
  447. #undef e2
  448. #undef r
  449. #undef e1
  450. }
  451. YY_ACTION(void) yy_15_statement(char *yytext, int yyleng)
  452. { if(yytext) { } if (yyleng) { }
  453. #define s yyval[-1]
  454. #define v yyval[-2]
  455. #define e yyval[-3]
  456. #define e2 yyval[-4]
  457. #define r yyval[-5]
  458. #define e1 yyval[-6]
  459. yyprintf((stderr, "do yy_15_statement\n"));
  460. system("ls *.bas"); ;
  461. #undef s
  462. #undef v
  463. #undef e
  464. #undef e2
  465. #undef r
  466. #undef e1
  467. }
  468. YY_ACTION(void) yy_14_statement(char *yytext, int yyleng)
  469. { if(yytext) { } if (yyleng) { }
  470. #define s yyval[-1]
  471. #define v yyval[-2]
  472. #define e yyval[-3]
  473. #define e2 yyval[-4]
  474. #define r yyval[-5]
  475. #define e1 yyval[-6]
  476. yyprintf((stderr, "do yy_14_statement\n"));
  477. type(s.string); ;
  478. #undef s
  479. #undef v
  480. #undef e
  481. #undef e2
  482. #undef r
  483. #undef e1
  484. }
  485. YY_ACTION(void) yy_13_statement(char *yytext, int yyleng)
  486. { if(yytext) { } if (yyleng) { }
  487. #define s yyval[-1]
  488. #define v yyval[-2]
  489. #define e yyval[-3]
  490. #define e2 yyval[-4]
  491. #define r yyval[-5]
  492. #define e1 yyval[-6]
  493. yyprintf((stderr, "do yy_13_statement\n"));
  494. load(s.string); ;
  495. #undef s
  496. #undef v
  497. #undef e
  498. #undef e2
  499. #undef r
  500. #undef e1
  501. }
  502. YY_ACTION(void) yy_12_statement(char *yytext, int yyleng)
  503. { if(yytext) { } if (yyleng) { }
  504. #define s yyval[-1]
  505. #define v yyval[-2]
  506. #define e yyval[-3]
  507. #define e2 yyval[-4]
  508. #define r yyval[-5]
  509. #define e1 yyval[-6]
  510. yyprintf((stderr, "do yy_12_statement\n"));
  511. save(s.string); ;
  512. #undef s
  513. #undef v
  514. #undef e
  515. #undef e2
  516. #undef r
  517. #undef e1
  518. }
  519. YY_ACTION(void) yy_11_statement(char *yytext, int yyleng)
  520. { if(yytext) { } if (yyleng) { }
  521. #define s yyval[-1]
  522. #define v yyval[-2]
  523. #define e yyval[-3]
  524. #define e2 yyval[-4]
  525. #define r yyval[-5]
  526. #define e1 yyval[-6]
  527. yyprintf((stderr, "do yy_11_statement\n"));
  528. exit(0); ;
  529. #undef s
  530. #undef v
  531. #undef e
  532. #undef e2
  533. #undef r
  534. #undef e1
  535. }
  536. YY_ACTION(void) yy_10_statement(char *yytext, int yyleng)
  537. { if(yytext) { } if (yyleng) { }
  538. #define s yyval[-1]
  539. #define v yyval[-2]
  540. #define e yyval[-3]
  541. #define e2 yyval[-4]
  542. #define r yyval[-5]
  543. #define e1 yyval[-6]
  544. yyprintf((stderr, "do yy_10_statement\n"));
  545. pc= -1; if (batch) exit(0); ;
  546. #undef s
  547. #undef v
  548. #undef e
  549. #undef e2
  550. #undef r
  551. #undef e1
  552. }
  553. YY_ACTION(void) yy_9_statement(char *yytext, int yyleng)
  554. { if(yytext) { } if (yyleng) { }
  555. #define s yyval[-1]
  556. #define v yyval[-2]
  557. #define e yyval[-3]
  558. #define e2 yyval[-4]
  559. #define r yyval[-5]
  560. #define e1 yyval[-6]
  561. yyprintf((stderr, "do yy_9_statement\n"));
  562. pc= 0; ;
  563. #undef s
  564. #undef v
  565. #undef e
  566. #undef e2
  567. #undef r
  568. #undef e1
  569. }
  570. YY_ACTION(void) yy_8_statement(char *yytext, int yyleng)
  571. { if(yytext) { } if (yyleng) { }
  572. #define s yyval[-1]
  573. #define v yyval[-2]
  574. #define e yyval[-3]
  575. #define e2 yyval[-4]
  576. #define r yyval[-5]
  577. #define e1 yyval[-6]
  578. yyprintf((stderr, "do yy_8_statement\n"));
  579. load(s.string); pc= 0; ;
  580. #undef s
  581. #undef v
  582. #undef e
  583. #undef e2
  584. #undef r
  585. #undef e1
  586. }
  587. YY_ACTION(void) yy_7_statement(char *yytext, int yyleng)
  588. { if(yytext) { } if (yyleng) { }
  589. #define s yyval[-1]
  590. #define v yyval[-2]
  591. #define e yyval[-3]
  592. #define e2 yyval[-4]
  593. #define r yyval[-5]
  594. #define e1 yyval[-6]
  595. yyprintf((stderr, "do yy_7_statement\n"));
  596. int i; for (i= 0; i < numLines; ++i) printf("%5d %s", lines[i].number, lines[i].text); ;
  597. #undef s
  598. #undef v
  599. #undef e
  600. #undef e2
  601. #undef r
  602. #undef e1
  603. }
  604. YY_ACTION(void) yy_6_statement(char *yytext, int yyleng)
  605. { if(yytext) { } if (yyleng) { }
  606. #define s yyval[-1]
  607. #define v yyval[-2]
  608. #define e yyval[-3]
  609. #define e2 yyval[-4]
  610. #define r yyval[-5]
  611. #define e1 yyval[-6]
  612. yyprintf((stderr, "do yy_6_statement\n"));
  613. while (numLines) accept(lines->number, "\n"); ;
  614. #undef s
  615. #undef v
  616. #undef e
  617. #undef e2
  618. #undef r
  619. #undef e1
  620. }
  621. YY_ACTION(void) yy_5_statement(char *yytext, int yyleng)
  622. { if(yytext) { } if (yyleng) { }
  623. #define s yyval[-1]
  624. #define v yyval[-2]
  625. #define e yyval[-3]
  626. #define e2 yyval[-4]
  627. #define r yyval[-5]
  628. #define e1 yyval[-6]
  629. yyprintf((stderr, "do yy_5_statement\n"));
  630. epc= pc; if ((pc= sp ? stack[--sp] : -1) < 0) error("no gosub"); ;
  631. #undef s
  632. #undef v
  633. #undef e
  634. #undef e2
  635. #undef r
  636. #undef e1
  637. }
  638. YY_ACTION(void) yy_4_statement(char *yytext, int yyleng)
  639. { if(yytext) { } if (yyleng) { }
  640. #define s yyval[-1]
  641. #define v yyval[-2]
  642. #define e yyval[-3]
  643. #define e2 yyval[-4]
  644. #define r yyval[-5]
  645. #define e1 yyval[-6]
  646. yyprintf((stderr, "do yy_4_statement\n"));
  647. epc= pc; if (sp < 1024) stack[sp++]= pc, pc= findLine(e.number, 0); else error("too many gosubs");
  648. if (pc < 0) error("no such line"); ;
  649. #undef s
  650. #undef v
  651. #undef e
  652. #undef e2
  653. #undef r
  654. #undef e1
  655. }
  656. YY_ACTION(void) yy_3_statement(char *yytext, int yyleng)
  657. { if(yytext) { } if (yyleng) { }
  658. #define s yyval[-1]
  659. #define v yyval[-2]
  660. #define e yyval[-3]
  661. #define e2 yyval[-4]
  662. #define r yyval[-5]
  663. #define e1 yyval[-6]
  664. yyprintf((stderr, "do yy_3_statement\n"));
  665. variables[v.number]= e.number; ;
  666. #undef s
  667. #undef v
  668. #undef e
  669. #undef e2
  670. #undef r
  671. #undef e1
  672. }
  673. YY_ACTION(void) yy_2_statement(char *yytext, int yyleng)
  674. { if(yytext) { } if (yyleng) { }
  675. #define s yyval[-1]
  676. #define v yyval[-2]
  677. #define e yyval[-3]
  678. #define e2 yyval[-4]
  679. #define r yyval[-5]
  680. #define e1 yyval[-6]
  681. yyprintf((stderr, "do yy_2_statement\n"));
  682. epc= pc; if ((pc= findLine(e.number, 0)) < 0) error("no such line"); ;
  683. #undef s
  684. #undef v
  685. #undef e
  686. #undef e2
  687. #undef r
  688. #undef e1
  689. }
  690. YY_ACTION(void) yy_1_statement(char *yytext, int yyleng)
  691. { if(yytext) { } if (yyleng) { }
  692. #define s yyval[-1]
  693. #define v yyval[-2]
  694. #define e yyval[-3]
  695. #define e2 yyval[-4]
  696. #define r yyval[-5]
  697. #define e1 yyval[-6]
  698. yyprintf((stderr, "do yy_1_statement\n"));
  699. if (!r.binop(e1.number, e2.number)) yythunkpos= 0; ;
  700. #undef s
  701. #undef v
  702. #undef e
  703. #undef e2
  704. #undef r
  705. #undef e1
  706. }
  707. YY_ACTION(void) yy_3_line(char *yytext, int yyleng)
  708. { if(yytext) { } if (yyleng) { }
  709. #define n yyval[-1]
  710. #define s yyval[-2]
  711. yyprintf((stderr, "do yy_3_line\n"));
  712. exit(0); ;
  713. #undef n
  714. #undef s
  715. }
  716. YY_ACTION(void) yy_2_line(char *yytext, int yyleng)
  717. { if(yytext) { } if (yyleng) { }
  718. #define n yyval[-1]
  719. #define s yyval[-2]
  720. yyprintf((stderr, "do yy_2_line\n"));
  721. epc= pc; error("syntax error"); ;
  722. #undef n
  723. #undef s
  724. }
  725. YY_ACTION(void) yy_1_line(char *yytext, int yyleng)
  726. { if(yytext) { } if (yyleng) { }
  727. #define n yyval[-1]
  728. #define s yyval[-2]
  729. yyprintf((stderr, "do yy_1_line\n"));
  730. accept(n.number, yytext); ;
  731. #undef n
  732. #undef s
  733. }
  734. YY_RULE(int) yy_digit()
  735. { int yypos0= yypos, yythunkpos0= yythunkpos;
  736. yyprintf((stderr, "%s\n", "digit")); if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l1;
  737. yyprintf((stderr, " ok %s @ %s\n", "digit", yybuf+yypos));
  738. return 1;
  739. l1:; yypos= yypos0; yythunkpos= yythunkpos0;
  740. yyprintf((stderr, " fail %s @ %s\n", "digit", yybuf+yypos));
  741. return 0;
  742. }
  743. YY_RULE(int) yy_CLOSE()
  744. { int yypos0= yypos, yythunkpos0= yythunkpos;
  745. yyprintf((stderr, "%s\n", "CLOSE")); if (!yymatchChar(')')) goto l2; if (!yy__()) goto l2;
  746. yyprintf((stderr, " ok %s @ %s\n", "CLOSE", yybuf+yypos));
  747. return 1;
  748. l2:; yypos= yypos0; yythunkpos= yythunkpos0;
  749. yyprintf((stderr, " fail %s @ %s\n", "CLOSE", yybuf+yypos));
  750. return 0;
  751. }
  752. YY_RULE(int) yy_OPEN()
  753. { int yypos0= yypos, yythunkpos0= yythunkpos;
  754. yyprintf((stderr, "%s\n", "OPEN")); if (!yymatchChar('(')) goto l3; if (!yy__()) goto l3;
  755. yyprintf((stderr, " ok %s @ %s\n", "OPEN", yybuf+yypos));
  756. return 1;
  757. l3:; yypos= yypos0; yythunkpos= yythunkpos0;
  758. yyprintf((stderr, " fail %s @ %s\n", "OPEN", yybuf+yypos));
  759. return 0;
  760. }
  761. YY_RULE(int) yy_SLASH()
  762. { int yypos0= yypos, yythunkpos0= yythunkpos;
  763. yyprintf((stderr, "%s\n", "SLASH")); if (!yymatchChar('/')) goto l4; if (!yy__()) goto l4;
  764. yyprintf((stderr, " ok %s @ %s\n", "SLASH", yybuf+yypos));
  765. return 1;
  766. l4:; yypos= yypos0; yythunkpos= yythunkpos0;
  767. yyprintf((stderr, " fail %s @ %s\n", "SLASH", yybuf+yypos));
  768. return 0;
  769. }
  770. YY_RULE(int) yy_STAR()
  771. { int yypos0= yypos, yythunkpos0= yythunkpos;
  772. yyprintf((stderr, "%s\n", "STAR")); if (!yymatchChar('*')) goto l5; if (!yy__()) goto l5;
  773. yyprintf((stderr, " ok %s @ %s\n", "STAR", yybuf+yypos));
  774. return 1;
  775. l5:; yypos= yypos0; yythunkpos= yythunkpos0;
  776. yyprintf((stderr, " fail %s @ %s\n", "STAR", yybuf+yypos));
  777. return 0;
  778. }
  779. YY_RULE(int) yy_factor()
  780. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  781. yyprintf((stderr, "%s\n", "factor"));
  782. { int yypos7= yypos, yythunkpos7= yythunkpos; if (!yy_var()) goto l8; yyDo(yySet, -2, 0); yyDo(yy_1_factor, yybegin, yyend); goto l7;
  783. l8:; yypos= yypos7; yythunkpos= yythunkpos7; if (!yy_number()) goto l9; yyDo(yySet, -1, 0); goto l7;
  784. l9:; yypos= yypos7; yythunkpos= yythunkpos7; if (!yy_OPEN()) goto l6; if (!yy_expression()) goto l6; if (!yy_CLOSE()) goto l6;
  785. }
  786. l7:;
  787. yyprintf((stderr, " ok %s @ %s\n", "factor", yybuf+yypos)); yyDo(yyPop, 2, 0);
  788. return 1;
  789. l6:; yypos= yypos0; yythunkpos= yythunkpos0;
  790. yyprintf((stderr, " fail %s @ %s\n", "factor", yybuf+yypos));
  791. return 0;
  792. }
  793. YY_RULE(int) yy_MINUS()
  794. { int yypos0= yypos, yythunkpos0= yythunkpos;
  795. yyprintf((stderr, "%s\n", "MINUS")); if (!yymatchChar('-')) goto l10; if (!yy__()) goto l10;
  796. yyprintf((stderr, " ok %s @ %s\n", "MINUS", yybuf+yypos));
  797. return 1;
  798. l10:; yypos= yypos0; yythunkpos= yythunkpos0;
  799. yyprintf((stderr, " fail %s @ %s\n", "MINUS", yybuf+yypos));
  800. return 0;
  801. }
  802. YY_RULE(int) yy_term()
  803. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  804. yyprintf((stderr, "%s\n", "term")); if (!yy_factor()) goto l11; yyDo(yySet, -2, 0);
  805. l12:;
  806. { int yypos13= yypos, yythunkpos13= yythunkpos;
  807. { int yypos14= yypos, yythunkpos14= yythunkpos; if (!yy_STAR()) goto l15; if (!yy_factor()) goto l15; yyDo(yySet, -1, 0); yyDo(yy_1_term, yybegin, yyend); goto l14;
  808. l15:; yypos= yypos14; yythunkpos= yythunkpos14; if (!yy_SLASH()) goto l13; if (!yy_factor()) goto l13; yyDo(yySet, -1, 0); yyDo(yy_2_term, yybegin, yyend);
  809. }
  810. l14:; goto l12;
  811. l13:; yypos= yypos13; yythunkpos= yythunkpos13;
  812. } yyDo(yy_3_term, yybegin, yyend);
  813. yyprintf((stderr, " ok %s @ %s\n", "term", yybuf+yypos)); yyDo(yyPop, 2, 0);
  814. return 1;
  815. l11:; yypos= yypos0; yythunkpos= yythunkpos0;
  816. yyprintf((stderr, " fail %s @ %s\n", "term", yybuf+yypos));
  817. return 0;
  818. }
  819. YY_RULE(int) yy_PLUS()
  820. { int yypos0= yypos, yythunkpos0= yythunkpos;
  821. yyprintf((stderr, "%s\n", "PLUS")); if (!yymatchChar('+')) goto l16; if (!yy__()) goto l16;
  822. yyprintf((stderr, " ok %s @ %s\n", "PLUS", yybuf+yypos));
  823. return 1;
  824. l16:; yypos= yypos0; yythunkpos= yythunkpos0;
  825. yyprintf((stderr, " fail %s @ %s\n", "PLUS", yybuf+yypos));
  826. return 0;
  827. }
  828. YY_RULE(int) yy_COMMA()
  829. { int yypos0= yypos, yythunkpos0= yythunkpos;
  830. yyprintf((stderr, "%s\n", "COMMA")); if (!yymatchChar(',')) goto l17; if (!yy__()) goto l17;
  831. yyprintf((stderr, " ok %s @ %s\n", "COMMA", yybuf+yypos));
  832. return 1;
  833. l17:; yypos= yypos0; yythunkpos= yythunkpos0;
  834. yyprintf((stderr, " fail %s @ %s\n", "COMMA", yybuf+yypos));
  835. return 0;
  836. }
  837. YY_RULE(int) yy_string()
  838. { int yypos0= yypos, yythunkpos0= yythunkpos;
  839. yyprintf((stderr, "%s\n", "string")); if (!yymatchChar('"')) goto l18; yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l18;
  840. l19:;
  841. { int yypos20= yypos, yythunkpos20= yythunkpos; if (!yymatchClass((unsigned char *)"\377\377\377\377\373\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377")) goto l20; goto l19;
  842. l20:; yypos= yypos20; yythunkpos= yythunkpos20;
  843. } yyText(yybegin, yyend); if (!(YY_END)) goto l18; if (!yymatchChar('"')) goto l18; if (!yy__()) goto l18; yyDo(yy_1_string, yybegin, yyend);
  844. yyprintf((stderr, " ok %s @ %s\n", "string", yybuf+yypos));
  845. return 1;
  846. l18:; yypos= yypos0; yythunkpos= yythunkpos0;
  847. yyprintf((stderr, " fail %s @ %s\n", "string", yybuf+yypos));
  848. return 0;
  849. }
  850. YY_RULE(int) yy_EQUAL()
  851. { int yypos0= yypos, yythunkpos0= yythunkpos;
  852. yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar('=')) goto l21; if (!yy__()) goto l21;
  853. yyprintf((stderr, " ok %s @ %s\n", "EQUAL", yybuf+yypos));
  854. return 1;
  855. l21:; yypos= yypos0; yythunkpos= yythunkpos0;
  856. yyprintf((stderr, " fail %s @ %s\n", "EQUAL", yybuf+yypos));
  857. return 0;
  858. }
  859. YY_RULE(int) yy_var()
  860. { int yypos0= yypos, yythunkpos0= yythunkpos;
  861. yyprintf((stderr, "%s\n", "var")); yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l22; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\000\000\000\000\000\000\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l22; yyText(yybegin, yyend); if (!(YY_END)) goto l22; if (!yy__()) goto l22; yyDo(yy_1_var, yybegin, yyend);
  862. yyprintf((stderr, " ok %s @ %s\n", "var", yybuf+yypos));
  863. return 1;
  864. l22:; yypos= yypos0; yythunkpos= yythunkpos0;
  865. yyprintf((stderr, " fail %s @ %s\n", "var", yybuf+yypos));
  866. return 0;
  867. }
  868. YY_RULE(int) yy_var_list()
  869. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 1, 0);
  870. yyprintf((stderr, "%s\n", "var_list")); if (!yy_var()) goto l23; yyDo(yySet, -1, 0); yyDo(yy_1_var_list, yybegin, yyend);
  871. l24:;
  872. { int yypos25= yypos, yythunkpos25= yythunkpos; if (!yy_COMMA()) goto l25; if (!yy_var()) goto l25; yyDo(yySet, -1, 0); yyDo(yy_2_var_list, yybegin, yyend); goto l24;
  873. l25:; yypos= yypos25; yythunkpos= yythunkpos25;
  874. }
  875. yyprintf((stderr, " ok %s @ %s\n", "var_list", yybuf+yypos)); yyDo(yyPop, 1, 0);
  876. return 1;
  877. l23:; yypos= yypos0; yythunkpos= yythunkpos0;
  878. yyprintf((stderr, " fail %s @ %s\n", "var_list", yybuf+yypos));
  879. return 0;
  880. }
  881. YY_RULE(int) yy_relop()
  882. { int yypos0= yypos, yythunkpos0= yythunkpos;
  883. yyprintf((stderr, "%s\n", "relop"));
  884. { int yypos27= yypos, yythunkpos27= yythunkpos; if (!yymatchString("<=")) goto l28; if (!yy__()) goto l28; yyDo(yy_1_relop, yybegin, yyend); goto l27;
  885. l28:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchString("<>")) goto l29; if (!yy__()) goto l29; yyDo(yy_2_relop, yybegin, yyend); goto l27;
  886. l29:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchChar('<')) goto l30; if (!yy__()) goto l30; yyDo(yy_3_relop, yybegin, yyend); goto l27;
  887. l30:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchString(">=")) goto l31; if (!yy__()) goto l31; yyDo(yy_4_relop, yybegin, yyend); goto l27;
  888. l31:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchChar('>')) goto l32; if (!yy__()) goto l32; yyDo(yy_5_relop, yybegin, yyend); goto l27;
  889. l32:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchChar('=')) goto l26; if (!yy__()) goto l26; yyDo(yy_6_relop, yybegin, yyend);
  890. }
  891. l27:;
  892. yyprintf((stderr, " ok %s @ %s\n", "relop", yybuf+yypos));
  893. return 1;
  894. l26:; yypos= yypos0; yythunkpos= yythunkpos0;
  895. yyprintf((stderr, " fail %s @ %s\n", "relop", yybuf+yypos));
  896. return 0;
  897. }
  898. YY_RULE(int) yy_expression()
  899. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  900. yyprintf((stderr, "%s\n", "expression"));
  901. { int yypos34= yypos, yythunkpos34= yythunkpos;
  902. { int yypos36= yypos, yythunkpos36= yythunkpos; if (!yy_PLUS()) goto l36; goto l37;
  903. l36:; yypos= yypos36; yythunkpos= yythunkpos36;
  904. }
  905. l37:; if (!yy_term()) goto l35; yyDo(yySet, -2, 0); goto l34;
  906. l35:; yypos= yypos34; yythunkpos= yythunkpos34; if (!yy_MINUS()) goto l33; if (!yy_term()) goto l33; yyDo(yySet, -2, 0); yyDo(yy_1_expression, yybegin, yyend);
  907. }
  908. l34:;
  909. l38:;
  910. { int yypos39= yypos, yythunkpos39= yythunkpos;
  911. { int yypos40= yypos, yythunkpos40= yythunkpos; if (!yy_PLUS()) goto l41; if (!yy_term()) goto l41; yyDo(yySet, -1, 0); yyDo(yy_2_expression, yybegin, yyend); goto l40;
  912. l41:; yypos= yypos40; yythunkpos= yythunkpos40; if (!yy_MINUS()) goto l39; if (!yy_term()) goto l39; yyDo(yySet, -1, 0); yyDo(yy_3_expression, yybegin, yyend);
  913. }
  914. l40:; goto l38;
  915. l39:; yypos= yypos39; yythunkpos= yythunkpos39;
  916. } yyDo(yy_4_expression, yybegin, yyend);
  917. yyprintf((stderr, " ok %s @ %s\n", "expression", yybuf+yypos)); yyDo(yyPop, 2, 0);
  918. return 1;
  919. l33:; yypos= yypos0; yythunkpos= yythunkpos0;
  920. yyprintf((stderr, " fail %s @ %s\n", "expression", yybuf+yypos));
  921. return 0;
  922. }
  923. YY_RULE(int) yy_expr_list()
  924. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 1, 0);
  925. yyprintf((stderr, "%s\n", "expr_list"));
  926. { int yypos43= yypos, yythunkpos43= yythunkpos;
  927. { int yypos45= yypos, yythunkpos45= yythunkpos; if (!yy_string()) goto l46; yyDo(yySet, -1, 0); yyDo(yy_1_expr_list, yybegin, yyend); goto l45;
  928. l46:; yypos= yypos45; yythunkpos= yythunkpos45; if (!yy_expression()) goto l43; yyDo(yySet, -1, 0); yyDo(yy_2_expr_list, yybegin, yyend);
  929. }
  930. l45:; goto l44;
  931. l43:; yypos= yypos43; yythunkpos= yythunkpos43;
  932. }
  933. l44:;
  934. l47:;
  935. { int yypos48= yypos, yythunkpos48= yythunkpos; if (!yy_COMMA()) goto l48;
  936. { int yypos49= yypos, yythunkpos49= yythunkpos; if (!yy_string()) goto l50; yyDo(yySet, -1, 0); yyDo(yy_3_expr_list, yybegin, yyend); goto l49;
  937. l50:; yypos= yypos49; yythunkpos= yythunkpos49; if (!yy_expression()) goto l48; yyDo(yySet, -1, 0); yyDo(yy_4_expr_list, yybegin, yyend);
  938. }
  939. l49:; goto l47;
  940. l48:; yypos= yypos48; yythunkpos= yythunkpos48;
  941. }
  942. { int yypos51= yypos, yythunkpos51= yythunkpos; if (!yy_COMMA()) goto l52; goto l51;
  943. l52:; yypos= yypos51; yythunkpos= yythunkpos51;
  944. { int yypos53= yypos, yythunkpos53= yythunkpos; if (!yy_COMMA()) goto l53; goto l42;
  945. l53:; yypos= yypos53; yythunkpos= yythunkpos53;
  946. } yyDo(yy_5_expr_list, yybegin, yyend);
  947. }
  948. l51:;
  949. yyprintf((stderr, " ok %s @ %s\n", "expr_list", yybuf+yypos)); yyDo(yyPop, 1, 0);
  950. return 1;
  951. l42:; yypos= yypos0; yythunkpos= yythunkpos0;
  952. yyprintf((stderr, " fail %s @ %s\n", "expr_list", yybuf+yypos));
  953. return 0;
  954. }
  955. YY_RULE(int) yy_number()
  956. { int yypos0= yypos, yythunkpos0= yythunkpos;
  957. yyprintf((stderr, "%s\n", "number")); yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l54; if (!yy_digit()) goto l54;
  958. l55:;
  959. { int yypos56= yypos, yythunkpos56= yythunkpos; if (!yy_digit()) goto l56; goto l55;
  960. l56:; yypos= yypos56; yythunkpos= yythunkpos56;
  961. } yyText(yybegin, yyend); if (!(YY_END)) goto l54; if (!yy__()) goto l54; yyDo(yy_1_number, yybegin, yyend);
  962. yyprintf((stderr, " ok %s @ %s\n", "number", yybuf+yypos));
  963. return 1;
  964. l54:; yypos= yypos0; yythunkpos= yythunkpos0;
  965. yyprintf((stderr, " fail %s @ %s\n", "number", yybuf+yypos));
  966. return 0;
  967. }
  968. YY_RULE(int) yy_CR()
  969. { int yypos0= yypos, yythunkpos0= yythunkpos;
  970. yyprintf((stderr, "%s\n", "CR"));
  971. { int yypos58= yypos, yythunkpos58= yythunkpos; if (!yymatchChar('\n')) goto l59; goto l58;
  972. l59:; yypos= yypos58; yythunkpos= yythunkpos58; if (!yymatchChar('\r')) goto l60; goto l58;
  973. l60:; yypos= yypos58; yythunkpos= yythunkpos58; if (!yymatchString("\r\n")) goto l57;
  974. }
  975. l58:;
  976. yyprintf((stderr, " ok %s @ %s\n", "CR", yybuf+yypos));
  977. return 1;
  978. l57:; yypos= yypos0; yythunkpos= yythunkpos0;
  979. yyprintf((stderr, " fail %s @ %s\n", "CR", yybuf+yypos));
  980. return 0;
  981. }
  982. YY_RULE(int) yy_statement()
  983. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 6, 0);
  984. yyprintf((stderr, "%s\n", "statement"));
  985. { int yypos62= yypos, yythunkpos62= yythunkpos; if (!yymatchString("print")) goto l63; if (!yy__()) goto l63; if (!yy_expr_list()) goto l63; goto l62;
  986. l63:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("if")) goto l64; if (!yy__()) goto l64; if (!yy_expression()) goto l64; yyDo(yySet, -6, 0); if (!yy_relop()) goto l64; yyDo(yySet, -5, 0); if (!yy_expression()) goto l64; yyDo(yySet, -4, 0); yyDo(yy_1_statement, yybegin, yyend); if (!yymatchString("then")) goto l64; if (!yy__()) goto l64; if (!yy_statement()) goto l64; goto l62;
  987. l64:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("goto")) goto l65; if (!yy__()) goto l65; if (!yy_expression()) goto l65; yyDo(yySet, -3, 0); yyDo(yy_2_statement, yybegin, yyend); goto l62;
  988. l65:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("input")) goto l66; if (!yy__()) goto l66; if (!yy_var_list()) goto l66; goto l62;
  989. l66:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("let")) goto l67; if (!yy__()) goto l67; if (!yy_var()) goto l67; yyDo(yySet, -2, 0); if (!yy_EQUAL()) goto l67; if (!yy_expression()) goto l67; yyDo(yySet, -3, 0); yyDo(yy_3_statement, yybegin, yyend); goto l62;
  990. l67:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("gosub")) goto l68; if (!yy__()) goto l68; if (!yy_expression()) goto l68; yyDo(yySet, -3, 0); yyDo(yy_4_statement, yybegin, yyend); goto l62;
  991. l68:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("return")) goto l69; if (!yy__()) goto l69; yyDo(yy_5_statement, yybegin, yyend); goto l62;
  992. l69:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("clear")) goto l70; if (!yy__()) goto l70; yyDo(yy_6_statement, yybegin, yyend); goto l62;
  993. l70:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("list")) goto l71; if (!yy__()) goto l71; yyDo(yy_7_statement, yybegin, yyend); goto l62;
  994. l71:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("run")) goto l72; if (!yy__()) goto l72; if (!yy_string()) goto l72; yyDo(yySet, -1, 0); yyDo(yy_8_statement, yybegin, yyend); goto l62;
  995. l72:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("run")) goto l73; if (!yy__()) goto l73; yyDo(yy_9_statement, yybegin, yyend); goto l62;
  996. l73:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("end")) goto l74; if (!yy__()) goto l74; yyDo(yy_10_statement, yybegin, yyend); goto l62;
  997. l74:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("rem")) goto l75; if (!yy__()) goto l75;
  998. l76:;
  999. { int yypos77= yypos, yythunkpos77= yythunkpos;
  1000. { int yypos78= yypos, yythunkpos78= yythunkpos; if (!yy_CR()) goto l78; goto l77;
  1001. l78:; yypos= yypos78; yythunkpos= yythunkpos78;
  1002. } if (!yymatchDot()) goto l77; goto l76;
  1003. l77:; yypos= yypos77; yythunkpos= yythunkpos77;
  1004. } goto l62;
  1005. l75:; yypos= yypos62; yythunkpos= yythunkpos62;
  1006. { int yypos80= yypos, yythunkpos80= yythunkpos; if (!yymatchString("bye")) goto l81; goto l80;
  1007. l81:; yypos= yypos80; yythunkpos= yythunkpos80; if (!yymatchString("quit")) goto l82; goto l80;
  1008. l82:; yypos= yypos80; yythunkpos= yythunkpos80; if (!yymatchString("exit")) goto l79;
  1009. }
  1010. l80:; if (!yy__()) goto l79; yyDo(yy_11_statement, yybegin, yyend); goto l62;
  1011. l79:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("save")) goto l83; if (!yy__()) goto l83; if (!yy_string()) goto l83; yyDo(yySet, -1, 0); yyDo(yy_12_statement, yybegin, yyend); goto l62;
  1012. l83:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("load")) goto l84; if (!yy__()) goto l84; if (!yy_string()) goto l84; yyDo(yySet, -1, 0); yyDo(yy_13_statement, yybegin, yyend); goto l62;
  1013. l84:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("type")) goto l85; if (!yy__()) goto l85; if (!yy_string()) goto l85; yyDo(yySet, -1, 0); yyDo(yy_14_statement, yybegin, yyend); goto l62;
  1014. l85:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("dir")) goto l86; if (!yy__()) goto l86; yyDo(yy_15_statement, yybegin, yyend); goto l62;
  1015. l86:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("help")) goto l61; if (!yy__()) goto l61; yyDo(yy_16_statement, yybegin, yyend);
  1016. }
  1017. l62:;
  1018. yyprintf((stderr, " ok %s @ %s\n", "statement", yybuf+yypos)); yyDo(yyPop, 6, 0);
  1019. return 1;
  1020. l61:; yypos= yypos0; yythunkpos= yythunkpos0;
  1021. yyprintf((stderr, " fail %s @ %s\n", "statement", yybuf+yypos));
  1022. return 0;
  1023. }
  1024. YY_RULE(int) yy__()
  1025. {
  1026. yyprintf((stderr, "%s\n", "_"));
  1027. l88:;
  1028. { int yypos89= yypos, yythunkpos89= yythunkpos; if (!yymatchClass((unsigned char *)"\000\002\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l89; goto l88;
  1029. l89:; yypos= yypos89; yythunkpos= yythunkpos89;
  1030. }
  1031. yyprintf((stderr, " ok %s @ %s\n", "_", yybuf+yypos));
  1032. return 1;
  1033. }
  1034. YY_RULE(int) yy_line()
  1035. { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
  1036. yyprintf((stderr, "%s\n", "line"));
  1037. { int yypos91= yypos, yythunkpos91= yythunkpos; if (!yy__()) goto l92; if (!yy_statement()) goto l92; yyDo(yySet, -2, 0); if (!yy_CR()) goto l92; goto l91;
  1038. l92:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l93; if (!yy_number()) goto l93; yyDo(yySet, -1, 0); yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l93;
  1039. l94:;
  1040. { int yypos95= yypos, yythunkpos95= yythunkpos;
  1041. { int yypos96= yypos, yythunkpos96= yythunkpos; if (!yy_CR()) goto l96; goto l95;
  1042. l96:; yypos= yypos96; yythunkpos= yythunkpos96;
  1043. } if (!yymatchDot()) goto l95; goto l94;
  1044. l95:; yypos= yypos95; yythunkpos= yythunkpos95;
  1045. } if (!yy_CR()) goto l93; yyText(yybegin, yyend); if (!(YY_END)) goto l93; yyDo(yy_1_line, yybegin, yyend); goto l91;
  1046. l93:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l97; if (!yy_CR()) goto l97; goto l91;
  1047. l97:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l98; yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l98;
  1048. l99:;
  1049. { int yypos100= yypos, yythunkpos100= yythunkpos;
  1050. { int yypos101= yypos, yythunkpos101= yythunkpos; if (!yy_CR()) goto l101; goto l100;
  1051. l101:; yypos= yypos101; yythunkpos= yythunkpos101;
  1052. } if (!yymatchDot()) goto l100; goto l99;
  1053. l100:; yypos= yypos100; yythunkpos= yythunkpos100;
  1054. } if (!yy_CR()) goto l98; yyText(yybegin, yyend); if (!(YY_END)) goto l98; yyDo(yy_2_line, yybegin, yyend); goto l91;
  1055. l98:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l90;
  1056. { int yypos102= yypos, yythunkpos102= yythunkpos; if (!yymatchDot()) goto l102; goto l90;
  1057. l102:; yypos= yypos102; yythunkpos= yythunkpos102;
  1058. } yyDo(yy_3_line, yybegin, yyend);
  1059. }
  1060. l91:;
  1061. yyprintf((stderr, " ok %s @ %s\n", "line", yybuf+yypos)); yyDo(yyPop, 2, 0);
  1062. return 1;
  1063. l90:; yypos= yypos0; yythunkpos= yythunkpos0;
  1064. yyprintf((stderr, " fail %s @ %s\n", "line", yybuf+yypos));
  1065. return 0;
  1066. }
  1067. #ifndef YY_PART
  1068. typedef int (*yyrule)();
  1069. YY_PARSE(int) YYPARSEFROM(yyrule yystart)
  1070. {
  1071. int yyok;
  1072. if (!yybuflen)
  1073. {
  1074. yybuflen= 1024;
  1075. yybuf= malloc(yybuflen);
  1076. yytextlen= 1024;
  1077. yytext= malloc(yytextlen);
  1078. yythunkslen= 32;
  1079. yythunks= malloc(sizeof(yythunk) * yythunkslen);
  1080. yyvalslen= 32;
  1081. yyvals= malloc(sizeof(YYSTYPE) * yyvalslen);
  1082. yybegin= yyend= yypos= yylimit= yythunkpos= 0;
  1083. }
  1084. yybegin= yyend= yypos;
  1085. yythunkpos= 0;
  1086. yyval= yyvals;
  1087. yyok= yystart();
  1088. if (yyok) yyDone();
  1089. yyCommit();
  1090. return yyok;
  1091. (void)yyrefill;
  1092. (void)yymatchDot;
  1093. (void)yymatchChar;
  1094. (void)yymatchString;
  1095. (void)yymatchClass;
  1096. (void)yyDo;
  1097. (void)yyText;
  1098. (void)yyDone;
  1099. (void)yyCommit;
  1100. (void)yyAccept;
  1101. (void)yyPush;
  1102. (void)yyPop;
  1103. (void)yySet;
  1104. (void)yytextmax;
  1105. }
  1106. YY_PARSE(int) YYPARSE(void)
  1107. {
  1108. return YYPARSEFROM(yy_line);
  1109. }
  1110. #endif
  1111. #include <unistd.h>
  1112. #include <stdarg.h>
  1113. char *help=
  1114. "print <num>|<string> [, <num>|<string> ...] [,]\n"
  1115. "if <expr> <|<=|<>|=|>=|> <expr> then <stmt>\n"
  1116. "input <var> [, <var> ...] let <var> = <expr>\n"
  1117. "goto <expr> gosub <expr>\n"
  1118. "end return\n"
  1119. "list clear\n"
  1120. "run [\"filename\"] rem <comment...>\n"
  1121. "dir type \"filename\"\n"
  1122. "save \"filename\" load \"filename\"\n"
  1123. "bye|quit|exit help\n"
  1124. ;
  1125. void error(char *fmt, ...)
  1126. {
  1127. va_list ap;
  1128. va_start(ap, fmt);
  1129. if (epc > 0)
  1130. fprintf(stderr, "\nline %d: %s", lines[epc-1].number, lines[epc-1].text);
  1131. else
  1132. fprintf(stderr, "\n");
  1133. vfprintf(stderr, fmt, ap);
  1134. fprintf(stderr, "\n");
  1135. va_end(ap);
  1136. epc= pc= -1;
  1137. }
  1138. #ifdef USE_READLINE
  1139. # include <readline/readline.h>
  1140. # include <readline/history.h>
  1141. #endif
  1142. int nextline(char *buf, int max)
  1143. {
  1144. pc= -1;
  1145. if (batch) exit(0);
  1146. if (isatty(fileno(stdin)))
  1147. {
  1148. # ifdef USE_READLINE
  1149. char *line= readline(">");
  1150. if (line)
  1151. {
  1152. int len= strlen(line);
  1153. if (len >= max) len= max - 1;
  1154. strncpy(buf, line, len);
  1155. (buf)[len]= '\n';
  1156. add_history(line);
  1157. free(line);
  1158. return len + 1;
  1159. }
  1160. else
  1161. {
  1162. printf("\n");
  1163. return 0;
  1164. }
  1165. # endif
  1166. putchar('>');
  1167. fflush(stdout);
  1168. }
  1169. return fgets(buf, max, stdin) ? strlen(buf) : 0;
  1170. }
  1171. int maxLines= 0;
  1172. int findLine(int n, int create)
  1173. {
  1174. int lo= 0, hi= numLines - 1;
  1175. while (lo <= hi)
  1176. {
  1177. int mid= (lo + hi) / 2, lno= lines[mid].number;
  1178. if (lno > n)
  1179. hi= mid - 1;
  1180. else if (lno < n)
  1181. lo= mid + 1;
  1182. else
  1183. return mid;
  1184. }
  1185. if (create)
  1186. {
  1187. if (numLines == maxLines)
  1188. {
  1189. maxLines *= 2;
  1190. lines= realloc(lines, sizeof(line) * maxLines);
  1191. }
  1192. if (lo < numLines)
  1193. memmove(lines + lo + 1, lines + lo, sizeof(line) * (numLines - lo));
  1194. ++numLines;
  1195. lines[lo].number= n;
  1196. lines[lo].text= 0;
  1197. return lo;
  1198. }
  1199. return -1;
  1200. }
  1201. void accept(int n, char *s)
  1202. {
  1203. if (s[0] < 32) /* delete */
  1204. {
  1205. int lno= findLine(n, 0);
  1206. if (lno >= 0)
  1207. {
  1208. if (lno < numLines - 1)
  1209. memmove(lines + lno, lines + lno + 1, sizeof(line) * (numLines - lno - 1));
  1210. --numLines;
  1211. }
  1212. }
  1213. else /* insert */
  1214. {
  1215. int lno= findLine(n, 1);
  1216. if (lines[lno].text) free(lines[lno].text);
  1217. lines[lno].length= strlen(s);
  1218. lines[lno].text= strdup(s);
  1219. }
  1220. }
  1221. char *extend(char *name)
  1222. {
  1223. static char path[1024];
  1224. int len= strlen(name);
  1225. sprintf(path, "%s%s", name, (((len > 4) && !strcasecmp(".bas", name + len - 4)) ? "" : ".bas"));
  1226. return path;
  1227. }
  1228. void save(char *name)
  1229. {
  1230. FILE *f= fopen(name= extend(name), "w");
  1231. if (!f)
  1232. perror(name);
  1233. else
  1234. {
  1235. int i;
  1236. for (i= 0; i < numLines; ++i)
  1237. fprintf(f, "%d %s", lines[i].number, lines[i].text);
  1238. fclose(f);
  1239. }
  1240. }
  1241. void load(char *name)
  1242. {
  1243. FILE *f= fopen(name= extend(name), "r");
  1244. if (!f)
  1245. perror(name);
  1246. else
  1247. {
  1248. int lineNumber;
  1249. char lineText[1024];
  1250. while ((1 == fscanf(f, " %d ", &lineNumber)) && fgets(lineText, sizeof(lineText), f))
  1251. accept(lineNumber, lineText);
  1252. fclose(f);
  1253. }
  1254. }
  1255. void type(char *name)
  1256. {
  1257. FILE *f= fopen(name= extend(name), "r");
  1258. if (!f)
  1259. perror(name);
  1260. else
  1261. {
  1262. int c, d;
  1263. while ((c= getc(f)) >= 0)
  1264. putchar(d= c);
  1265. fclose(f);
  1266. if ('\n' != d && '\r' != d) putchar('\n');
  1267. }
  1268. }
  1269. int input(void)
  1270. {
  1271. char line[32];
  1272. fgets(line, sizeof(line), stdin);
  1273. return atoi(line);
  1274. }
  1275. int main(int argc, char **argv)
  1276. {
  1277. lines= malloc(sizeof(line) * (maxLines= 32));
  1278. numLines= 0;
  1279. if (argc > 1)
  1280. {
  1281. batch= 1;
  1282. while (argc-- > 1)
  1283. load(*++argv);
  1284. pc= 0;
  1285. }
  1286. while (!feof(stdin))
  1287. yyparse();
  1288. return 0;
  1289. }