12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352 |
- /* A recursive-descent parser generated by peg 0.1.1 */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define YYRULECOUNT 22
- # include <stdio.h>
- typedef struct line line;
- struct line
- {
- int number;
- int length;
- char *text;
- };
- line *lines= 0;
- int numLines= 0;
- int pc= -1, epc= -1;
- int batch= 0;
- int nextline(char *buf, int max);
- # define min(x, y) ((x) < (y) ? (x) : (y))
- # define YY_INPUT(buf, result, max_size) \
- { \
- if ((pc >= 0) && (pc < numLines)) \
- { \
- line *linep= lines+pc++; \
- result= min(max_size, linep->length); \
- memcpy(buf, linep->text, result); \
- } \
- else \
- result= nextline(buf, max_size); \
- }
- union value {
- int number;
- char *string;
- int (*binop)(int lhs, int rhs);
- };
- # define YYSTYPE union value
- int variables[26];
- void accept(int number, char *line);
- void save(char *name);
- void load(char *name);
- void type(char *name);
- int lessThan(int lhs, int rhs) { return lhs < rhs; }
- int lessEqual(int lhs, int rhs) { return lhs <= rhs; }
- int notEqual(int lhs, int rhs) { return lhs != rhs; }
- int equalTo(int lhs, int rhs) { return lhs == rhs; }
- int greaterEqual(int lhs, int rhs) { return lhs >= rhs; }
- int greaterThan(int lhs, int rhs) { return lhs > rhs; }
- int input(void);
- int stack[1024], sp= 0;
- char *help;
- void error(char *fmt, ...);
- int findLine(int n, int create);
- #ifndef YY_VARIABLE
- #define YY_VARIABLE(T) static T
- #endif
- #ifndef YY_LOCAL
- #define YY_LOCAL(T) static T
- #endif
- #ifndef YY_ACTION
- #define YY_ACTION(T) static T
- #endif
- #ifndef YY_RULE
- #define YY_RULE(T) static T
- #endif
- #ifndef YY_PARSE
- #define YY_PARSE(T) T
- #endif
- #ifndef YYPARSE
- #define YYPARSE yyparse
- #endif
- #ifndef YYPARSEFROM
- #define YYPARSEFROM yyparsefrom
- #endif
- #ifndef YY_INPUT
- #define YY_INPUT(buf, result, max_size) \
- { \
- int yyc= getchar(); \
- result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
- yyprintf((stderr, "<%c>", yyc)); \
- }
- #endif
- #ifndef YY_BEGIN
- #define YY_BEGIN ( yybegin= yypos, 1)
- #endif
- #ifndef YY_END
- #define YY_END ( yyend= yypos, 1)
- #endif
- #ifdef YY_DEBUG
- # define yyprintf(args) fprintf args
- #else
- # define yyprintf(args)
- #endif
- #ifndef YYSTYPE
- #define YYSTYPE int
- #endif
- #ifndef YY_PART
- typedef void (*yyaction)(char *yytext, int yyleng);
- typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk;
- YY_VARIABLE(char * ) yybuf= 0;
- YY_VARIABLE(int ) yybuflen= 0;
- YY_VARIABLE(int ) yypos= 0;
- YY_VARIABLE(int ) yylimit= 0;
- YY_VARIABLE(char * ) yytext= 0;
- YY_VARIABLE(int ) yytextlen= 0;
- YY_VARIABLE(int ) yybegin= 0;
- YY_VARIABLE(int ) yyend= 0;
- YY_VARIABLE(int ) yytextmax= 0;
- YY_VARIABLE(yythunk *) yythunks= 0;
- YY_VARIABLE(int ) yythunkslen= 0;
- YY_VARIABLE(int ) yythunkpos= 0;
- YY_VARIABLE(YYSTYPE ) yy;
- YY_VARIABLE(YYSTYPE *) yyval= 0;
- YY_VARIABLE(YYSTYPE *) yyvals= 0;
- YY_VARIABLE(int ) yyvalslen= 0;
- YY_LOCAL(int) yyrefill(void)
- {
- int yyn;
- while (yybuflen - yypos < 512)
- {
- yybuflen *= 2;
- yybuf= realloc(yybuf, yybuflen);
- }
- YY_INPUT((yybuf + yypos), yyn, (yybuflen - yypos));
- if (!yyn) return 0;
- yylimit += yyn;
- return 1;
- }
- YY_LOCAL(int) yymatchDot(void)
- {
- if (yypos >= yylimit && !yyrefill()) return 0;
- ++yypos;
- return 1;
- }
- YY_LOCAL(int) yymatchChar(int c)
- {
- if (yypos >= yylimit && !yyrefill()) return 0;
- if (yybuf[yypos] == c)
- {
- ++yypos;
- yyprintf((stderr, " ok yymatchChar(%c) @ %s\n", c, yybuf+yypos));
- return 1;
- }
- yyprintf((stderr, " fail yymatchChar(%c) @ %s\n", c, yybuf+yypos));
- return 0;
- }
- YY_LOCAL(int) yymatchString(char *s)
- {
- int yysav= yypos;
- while (*s)
- {
- if (yypos >= yylimit && !yyrefill()) return 0;
- if (yybuf[yypos] != *s)
- {
- yypos= yysav;
- return 0;
- }
- ++s;
- ++yypos;
- }
- return 1;
- }
- YY_LOCAL(int) yymatchClass(unsigned char *bits)
- {
- int c;
- if (yypos >= yylimit && !yyrefill()) return 0;
- c= yybuf[yypos];
- if (bits[c >> 3] & (1 << (c & 7)))
- {
- ++yypos;
- yyprintf((stderr, " ok yymatchClass @ %s\n", yybuf+yypos));
- return 1;
- }
- yyprintf((stderr, " fail yymatchClass @ %s\n", yybuf+yypos));
- return 0;
- }
- YY_LOCAL(void) yyDo(yyaction action, int begin, int end)
- {
- while (yythunkpos >= yythunkslen)
- {
- yythunkslen *= 2;
- yythunks= realloc(yythunks, sizeof(yythunk) * yythunkslen);
- }
- yythunks[yythunkpos].begin= begin;
- yythunks[yythunkpos].end= end;
- yythunks[yythunkpos].action= action;
- ++yythunkpos;
- }
- YY_LOCAL(int) yyText(int begin, int end)
- {
- int yyleng= end - begin;
- if (yyleng <= 0)
- yyleng= 0;
- else
- {
- while (yytextlen < (yyleng - 1))
- {
- yytextlen *= 2;
- yytext= realloc(yytext, yytextlen);
- }
- memcpy(yytext, yybuf + begin, yyleng);
- }
- yytext[yyleng]= '\0';
- return yyleng;
- }
- YY_LOCAL(void) yyDone(void)
- {
- int pos;
- for (pos= 0; pos < yythunkpos; ++pos)
- {
- yythunk *thunk= &yythunks[pos];
- int yyleng= thunk->end ? yyText(thunk->begin, thunk->end) : thunk->begin;
- yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, yytext));
- thunk->action(yytext, yyleng);
- }
- yythunkpos= 0;
- }
- YY_LOCAL(void) yyCommit()
- {
- if ((yylimit -= yypos))
- {
- memmove(yybuf, yybuf + yypos, yylimit);
- }
- yybegin -= yypos;
- yyend -= yypos;
- yypos= yythunkpos= 0;
- }
- YY_LOCAL(int) yyAccept(int tp0)
- {
- if (tp0)
- {
- fprintf(stderr, "accept denied at %d\n", tp0);
- return 0;
- }
- else
- {
- yyDone();
- yyCommit();
- }
- return 1;
- }
- YY_LOCAL(void) yyPush(char *text, int count) { if (text) { } yyval += count; }
- YY_LOCAL(void) yyPop(char *text, int count) { if (text) { } yyval -= count; }
- YY_LOCAL(void) yySet(char *text, int count) { if (text) { } yyval[count]= yy; }
- #endif /* YY_PART */
- #define YYACCEPT yyAccept(yythunkpos0)
- YY_RULE(int) yy_digit(); /* 22 */
- YY_RULE(int) yy_CLOSE(); /* 21 */
- YY_RULE(int) yy_OPEN(); /* 20 */
- YY_RULE(int) yy_SLASH(); /* 19 */
- YY_RULE(int) yy_STAR(); /* 18 */
- YY_RULE(int) yy_factor(); /* 17 */
- YY_RULE(int) yy_MINUS(); /* 16 */
- YY_RULE(int) yy_term(); /* 15 */
- YY_RULE(int) yy_PLUS(); /* 14 */
- YY_RULE(int) yy_COMMA(); /* 13 */
- YY_RULE(int) yy_string(); /* 12 */
- YY_RULE(int) yy_EQUAL(); /* 11 */
- YY_RULE(int) yy_var(); /* 10 */
- YY_RULE(int) yy_var_list(); /* 9 */
- YY_RULE(int) yy_relop(); /* 8 */
- YY_RULE(int) yy_expression(); /* 7 */
- YY_RULE(int) yy_expr_list(); /* 6 */
- YY_RULE(int) yy_number(); /* 5 */
- YY_RULE(int) yy_CR(); /* 4 */
- YY_RULE(int) yy_statement(); /* 3 */
- YY_RULE(int) yy__(); /* 2 */
- YY_RULE(int) yy_line(); /* 1 */
- YY_ACTION(void) yy_6_relop(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_6_relop\n"));
- yy.binop= equalTo; ;
- }
- YY_ACTION(void) yy_5_relop(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_5_relop\n"));
- yy.binop= greaterThan; ;
- }
- YY_ACTION(void) yy_4_relop(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_4_relop\n"));
- yy.binop= greaterEqual; ;
- }
- YY_ACTION(void) yy_3_relop(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_3_relop\n"));
- yy.binop= lessThan; ;
- }
- YY_ACTION(void) yy_2_relop(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_2_relop\n"));
- yy.binop= notEqual; ;
- }
- YY_ACTION(void) yy_1_relop(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_1_relop\n"));
- yy.binop= lessEqual; ;
- }
- YY_ACTION(void) yy_1_string(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_1_string\n"));
- yy.string = yytext; ;
- }
- YY_ACTION(void) yy_1_number(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_1_number\n"));
- yy.number = atoi(yytext); ;
- }
- YY_ACTION(void) yy_1_var(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- yyprintf((stderr, "do yy_1_var\n"));
- yy.number = yytext[0] - 'a' ;
- }
- YY_ACTION(void) yy_1_factor(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define n yyval[-1]
- #define v yyval[-2]
- yyprintf((stderr, "do yy_1_factor\n"));
- yy.number = variables[v.number] ;
- #undef n
- #undef v
- }
- YY_ACTION(void) yy_3_term(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_3_term\n"));
- yy.number = l.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_2_term(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_2_term\n"));
- l.number /= r.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_1_term(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_1_term\n"));
- l.number *= r.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_4_expression(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_4_expression\n"));
- yy.number = l.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_3_expression(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_3_expression\n"));
- l.number -= r.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_2_expression(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_2_expression\n"));
- l.number += r.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_1_expression(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define r yyval[-1]
- #define l yyval[-2]
- yyprintf((stderr, "do yy_1_expression\n"));
- l.number = -l.number ;
- #undef r
- #undef l
- }
- YY_ACTION(void) yy_2_var_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define v yyval[-1]
- yyprintf((stderr, "do yy_2_var_list\n"));
- variables[v.number]= input(); ;
- #undef v
- }
- YY_ACTION(void) yy_1_var_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define v yyval[-1]
- yyprintf((stderr, "do yy_1_var_list\n"));
- variables[v.number]= input(); ;
- #undef v
- }
- YY_ACTION(void) yy_5_expr_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define e yyval[-1]
- yyprintf((stderr, "do yy_5_expr_list\n"));
- printf("\n"); ;
- #undef e
- }
- YY_ACTION(void) yy_4_expr_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define e yyval[-1]
- yyprintf((stderr, "do yy_4_expr_list\n"));
- printf("%d", e.number); ;
- #undef e
- }
- YY_ACTION(void) yy_3_expr_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define e yyval[-1]
- yyprintf((stderr, "do yy_3_expr_list\n"));
- printf("%s", e.string); ;
- #undef e
- }
- YY_ACTION(void) yy_2_expr_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define e yyval[-1]
- yyprintf((stderr, "do yy_2_expr_list\n"));
- printf("%d", e.number); ;
- #undef e
- }
- YY_ACTION(void) yy_1_expr_list(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define e yyval[-1]
- yyprintf((stderr, "do yy_1_expr_list\n"));
- printf("%s", e.string); ;
- #undef e
- }
- YY_ACTION(void) yy_16_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_16_statement\n"));
- fprintf(stderr, "%s", help); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_15_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_15_statement\n"));
- system("ls *.bas"); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_14_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_14_statement\n"));
- type(s.string); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_13_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_13_statement\n"));
- load(s.string); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_12_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_12_statement\n"));
- save(s.string); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_11_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_11_statement\n"));
- exit(0); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_10_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_10_statement\n"));
- pc= -1; if (batch) exit(0); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_9_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_9_statement\n"));
- pc= 0; ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_8_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_8_statement\n"));
- load(s.string); pc= 0; ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_7_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_7_statement\n"));
- int i; for (i= 0; i < numLines; ++i) printf("%5d %s", lines[i].number, lines[i].text); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_6_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_6_statement\n"));
- while (numLines) accept(lines->number, "\n"); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_5_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_5_statement\n"));
- epc= pc; if ((pc= sp ? stack[--sp] : -1) < 0) error("no gosub"); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_4_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_4_statement\n"));
- epc= pc; if (sp < 1024) stack[sp++]= pc, pc= findLine(e.number, 0); else error("too many gosubs");
- if (pc < 0) error("no such line"); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_3_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_3_statement\n"));
- variables[v.number]= e.number; ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_2_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_2_statement\n"));
- epc= pc; if ((pc= findLine(e.number, 0)) < 0) error("no such line"); ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_1_statement(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define s yyval[-1]
- #define v yyval[-2]
- #define e yyval[-3]
- #define e2 yyval[-4]
- #define r yyval[-5]
- #define e1 yyval[-6]
- yyprintf((stderr, "do yy_1_statement\n"));
- if (!r.binop(e1.number, e2.number)) yythunkpos= 0; ;
- #undef s
- #undef v
- #undef e
- #undef e2
- #undef r
- #undef e1
- }
- YY_ACTION(void) yy_3_line(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define n yyval[-1]
- #define s yyval[-2]
- yyprintf((stderr, "do yy_3_line\n"));
- exit(0); ;
- #undef n
- #undef s
- }
- YY_ACTION(void) yy_2_line(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define n yyval[-1]
- #define s yyval[-2]
- yyprintf((stderr, "do yy_2_line\n"));
- epc= pc; error("syntax error"); ;
- #undef n
- #undef s
- }
- YY_ACTION(void) yy_1_line(char *yytext, int yyleng)
- { if(yytext) { } if (yyleng) { }
- #define n yyval[-1]
- #define s yyval[-2]
- yyprintf((stderr, "do yy_1_line\n"));
- accept(n.number, yytext); ;
- #undef n
- #undef s
- }
- YY_RULE(int) yy_digit()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- 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;
- yyprintf((stderr, " ok %s @ %s\n", "digit", yybuf+yypos));
- return 1;
- l1:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "digit", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_CLOSE()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "CLOSE")); if (!yymatchChar(')')) goto l2; if (!yy__()) goto l2;
- yyprintf((stderr, " ok %s @ %s\n", "CLOSE", yybuf+yypos));
- return 1;
- l2:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "CLOSE", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_OPEN()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "OPEN")); if (!yymatchChar('(')) goto l3; if (!yy__()) goto l3;
- yyprintf((stderr, " ok %s @ %s\n", "OPEN", yybuf+yypos));
- return 1;
- l3:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "OPEN", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_SLASH()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "SLASH")); if (!yymatchChar('/')) goto l4; if (!yy__()) goto l4;
- yyprintf((stderr, " ok %s @ %s\n", "SLASH", yybuf+yypos));
- return 1;
- l4:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "SLASH", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_STAR()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "STAR")); if (!yymatchChar('*')) goto l5; if (!yy__()) goto l5;
- yyprintf((stderr, " ok %s @ %s\n", "STAR", yybuf+yypos));
- return 1;
- l5:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "STAR", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_factor()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
- yyprintf((stderr, "%s\n", "factor"));
- { int yypos7= yypos, yythunkpos7= yythunkpos; if (!yy_var()) goto l8; yyDo(yySet, -2, 0); yyDo(yy_1_factor, yybegin, yyend); goto l7;
- l8:; yypos= yypos7; yythunkpos= yythunkpos7; if (!yy_number()) goto l9; yyDo(yySet, -1, 0); goto l7;
- l9:; yypos= yypos7; yythunkpos= yythunkpos7; if (!yy_OPEN()) goto l6; if (!yy_expression()) goto l6; if (!yy_CLOSE()) goto l6;
- }
- l7:;
- yyprintf((stderr, " ok %s @ %s\n", "factor", yybuf+yypos)); yyDo(yyPop, 2, 0);
- return 1;
- l6:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "factor", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_MINUS()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "MINUS")); if (!yymatchChar('-')) goto l10; if (!yy__()) goto l10;
- yyprintf((stderr, " ok %s @ %s\n", "MINUS", yybuf+yypos));
- return 1;
- l10:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "MINUS", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_term()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
- yyprintf((stderr, "%s\n", "term")); if (!yy_factor()) goto l11; yyDo(yySet, -2, 0);
- l12:;
- { int yypos13= yypos, yythunkpos13= yythunkpos;
- { 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;
- 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);
- }
- l14:; goto l12;
- l13:; yypos= yypos13; yythunkpos= yythunkpos13;
- } yyDo(yy_3_term, yybegin, yyend);
- yyprintf((stderr, " ok %s @ %s\n", "term", yybuf+yypos)); yyDo(yyPop, 2, 0);
- return 1;
- l11:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "term", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_PLUS()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "PLUS")); if (!yymatchChar('+')) goto l16; if (!yy__()) goto l16;
- yyprintf((stderr, " ok %s @ %s\n", "PLUS", yybuf+yypos));
- return 1;
- l16:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "PLUS", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_COMMA()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "COMMA")); if (!yymatchChar(',')) goto l17; if (!yy__()) goto l17;
- yyprintf((stderr, " ok %s @ %s\n", "COMMA", yybuf+yypos));
- return 1;
- l17:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "COMMA", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_string()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "string")); if (!yymatchChar('"')) goto l18; yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l18;
- l19:;
- { 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;
- l20:; yypos= yypos20; yythunkpos= yythunkpos20;
- } yyText(yybegin, yyend); if (!(YY_END)) goto l18; if (!yymatchChar('"')) goto l18; if (!yy__()) goto l18; yyDo(yy_1_string, yybegin, yyend);
- yyprintf((stderr, " ok %s @ %s\n", "string", yybuf+yypos));
- return 1;
- l18:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "string", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_EQUAL()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar('=')) goto l21; if (!yy__()) goto l21;
- yyprintf((stderr, " ok %s @ %s\n", "EQUAL", yybuf+yypos));
- return 1;
- l21:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "EQUAL", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_var()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- 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);
- yyprintf((stderr, " ok %s @ %s\n", "var", yybuf+yypos));
- return 1;
- l22:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "var", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_var_list()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 1, 0);
- yyprintf((stderr, "%s\n", "var_list")); if (!yy_var()) goto l23; yyDo(yySet, -1, 0); yyDo(yy_1_var_list, yybegin, yyend);
- l24:;
- { 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;
- l25:; yypos= yypos25; yythunkpos= yythunkpos25;
- }
- yyprintf((stderr, " ok %s @ %s\n", "var_list", yybuf+yypos)); yyDo(yyPop, 1, 0);
- return 1;
- l23:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "var_list", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_relop()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "relop"));
- { int yypos27= yypos, yythunkpos27= yythunkpos; if (!yymatchString("<=")) goto l28; if (!yy__()) goto l28; yyDo(yy_1_relop, yybegin, yyend); goto l27;
- l28:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchString("<>")) goto l29; if (!yy__()) goto l29; yyDo(yy_2_relop, yybegin, yyend); goto l27;
- l29:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchChar('<')) goto l30; if (!yy__()) goto l30; yyDo(yy_3_relop, yybegin, yyend); goto l27;
- l30:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchString(">=")) goto l31; if (!yy__()) goto l31; yyDo(yy_4_relop, yybegin, yyend); goto l27;
- l31:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchChar('>')) goto l32; if (!yy__()) goto l32; yyDo(yy_5_relop, yybegin, yyend); goto l27;
- l32:; yypos= yypos27; yythunkpos= yythunkpos27; if (!yymatchChar('=')) goto l26; if (!yy__()) goto l26; yyDo(yy_6_relop, yybegin, yyend);
- }
- l27:;
- yyprintf((stderr, " ok %s @ %s\n", "relop", yybuf+yypos));
- return 1;
- l26:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "relop", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_expression()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
- yyprintf((stderr, "%s\n", "expression"));
- { int yypos34= yypos, yythunkpos34= yythunkpos;
- { int yypos36= yypos, yythunkpos36= yythunkpos; if (!yy_PLUS()) goto l36; goto l37;
- l36:; yypos= yypos36; yythunkpos= yythunkpos36;
- }
- l37:; if (!yy_term()) goto l35; yyDo(yySet, -2, 0); goto l34;
- 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);
- }
- l34:;
- l38:;
- { int yypos39= yypos, yythunkpos39= yythunkpos;
- { 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;
- 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);
- }
- l40:; goto l38;
- l39:; yypos= yypos39; yythunkpos= yythunkpos39;
- } yyDo(yy_4_expression, yybegin, yyend);
- yyprintf((stderr, " ok %s @ %s\n", "expression", yybuf+yypos)); yyDo(yyPop, 2, 0);
- return 1;
- l33:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "expression", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_expr_list()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 1, 0);
- yyprintf((stderr, "%s\n", "expr_list"));
- { int yypos43= yypos, yythunkpos43= yythunkpos;
- { int yypos45= yypos, yythunkpos45= yythunkpos; if (!yy_string()) goto l46; yyDo(yySet, -1, 0); yyDo(yy_1_expr_list, yybegin, yyend); goto l45;
- l46:; yypos= yypos45; yythunkpos= yythunkpos45; if (!yy_expression()) goto l43; yyDo(yySet, -1, 0); yyDo(yy_2_expr_list, yybegin, yyend);
- }
- l45:; goto l44;
- l43:; yypos= yypos43; yythunkpos= yythunkpos43;
- }
- l44:;
- l47:;
- { int yypos48= yypos, yythunkpos48= yythunkpos; if (!yy_COMMA()) goto l48;
- { int yypos49= yypos, yythunkpos49= yythunkpos; if (!yy_string()) goto l50; yyDo(yySet, -1, 0); yyDo(yy_3_expr_list, yybegin, yyend); goto l49;
- l50:; yypos= yypos49; yythunkpos= yythunkpos49; if (!yy_expression()) goto l48; yyDo(yySet, -1, 0); yyDo(yy_4_expr_list, yybegin, yyend);
- }
- l49:; goto l47;
- l48:; yypos= yypos48; yythunkpos= yythunkpos48;
- }
- { int yypos51= yypos, yythunkpos51= yythunkpos; if (!yy_COMMA()) goto l52; goto l51;
- l52:; yypos= yypos51; yythunkpos= yythunkpos51;
- { int yypos53= yypos, yythunkpos53= yythunkpos; if (!yy_COMMA()) goto l53; goto l42;
- l53:; yypos= yypos53; yythunkpos= yythunkpos53;
- } yyDo(yy_5_expr_list, yybegin, yyend);
- }
- l51:;
- yyprintf((stderr, " ok %s @ %s\n", "expr_list", yybuf+yypos)); yyDo(yyPop, 1, 0);
- return 1;
- l42:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "expr_list", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_number()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "number")); yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l54; if (!yy_digit()) goto l54;
- l55:;
- { int yypos56= yypos, yythunkpos56= yythunkpos; if (!yy_digit()) goto l56; goto l55;
- l56:; yypos= yypos56; yythunkpos= yythunkpos56;
- } yyText(yybegin, yyend); if (!(YY_END)) goto l54; if (!yy__()) goto l54; yyDo(yy_1_number, yybegin, yyend);
- yyprintf((stderr, " ok %s @ %s\n", "number", yybuf+yypos));
- return 1;
- l54:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "number", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_CR()
- { int yypos0= yypos, yythunkpos0= yythunkpos;
- yyprintf((stderr, "%s\n", "CR"));
- { int yypos58= yypos, yythunkpos58= yythunkpos; if (!yymatchChar('\n')) goto l59; goto l58;
- l59:; yypos= yypos58; yythunkpos= yythunkpos58; if (!yymatchChar('\r')) goto l60; goto l58;
- l60:; yypos= yypos58; yythunkpos= yythunkpos58; if (!yymatchString("\r\n")) goto l57;
- }
- l58:;
- yyprintf((stderr, " ok %s @ %s\n", "CR", yybuf+yypos));
- return 1;
- l57:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "CR", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy_statement()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 6, 0);
- yyprintf((stderr, "%s\n", "statement"));
- { int yypos62= yypos, yythunkpos62= yythunkpos; if (!yymatchString("print")) goto l63; if (!yy__()) goto l63; if (!yy_expr_list()) goto l63; goto l62;
- 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;
- 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;
- l65:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("input")) goto l66; if (!yy__()) goto l66; if (!yy_var_list()) goto l66; goto l62;
- 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;
- 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;
- l68:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("return")) goto l69; if (!yy__()) goto l69; yyDo(yy_5_statement, yybegin, yyend); goto l62;
- l69:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("clear")) goto l70; if (!yy__()) goto l70; yyDo(yy_6_statement, yybegin, yyend); goto l62;
- l70:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("list")) goto l71; if (!yy__()) goto l71; yyDo(yy_7_statement, yybegin, yyend); goto l62;
- 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;
- l72:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("run")) goto l73; if (!yy__()) goto l73; yyDo(yy_9_statement, yybegin, yyend); goto l62;
- l73:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("end")) goto l74; if (!yy__()) goto l74; yyDo(yy_10_statement, yybegin, yyend); goto l62;
- l74:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("rem")) goto l75; if (!yy__()) goto l75;
- l76:;
- { int yypos77= yypos, yythunkpos77= yythunkpos;
- { int yypos78= yypos, yythunkpos78= yythunkpos; if (!yy_CR()) goto l78; goto l77;
- l78:; yypos= yypos78; yythunkpos= yythunkpos78;
- } if (!yymatchDot()) goto l77; goto l76;
- l77:; yypos= yypos77; yythunkpos= yythunkpos77;
- } goto l62;
- l75:; yypos= yypos62; yythunkpos= yythunkpos62;
- { int yypos80= yypos, yythunkpos80= yythunkpos; if (!yymatchString("bye")) goto l81; goto l80;
- l81:; yypos= yypos80; yythunkpos= yythunkpos80; if (!yymatchString("quit")) goto l82; goto l80;
- l82:; yypos= yypos80; yythunkpos= yythunkpos80; if (!yymatchString("exit")) goto l79;
- }
- l80:; if (!yy__()) goto l79; yyDo(yy_11_statement, yybegin, yyend); goto l62;
- 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;
- 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;
- 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;
- l85:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("dir")) goto l86; if (!yy__()) goto l86; yyDo(yy_15_statement, yybegin, yyend); goto l62;
- l86:; yypos= yypos62; yythunkpos= yythunkpos62; if (!yymatchString("help")) goto l61; if (!yy__()) goto l61; yyDo(yy_16_statement, yybegin, yyend);
- }
- l62:;
- yyprintf((stderr, " ok %s @ %s\n", "statement", yybuf+yypos)); yyDo(yyPop, 6, 0);
- return 1;
- l61:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "statement", yybuf+yypos));
- return 0;
- }
- YY_RULE(int) yy__()
- {
- yyprintf((stderr, "%s\n", "_"));
- l88:;
- { 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;
- l89:; yypos= yypos89; yythunkpos= yythunkpos89;
- }
- yyprintf((stderr, " ok %s @ %s\n", "_", yybuf+yypos));
- return 1;
- }
- YY_RULE(int) yy_line()
- { int yypos0= yypos, yythunkpos0= yythunkpos; yyDo(yyPush, 2, 0);
- yyprintf((stderr, "%s\n", "line"));
- { 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;
- 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;
- l94:;
- { int yypos95= yypos, yythunkpos95= yythunkpos;
- { int yypos96= yypos, yythunkpos96= yythunkpos; if (!yy_CR()) goto l96; goto l95;
- l96:; yypos= yypos96; yythunkpos= yythunkpos96;
- } if (!yymatchDot()) goto l95; goto l94;
- l95:; yypos= yypos95; yythunkpos= yythunkpos95;
- } if (!yy_CR()) goto l93; yyText(yybegin, yyend); if (!(YY_END)) goto l93; yyDo(yy_1_line, yybegin, yyend); goto l91;
- l93:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l97; if (!yy_CR()) goto l97; goto l91;
- l97:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l98; yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l98;
- l99:;
- { int yypos100= yypos, yythunkpos100= yythunkpos;
- { int yypos101= yypos, yythunkpos101= yythunkpos; if (!yy_CR()) goto l101; goto l100;
- l101:; yypos= yypos101; yythunkpos= yythunkpos101;
- } if (!yymatchDot()) goto l100; goto l99;
- l100:; yypos= yypos100; yythunkpos= yythunkpos100;
- } if (!yy_CR()) goto l98; yyText(yybegin, yyend); if (!(YY_END)) goto l98; yyDo(yy_2_line, yybegin, yyend); goto l91;
- l98:; yypos= yypos91; yythunkpos= yythunkpos91; if (!yy__()) goto l90;
- { int yypos102= yypos, yythunkpos102= yythunkpos; if (!yymatchDot()) goto l102; goto l90;
- l102:; yypos= yypos102; yythunkpos= yythunkpos102;
- } yyDo(yy_3_line, yybegin, yyend);
- }
- l91:;
- yyprintf((stderr, " ok %s @ %s\n", "line", yybuf+yypos)); yyDo(yyPop, 2, 0);
- return 1;
- l90:; yypos= yypos0; yythunkpos= yythunkpos0;
- yyprintf((stderr, " fail %s @ %s\n", "line", yybuf+yypos));
- return 0;
- }
- #ifndef YY_PART
- typedef int (*yyrule)();
- YY_PARSE(int) YYPARSEFROM(yyrule yystart)
- {
- int yyok;
- if (!yybuflen)
- {
- yybuflen= 1024;
- yybuf= malloc(yybuflen);
- yytextlen= 1024;
- yytext= malloc(yytextlen);
- yythunkslen= 32;
- yythunks= malloc(sizeof(yythunk) * yythunkslen);
- yyvalslen= 32;
- yyvals= malloc(sizeof(YYSTYPE) * yyvalslen);
- yybegin= yyend= yypos= yylimit= yythunkpos= 0;
- }
- yybegin= yyend= yypos;
- yythunkpos= 0;
- yyval= yyvals;
- yyok= yystart();
- if (yyok) yyDone();
- yyCommit();
- return yyok;
- (void)yyrefill;
- (void)yymatchDot;
- (void)yymatchChar;
- (void)yymatchString;
- (void)yymatchClass;
- (void)yyDo;
- (void)yyText;
- (void)yyDone;
- (void)yyCommit;
- (void)yyAccept;
- (void)yyPush;
- (void)yyPop;
- (void)yySet;
- (void)yytextmax;
- }
- YY_PARSE(int) YYPARSE(void)
- {
- return YYPARSEFROM(yy_line);
- }
- #endif
- #include <unistd.h>
- #include <stdarg.h>
- char *help=
- "print <num>|<string> [, <num>|<string> ...] [,]\n"
- "if <expr> <|<=|<>|=|>=|> <expr> then <stmt>\n"
- "input <var> [, <var> ...] let <var> = <expr>\n"
- "goto <expr> gosub <expr>\n"
- "end return\n"
- "list clear\n"
- "run [\"filename\"] rem <comment...>\n"
- "dir type \"filename\"\n"
- "save \"filename\" load \"filename\"\n"
- "bye|quit|exit help\n"
- ;
- void error(char *fmt, ...)
- {
- va_list ap;
- va_start(ap, fmt);
- if (epc > 0)
- fprintf(stderr, "\nline %d: %s", lines[epc-1].number, lines[epc-1].text);
- else
- fprintf(stderr, "\n");
- vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
- va_end(ap);
- epc= pc= -1;
- }
- #ifdef USE_READLINE
- # include <readline/readline.h>
- # include <readline/history.h>
- #endif
- int nextline(char *buf, int max)
- {
- pc= -1;
- if (batch) exit(0);
- if (isatty(fileno(stdin)))
- {
- # ifdef USE_READLINE
- char *line= readline(">");
- if (line)
- {
- int len= strlen(line);
- if (len >= max) len= max - 1;
- strncpy(buf, line, len);
- (buf)[len]= '\n';
- add_history(line);
- free(line);
- return len + 1;
- }
- else
- {
- printf("\n");
- return 0;
- }
- # endif
- putchar('>');
- fflush(stdout);
- }
- return fgets(buf, max, stdin) ? strlen(buf) : 0;
- }
- int maxLines= 0;
- int findLine(int n, int create)
- {
- int lo= 0, hi= numLines - 1;
- while (lo <= hi)
- {
- int mid= (lo + hi) / 2, lno= lines[mid].number;
- if (lno > n)
- hi= mid - 1;
- else if (lno < n)
- lo= mid + 1;
- else
- return mid;
- }
- if (create)
- {
- if (numLines == maxLines)
- {
- maxLines *= 2;
- lines= realloc(lines, sizeof(line) * maxLines);
- }
- if (lo < numLines)
- memmove(lines + lo + 1, lines + lo, sizeof(line) * (numLines - lo));
- ++numLines;
- lines[lo].number= n;
- lines[lo].text= 0;
- return lo;
- }
- return -1;
- }
- void accept(int n, char *s)
- {
- if (s[0] < 32) /* delete */
- {
- int lno= findLine(n, 0);
- if (lno >= 0)
- {
- if (lno < numLines - 1)
- memmove(lines + lno, lines + lno + 1, sizeof(line) * (numLines - lno - 1));
- --numLines;
- }
- }
- else /* insert */
- {
- int lno= findLine(n, 1);
- if (lines[lno].text) free(lines[lno].text);
- lines[lno].length= strlen(s);
- lines[lno].text= strdup(s);
- }
- }
- char *extend(char *name)
- {
- static char path[1024];
- int len= strlen(name);
- sprintf(path, "%s%s", name, (((len > 4) && !strcasecmp(".bas", name + len - 4)) ? "" : ".bas"));
- return path;
- }
- void save(char *name)
- {
- FILE *f= fopen(name= extend(name), "w");
- if (!f)
- perror(name);
- else
- {
- int i;
- for (i= 0; i < numLines; ++i)
- fprintf(f, "%d %s", lines[i].number, lines[i].text);
- fclose(f);
- }
- }
- void load(char *name)
- {
- FILE *f= fopen(name= extend(name), "r");
- if (!f)
- perror(name);
- else
- {
- int lineNumber;
- char lineText[1024];
- while ((1 == fscanf(f, " %d ", &lineNumber)) && fgets(lineText, sizeof(lineText), f))
- accept(lineNumber, lineText);
- fclose(f);
- }
- }
- void type(char *name)
- {
- FILE *f= fopen(name= extend(name), "r");
- if (!f)
- perror(name);
- else
- {
- int c, d;
- while ((c= getc(f)) >= 0)
- putchar(d= c);
- fclose(f);
- if ('\n' != d && '\r' != d) putchar('\n');
- }
- }
- int input(void)
- {
- char line[32];
- fgets(line, sizeof(line), stdin);
- return atoi(line);
- }
- int main(int argc, char **argv)
- {
- lines= malloc(sizeof(line) * (maxLines= 32));
- numLines= 0;
- if (argc > 1)
- {
- batch= 1;
- while (argc-- > 1)
- load(*++argv);
- pc= 0;
- }
- while (!feof(stdin))
- yyparse();
- return 0;
- }
|