#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include "robotworld.h"
Include dependency graph for rowo.cpp:
Go to the source code of this file.
Classes | |
union | YYSTYPE |
struct | YYSTYPE::codestruct |
Defines | |
#define | YYBYACC 1 |
#define | YYMAJOR 1 |
#define | YYMINOR 9 |
#define | yyclearin (yychar=(-1)) |
#define | yyerrok (yyerrflag=0) |
#define | YYRECOVERING (yyerrflag!=0) |
#define | YYPREFIX "yy" |
#define | C the_str[the_ptr] |
#define | C1 the_str[the_ptr+1] |
#define | INT 257 |
#define | IDENTIFIER 258 |
#define | COMMENT 259 |
#define | Object 260 |
#define | EnumObjectType 261 |
#define | Cos 262 |
#define | Sin 263 |
#define | If 264 |
#define | Loop 265 |
#define | EQ 266 |
#define | NEQ 267 |
#define | AND 268 |
#define | OR 269 |
#define | YYERRCODE 256 |
#define | YYTABLESIZE 364 |
#define | YYFINAL 2 |
#define | YYDEBUG 0 |
#define | YYMAXTOKEN 270 |
#define | YYSTACKSIZE 500 |
#define | YYMAXDEPTH 500 |
#define | yystacksize YYSTACKSIZE |
#define | YYABORT goto yyabort |
#define | YYREJECT goto yyabort |
#define | YYACCEPT goto yyaccept |
#define | YYERROR goto yyerrlab |
Functions | |
const std::string & | GetCodestr () |
std::map< std::string, int > & | GetCodemap () |
std::vector< VARIABLE * > & | GetVariables () |
bool | GetFailed () |
int | yyparse () |
short | reg_variable (const std::string &, int type=0) |
void | check_property (const std::string &, const std::string &) |
void | check_method (const std::string &, const std::string &) |
void | add_bytecode (char *, int opcode) |
void | add_bytecode (char *, int opcode, short val) |
void | add_bytecode (char *, int opcode, long val) |
void | add_bytecode (char *, int opcode, const std::string &object, const std::string &property_or_method) |
int | yyerror (char *s) |
int | yylex () |
void | parse_file (const std::string &filename) |
Variables | |
static char | yysccsid [] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" |
static char | the_str [1000] |
static int | the_ptr |
static int | line |
static FILE * | fil |
static int | uniq |
static std::vector< VARIABLE * > | variables |
static std::string | codestr |
static std::map< std::string, int > | codemap |
static bool | failed |
static int | x_ptr |
short | yylhs [] |
short | yylen [] |
short | yydefred [] |
short | yydgoto [] |
short | yysindex [] |
short | yyrindex [] |
short | yygindex [] |
short | yytable [] |
short | yycheck [] |
int | yydebug |
int | yynerrs |
int | yyerrflag |
int | yychar |
short * | yyssp |
YYSTYPE * | yyvsp |
YYSTYPE | yyval |
YYSTYPE | yylval |
short | yyss [YYSTACKSIZE] |
YYSTYPE | yyvs [YYSTACKSIZE] |
void add_bytecode | ( | char * | , | |
int | opcode, | |||
const std::string & | object, | |||
const std::string & | property_or_method | |||
) |
Definition at line 514 of file rowo.cpp.
References failed, ROBOTOBJECT_GUN, ROBOTOBJECT_RADAR, ROBOTOBJECT_ROBOT, ROBOTOBJECT_SHIELDS, and ROBOTOBJECT_TURRET.
00515 { 00516 int objectcode = 0; 00517 int val = 0; 00518 { 00519 // robot, radar, turret, gun, shields 00520 if (!strcmp(object.c_str(), "robot")) 00521 { 00522 objectcode = ROBOTOBJECT_ROBOT; 00523 if (property_or_method == "ok") 00524 val = 1; 00525 if (property_or_method == "damage") 00526 val = 2; 00527 if (property_or_method == "repair_rate") 00528 val = 3; 00529 if (property_or_method == "inventory") 00530 val = 4; 00531 if (property_or_method == "power") 00532 val = 5; 00533 if (property_or_method == "charging") 00534 val = 6; 00535 } 00536 else 00537 if (!strcmp(object.c_str(), "radar")) 00538 { 00539 objectcode = ROBOTOBJECT_RADAR; 00540 if (property_or_method == "ok") 00541 val = 1; 00542 if (property_or_method == "damage") 00543 val = 2; 00544 if (property_or_method == "repair_rate") 00545 val = 3; 00546 } 00547 else 00548 if (!strcmp(object.c_str(), "turret")) 00549 { 00550 objectcode = ROBOTOBJECT_TURRET; 00551 if (property_or_method == "ok") 00552 val = 1; 00553 if (property_or_method == "damage") 00554 val = 2; 00555 if (property_or_method == "repair_rate") 00556 val = 3; 00557 } 00558 else 00559 if (!strcmp(object.c_str(), "gun")) 00560 { 00561 objectcode = ROBOTOBJECT_GUN; 00562 if (property_or_method == "ok") 00563 val = 1; 00564 if (property_or_method == "damage") 00565 val = 2; 00566 if (property_or_method == "repair_rate") 00567 val = 3; 00568 } 00569 else 00570 if (!strcmp(object.c_str(), "shields")) 00571 { 00572 objectcode = ROBOTOBJECT_SHIELDS; 00573 if (property_or_method == "ok") 00574 val = 1; 00575 if (property_or_method == "damage") 00576 val = 2; 00577 if (property_or_method == "repair_rate") 00578 val = 3; 00579 } 00580 else 00581 { 00582 printf("Unknown object: %s\n", object.c_str() ); 00583 failed = true; 00584 } 00585 } 00586 sprintf(s + strlen(s), "%02x%02x%02x", opcode, objectcode, val); 00587 }
void add_bytecode | ( | char * | , | |
int | opcode, | |||
long | val | |||
) |
void add_bytecode | ( | char * | , | |
int | opcode, | |||
short | val | |||
) |
void add_bytecode | ( | char * | , | |
int | opcode | |||
) |
void check_method | ( | const std::string & | , | |
const std::string & | ||||
) |
void check_property | ( | const std::string & | , | |
const std::string & | ||||
) |
std::map<std::string, int>& GetCodemap | ( | ) |
const std::string& GetCodestr | ( | ) |
bool GetFailed | ( | ) |
std::vector<VARIABLE *>& GetVariables | ( | ) |
void parse_file | ( | const std::string & | filename | ) |
Definition at line 427 of file rowo.cpp.
References codemap, codestr, failed, fil, line, the_ptr, the_str, uniq, variables, and yyparse().
Referenced by main().
00428 { 00429 *the_str = 0; 00430 the_ptr = 0; 00431 line = 0; 00432 uniq = 1; 00433 codestr = ""; 00434 failed = false; 00435 while (codemap.size()) 00436 { 00437 codemap.erase(codemap.begin()); 00438 } 00439 while (variables.size()) 00440 { 00441 variables.erase(variables.begin()); 00442 } 00443 if ((fil = fopen(filename.c_str(), "rt")) != NULL) 00444 { 00445 yyparse(); 00446 fclose(fil); 00447 } 00448 else 00449 { 00450 fprintf(stderr, "Couldn't open '%s'...\n", filename.c_str()); 00451 failed = true; 00452 } 00453 }
short reg_variable | ( | const std::string & | , | |
int | type = 0 | |||
) |
Definition at line 456 of file rowo.cpp.
References variables.
Referenced by yyparse().
00457 { 00458 for (std::vector<VARIABLE *>::iterator it = variables.begin(); it != variables.end(); it++) 00459 { 00460 VARIABLE *p = *it; 00461 if (name == p -> name) 00462 { 00463 if (type && !p -> type) 00464 p -> type = type; 00465 if (type && p -> type && type != p -> type) 00466 fprintf(stderr,"Variable type mismatch: '%s'\n",name.c_str()); 00467 return p -> nr; 00468 } 00469 } 00470 VARIABLE *p = new VARIABLE(name, type, variables.size()); 00471 variables.push_back(p); 00472 return p -> nr; 00473 }
int yyerror | ( | char * | s | ) |
Definition at line 286 of file rowo.cpp.
References failed, line, the_str, and x_ptr.
Referenced by yyparse().
00287 { 00288 int i; 00289 00290 printf("%d>%s\n", line, the_str); 00291 printf("%d ", line); 00292 for (i = 1; i < x_ptr; i++) 00293 printf(" "); 00294 printf("^ yyerror '%s'\n", s); 00295 failed = true; 00296 return 0; 00297 }
int yylex | ( | ) |
Definition at line 300 of file rowo.cpp.
References AND, C, C1, COMMENT, EnumObjectType, EQ, fil, IDENTIFIER, If, INT, YYSTYPE::l, line, Loop, MAPOBJECT_BASE, MAPOBJECT_ITEM, MAPOBJECT_NOTHING, MAPOBJECT_PORTAL, MAPOBJECT_POWERUP_UNKNOWN, MAPOBJECT_ROBOT, NEQ, Object, OR, YYSTYPE::str, the_ptr, the_str, x_ptr, and yylval.
Referenced by yyparse().
00301 { 00302 size_t x; 00303 00304 while (C == ' ' || C == 9) 00305 { 00306 the_ptr++; 00307 } 00308 while (!C && !feof(fil)) 00309 { 00310 fgets(the_str, 1000, fil); 00311 the_str[strlen(the_str) - 1] = 0; 00312 for (size_t i = 0; i < strlen(the_str); i++) 00313 if (the_str[i] == 9) 00314 the_str[i] = ' '; 00315 the_ptr = 0; 00316 line++; 00317 while (C == ' ' || C == 9) 00318 { 00319 the_ptr++; 00320 } 00321 } 00322 if (feof(fil)) 00323 { 00324 return 0; 00325 } 00326 x_ptr = the_ptr; 00327 if (C == '=' && C1 == '=') 00328 { 00329 the_ptr += 2; 00330 return EQ; 00331 } 00332 if (C == '!' && C1 == '=') 00333 { 00334 the_ptr += 2; 00335 return NEQ; 00336 } 00337 if (C == '&' && C1 == '&') 00338 { 00339 the_ptr += 2; 00340 return AND; 00341 } 00342 if (C == '|' && C1 == '|') 00343 { 00344 the_ptr += 2; 00345 return OR; 00346 } 00347 if (C == '/' && C1 == '/') 00348 { 00349 strcpy(yylval.str, the_str + the_ptr); 00350 C = 0; 00351 return COMMENT; 00352 } 00353 if (isalpha(C)) 00354 { 00355 x = the_ptr++; 00356 while (isalnum(C) || C == '_') 00357 { 00358 the_ptr++; 00359 } 00360 std::string ord = static_cast<std::string>(the_str).substr(x, the_ptr - x); 00361 strcpy(yylval.str, ord.c_str()); 00362 if (ord == "if") 00363 return If; 00364 if (ord == "radar" || ord == "turret" || ord == "gun" || ord == "robot" || ord == "shields" ) 00365 { 00366 return Object; 00367 } 00368 if (ord == "Robot") // Robot, Portal, Powerup, Base, Nothing, Item 00369 { 00370 yylval.l = MAPOBJECT_ROBOT; 00371 return EnumObjectType; 00372 } 00373 if (ord == "Portal") 00374 { 00375 yylval.l = MAPOBJECT_PORTAL; 00376 return EnumObjectType; 00377 } 00378 if (ord == "Powerup") 00379 { 00380 yylval.l = MAPOBJECT_POWERUP_UNKNOWN; 00381 return EnumObjectType; 00382 } 00383 if (ord == "Base") 00384 { 00385 yylval.l = MAPOBJECT_BASE; 00386 return EnumObjectType; 00387 } 00388 if (ord == "Item") 00389 { 00390 yylval.l = MAPOBJECT_ITEM; 00391 return EnumObjectType; 00392 } 00393 if (ord == "Nothing") 00394 { 00395 yylval.l = MAPOBJECT_NOTHING; 00396 return EnumObjectType; 00397 } 00398 if (ord == "loop") 00399 return Loop; 00400 return IDENTIFIER; 00401 } 00402 if (isdigit(C)) 00403 { 00404 bool f = false; 00405 x = the_ptr; 00406 while (isdigit(C)) // || C == '.' || C == 'e' || C == 'E') 00407 { 00408 if (!isdigit(C)) 00409 f = true; 00410 the_ptr++; 00411 } 00412 std::string ord = static_cast<std::string>(the_str).substr(x, the_ptr - x); 00413 /* 00414 if (f) 00415 { 00416 yylval.d = atof(ord.c_str()); 00417 return FLOAT; 00418 } 00419 */ 00420 yylval.l = atol(ord.c_str()); 00421 return INT; 00422 } 00423 return the_str[the_ptr++]; 00424 }
int yyparse | ( | ) |
Definition at line 596 of file rowo.cpp.
References add_bytecode(), YYSTYPE::codestruct::bytecode, check_method(), check_property(), YYSTYPE::codestruct::code, YYSTYPE::code, codemap, codestr, YYSTYPE::l, reg_variable(), YYSTYPE::str, uniq, yychar, yycheck, YYDEBUG, yydebug, yydefred, yydgoto, YYERRCODE, yyerrflag, yyerror(), YYFINAL, yygindex, yylen, yylex(), yylhs, yylval, YYMAXTOKEN, yynerrs, YYPREFIX, yyrindex, yysindex, yyss, yyssp, yystacksize, yytable, YYTABLESIZE, yyval, yyvs, and yyvsp.
Referenced by parse_file().
00597 { 00598 register int yym, yyn, yystate; 00599 #if YYDEBUG 00600 register char *yys; 00601 extern char *getenv(); 00602 00603 if (yys = getenv("YYDEBUG")) 00604 { 00605 yyn = *yys; 00606 if (yyn >= '0' && yyn <= '9') 00607 yydebug = yyn - '0'; 00608 } 00609 #endif 00610 00611 yynerrs = 0; 00612 yyerrflag = 0; 00613 yychar = (-1); 00614 00615 yyssp = yyss; 00616 yyvsp = yyvs; 00617 *yyssp = yystate = 0; 00618 00619 yyloop: 00620 if (yyn = yydefred[yystate]) goto yyreduce; 00621 if (yychar < 0) 00622 { 00623 if ((yychar = yylex()) < 0) yychar = 0; 00624 #if YYDEBUG 00625 if (yydebug) 00626 { 00627 yys = 0; 00628 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 00629 if (!yys) yys = "illegal-symbol"; 00630 printf("%sdebug: state %d, reading %d (%s)\n", 00631 YYPREFIX, yystate, yychar, yys); 00632 } 00633 #endif 00634 } 00635 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && 00636 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 00637 { 00638 #if YYDEBUG 00639 if (yydebug) 00640 printf("%sdebug: state %d, shifting to state %d\n", 00641 YYPREFIX, yystate, yytable[yyn]); 00642 #endif 00643 if (yyssp >= yyss + yystacksize - 1) 00644 { 00645 goto yyoverflow; 00646 } 00647 *++yyssp = yystate = yytable[yyn]; 00648 *++yyvsp = yylval; 00649 yychar = (-1); 00650 if (yyerrflag > 0) --yyerrflag; 00651 goto yyloop; 00652 } 00653 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && 00654 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 00655 { 00656 yyn = yytable[yyn]; 00657 goto yyreduce; 00658 } 00659 if (yyerrflag) goto yyinrecovery; 00660 #ifdef lint 00661 goto yynewerror; 00662 #endif 00663 yynewerror: 00664 yyerror("syntax error"); 00665 #ifdef lint 00666 goto yyerrlab; 00667 #endif 00668 yyerrlab: 00669 ++yynerrs; 00670 yyinrecovery: 00671 if (yyerrflag < 3) 00672 { 00673 yyerrflag = 3; 00674 for (;;) 00675 { 00676 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && 00677 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) 00678 { 00679 #if YYDEBUG 00680 if (yydebug) 00681 printf("%sdebug: state %d, error recovery shifting\ 00682 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); 00683 #endif 00684 if (yyssp >= yyss + yystacksize - 1) 00685 { 00686 goto yyoverflow; 00687 } 00688 *++yyssp = yystate = yytable[yyn]; 00689 *++yyvsp = yylval; 00690 goto yyloop; 00691 } 00692 else 00693 { 00694 #if YYDEBUG 00695 if (yydebug) 00696 printf("%sdebug: error recovery discarding state %d\n", 00697 YYPREFIX, *yyssp); 00698 #endif 00699 if (yyssp <= yyss) goto yyabort; 00700 --yyssp; 00701 --yyvsp; 00702 } 00703 } 00704 } 00705 else 00706 { 00707 if (yychar == 0) goto yyabort; 00708 #if YYDEBUG 00709 if (yydebug) 00710 { 00711 yys = 0; 00712 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 00713 if (!yys) yys = "illegal-symbol"; 00714 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 00715 YYPREFIX, yystate, yychar, yys); 00716 } 00717 #endif 00718 yychar = (-1); 00719 goto yyloop; 00720 } 00721 yyreduce: 00722 #if YYDEBUG 00723 if (yydebug) 00724 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 00725 YYPREFIX, yystate, yyn, yyrule[yyn]); 00726 #endif 00727 yym = yylen[yyn]; 00728 yyval = yyvsp[1-yym]; 00729 switch (yyn) 00730 { 00731 case 4: 00732 #line 80 "rowo.y" 00733 { 00734 /* if (*scope) ...*/ 00735 add_bytecode(yyvsp[0].code.bytecode, 0x84); /* ret*/ 00736 /* create codestr / codemap*/ 00737 codemap[yyvsp[-1].str] = codestr.size() / 2; /* entry point*/ 00738 codestr += yyvsp[0].code.bytecode; 00739 } 00740 break; 00741 case 5: 00742 #line 88 "rowo.y" 00743 { 00744 *yyval.code.code = 0; 00745 *yyval.code.bytecode = 0; 00746 } 00747 break; 00748 case 6: 00749 #line 92 "rowo.y" 00750 { 00751 strcpy(yyval.code.code, yyvsp[-1].code.code); 00752 /* bytecode*/ 00753 strcpy(yyval.code.bytecode, yyvsp[-1].code.bytecode); 00754 } 00755 break; 00756 case 7: 00757 #line 98 "rowo.y" 00758 { 00759 strcpy(yyval.code.code, yyvsp[0].code.code); 00760 /* bytecode*/ 00761 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00762 } 00763 break; 00764 case 8: 00765 #line 103 "rowo.y" 00766 { 00767 strcpy(yyval.code.code, yyvsp[-1].code.code); 00768 strcat(yyval.code.code, yyvsp[0].code.code); 00769 /* bytecode*/ 00770 strcpy(yyval.code.bytecode, yyvsp[-1].code.bytecode); 00771 strcat(yyval.code.bytecode, yyvsp[0].code.bytecode); 00772 } 00773 break; 00774 case 9: 00775 #line 111 "rowo.y" 00776 { 00777 strcpy(yyval.code.code, yyvsp[0].code.code); 00778 /* bytecode*/ 00779 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00780 } 00781 break; 00782 case 10: 00783 #line 116 "rowo.y" 00784 { 00785 strcpy(yyval.code.code, yyvsp[0].code.code); 00786 /* bytecode*/ 00787 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00788 } 00789 break; 00790 case 11: 00791 #line 121 "rowo.y" 00792 { 00793 strcpy(yyval.code.code, yyvsp[0].code.code); 00794 /* bytecode*/ 00795 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00796 } 00797 break; 00798 case 12: 00799 #line 126 "rowo.y" 00800 { 00801 strcpy(yyval.code.code, yyvsp[0].code.code); 00802 /* bytecode*/ 00803 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00804 } 00805 break; 00806 case 13: 00807 #line 131 "rowo.y" 00808 { *yyval.code.code = 0; 00809 *yyval.code.bytecode = 0; 00810 } 00811 break; 00812 case 14: 00813 #line 135 "rowo.y" 00814 { 00815 /* if (*scope) ...*/ 00816 int x = uniq++; 00817 *yyval.code.code = 0; 00818 strcat(yyval.code.code, " // if_statement\n"); 00819 strcat(yyval.code.code, yyvsp[-2].code.code); 00820 sprintf(yyval.code.code + strlen(yyval.code.code), " jz label_%d\n", x); 00821 strcat(yyval.code.code, yyvsp[0].code.code); 00822 sprintf(yyval.code.code + strlen(yyval.code.code), "label_%d:\n", x); 00823 /* bytecode*/ 00824 strcpy(yyval.code.bytecode, yyvsp[-2].code.bytecode); /* get expression*/ 00825 short len = strlen(yyvsp[0].code.bytecode) / 2; /* length in bytes*/ 00826 add_bytecode(yyval.code.bytecode, 0x0a, len); /* jz*/ 00827 strcat(yyval.code.bytecode, yyvsp[0].code.bytecode); /* scope*/ 00828 } 00829 break; 00830 case 15: 00831 #line 151 "rowo.y" 00832 { 00833 *yyval.code.code = 0; 00834 strcat(yyval.code.code, " // assign_statement\n"); 00835 strcat(yyval.code.code, yyvsp[0].code.code); 00836 sprintf(yyval.code.code + strlen(yyval.code.code), " ld $%s, a\n", yyvsp[-2].str); 00837 00838 short var = reg_variable(yyvsp[-2].str, 1); 00839 /* bytecode*/ 00840 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); /* get expression*/ 00841 add_bytecode(yyval.code.bytecode, 0x0d, var); /* variable[] = register1*/ 00842 } 00843 break; 00844 case 16: 00845 #line 162 "rowo.y" 00846 { 00847 *yyval.code.code = 0; 00848 strcat(yyval.code.code, " // assign_statement\n"); 00849 strcat(yyval.code.code, yyvsp[0].code.code); 00850 sprintf(yyval.code.code + strlen(yyval.code.code), " ld $%s.%s, a\n", yyvsp[-4].str, yyvsp[-2].str); 00851 00852 check_property(yyvsp[-4].str, yyvsp[-2].str); 00853 /* bytecode*/ 00854 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); /* get expression*/ 00855 add_bytecode(yyval.code.bytecode, 0x0f, yyvsp[-4].str, yyvsp[-2].str); /* assign object.property*/ 00856 } 00857 break; 00858 case 17: 00859 #line 174 "rowo.y" 00860 { 00861 short var = reg_variable(yyvsp[-6].str, 2); 00862 check_property(yyvsp[-3].str, yyvsp[-1].str); 00863 /* bytecode*/ 00864 *yyval.code.bytecode = 0; 00865 add_bytecode(yyval.code.bytecode, 0x82, yyvsp[-3].str, yyvsp[-1].str); /* loop init object.property*/ 00866 strcat(yyval.code.bytecode, "0000"); /* loop body length*/ 00867 size_t x = strlen(yyval.code.bytecode); 00868 add_bytecode(yyval.code.bytecode, 0x83, var); /* assign object variable: 3 bytes*/ 00869 short len = strlen(yyvsp[0].code.bytecode) / 2 + 3; /* length in bytes*/ 00870 add_bytecode(yyval.code.bytecode, 0x0a, len); /* jz end of loop: 3 bytes*/ 00871 strcat(yyval.code.bytecode, yyvsp[0].code.bytecode); /* scope*/ 00872 len = strlen(yyvsp[0].code.bytecode) / 2 + 6; 00873 len = -len; 00874 add_bytecode(yyval.code.bytecode, 0x81, len); /* jmp loop beginning*/ 00875 00876 size_t body = (strlen(yyval.code.bytecode) - x) / 2; 00877 char slask[100]; 00878 sprintf(slask, "%04x", body); 00879 memcpy(yyval.code.bytecode + x - 4, slask, 4); 00880 } 00881 break; 00882 case 18: 00883 #line 195 "rowo.y" 00884 { 00885 short var1 = reg_variable(yyvsp[-6].str, 2); 00886 short var2 = reg_variable(yyvsp[-3].str); 00887 short len = strlen(yyvsp[-1].str); 00888 *yyval.code.bytecode = 0; 00889 add_bytecode(yyval.code.bytecode, 0x11, var2); /* register1 = variable[zz zz].property*/ 00890 sprintf(yyval.code.bytecode + strlen(yyval.code.bytecode), "%02x", len); 00891 for (int i = 0; i < len; i++) 00892 { 00893 sprintf(yyval.code.bytecode + strlen(yyval.code.bytecode), "%02x", yyvsp[-1].str[i]); 00894 } 00895 strcat(yyval.code.bytecode, "0000"); /* loop body length*/ 00896 size_t x = strlen(yyval.code.bytecode); 00897 add_bytecode(yyval.code.bytecode, 0x83, var1); /* assign object variable: 3 bytes*/ 00898 len = strlen(yyvsp[0].code.bytecode) / 2 + 3; /* length in bytes*/ 00899 add_bytecode(yyval.code.bytecode, 0x0a, len); /* jz end of loop: 3 bytes*/ 00900 strcat(yyval.code.bytecode, yyvsp[0].code.bytecode); /* scope*/ 00901 len = strlen(yyvsp[0].code.bytecode) / 2 + 6; 00902 len = -len; 00903 add_bytecode(yyval.code.bytecode, 0x81, len); /* jmp loop beginning*/ 00904 00905 size_t body = (strlen(yyval.code.bytecode) - x) / 2; 00906 char slask[100]; 00907 sprintf(slask, "%04x", body); 00908 memcpy(yyval.code.bytecode + x - 4, slask, 4); 00909 } 00910 break; 00911 case 19: 00912 #line 222 "rowo.y" 00913 { 00914 *yyval.code.code = 0; 00915 strcat(yyval.code.code, " // object_statement\n"); 00916 strcat(yyval.code.code, yyvsp[-1].code.code); 00917 sprintf(yyval.code.code + strlen(yyval.code.code), " call $%s.%s\n", yyvsp[-5].str, yyvsp[-3].str); 00918 strcat(yyval.code.code, " pop a // ? - call returns with value in a, not on stack perhaps?\n"); 00919 00920 check_method(yyvsp[-5].str, yyvsp[-3].str); 00921 /* bytecode*/ 00922 *yyval.code.bytecode = 0; 00923 strcpy(yyval.code.bytecode, yyvsp[-1].code.bytecode); /* parameters*/ 00924 add_bytecode(yyval.code.bytecode, 0x0e, yyvsp[-5].str, yyvsp[-3].str); /* call object.method result in register1*/ 00925 } 00926 break; 00927 case 20: 00928 #line 236 "rowo.y" 00929 { 00930 *yyval.code.code = 0; 00931 *yyval.code.bytecode = 0; 00932 } 00933 break; 00934 case 21: 00935 #line 240 "rowo.y" 00936 { 00937 strcpy(yyval.code.code, yyvsp[0].code.code); 00938 /* bytecode*/ 00939 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00940 } 00941 break; 00942 case 22: 00943 #line 245 "rowo.y" 00944 { 00945 strcpy(yyval.code.code, yyvsp[-2].code.code); 00946 strcat(yyval.code.code, yyvsp[0].code.code); 00947 /* bytecode*/ 00948 strcpy(yyval.code.bytecode, yyvsp[-2].code.bytecode); 00949 strcat(yyval.code.bytecode, yyvsp[0].code.bytecode); 00950 } 00951 break; 00952 case 23: 00953 #line 253 "rowo.y" 00954 { 00955 strcpy(yyval.code.code, yyvsp[0].code.code); 00956 strcat(yyval.code.code, " push a\n"); 00957 /* bytecode*/ 00958 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 00959 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 00960 } 00961 break; 00962 case 24: 00963 #line 261 "rowo.y" 00964 { sprintf(yyval.code.code, " ld a, %ld\n", yyvsp[0].l); 00965 /* bytecode*/ 00966 *yyval.code.bytecode = 0; 00967 add_bytecode(yyval.code.bytecode, 0x03, yyvsp[0].l); 00968 } 00969 break; 00970 case 25: 00971 #line 266 "rowo.y" 00972 { 00973 sprintf(yyval.code.code, " ld a, %ld\n", yyvsp[0].l); 00974 /* bytecode*/ 00975 *yyval.code.bytecode = 0; 00976 add_bytecode(yyval.code.bytecode, 0x03, yyvsp[0].l); 00977 } 00978 break; 00979 case 26: 00980 #line 272 "rowo.y" 00981 { 00982 sprintf(yyval.code.code, " ld a, $%s.%s\n", yyvsp[-2].str, yyvsp[0].str); 00983 00984 check_property(yyvsp[-2].str, yyvsp[0].str); 00985 /* bytecode*/ 00986 *yyval.code.bytecode = 0; 00987 add_bytecode(yyval.code.bytecode, 0x01, yyvsp[-2].str, yyvsp[0].str); /* register1 = object.property*/ 00988 } 00989 break; 00990 case 27: 00991 #line 280 "rowo.y" 00992 { sprintf(yyval.code.code, " ld a, $%s\n", yyvsp[0].str); 00993 00994 short var = reg_variable(yyvsp[0].str); 00995 /* bytecode*/ 00996 *yyval.code.bytecode = 0; 00997 add_bytecode(yyval.code.bytecode, 0x0c, var); /* register1 = variable*/ 00998 } 00999 break; 01000 case 28: 01001 #line 287 "rowo.y" 01002 { 01003 sprintf(yyval.code.code, " ld a, $%s.%s\n", yyvsp[-2].str, yyvsp[0].str); 01004 01005 short var = reg_variable(yyvsp[-2].str); 01006 short len = strlen(yyvsp[0].str); 01007 check_property(yyvsp[-2].str, yyvsp[0].str); 01008 /* bytecode*/ 01009 *yyval.code.bytecode = 0; 01010 add_bytecode(yyval.code.bytecode, 0x10, var); /* register1 = variable[zz zz].property*/ 01011 sprintf(yyval.code.bytecode + strlen(yyval.code.bytecode), "%02x", len); 01012 for (int i = 0; i < len; i++) 01013 { 01014 sprintf(yyval.code.bytecode + strlen(yyval.code.bytecode), "%02x", yyvsp[0].str[i]); 01015 } 01016 } 01017 break; 01018 case 29: 01019 #line 302 "rowo.y" 01020 { 01021 strcpy(yyval.code.code, yyvsp[0].code.code); 01022 strcat(yyval.code.code, " push a\n"); 01023 strcat(yyval.code.code, yyvsp[-2].code.code); 01024 strcat(yyval.code.code, " pop b\n"); 01025 strcat(yyval.code.code, " add b\n"); 01026 /* bytecode*/ 01027 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01028 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01029 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01030 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01031 add_bytecode(yyval.code.bytecode, 0x25); /* add register2*/ 01032 } 01033 break; 01034 case 30: 01035 #line 315 "rowo.y" 01036 { 01037 strcpy(yyval.code.code, yyvsp[0].code.code); 01038 strcat(yyval.code.code, " push a\n"); 01039 strcat(yyval.code.code, yyvsp[-2].code.code); 01040 strcat(yyval.code.code, " pop b\n"); 01041 strcat(yyval.code.code, " sub b\n"); 01042 /* bytecode*/ 01043 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01044 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01045 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01046 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01047 add_bytecode(yyval.code.bytecode, 0x26); /* add register2*/ 01048 } 01049 break; 01050 case 31: 01051 #line 328 "rowo.y" 01052 { 01053 strcpy(yyval.code.code, yyvsp[0].code.code); 01054 strcat(yyval.code.code, " push a\n"); 01055 strcat(yyval.code.code, yyvsp[-2].code.code); 01056 strcat(yyval.code.code, " pop b\n"); 01057 strcat(yyval.code.code, " mul b\n"); 01058 /* bytecode*/ 01059 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01060 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01061 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01062 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01063 add_bytecode(yyval.code.bytecode, 0x27); /* add register2*/ 01064 } 01065 break; 01066 case 32: 01067 #line 341 "rowo.y" 01068 { 01069 strcpy(yyval.code.code, yyvsp[0].code.code); 01070 strcat(yyval.code.code, " push a\n"); 01071 strcat(yyval.code.code, yyvsp[-2].code.code); 01072 strcat(yyval.code.code, " pop b\n"); 01073 strcat(yyval.code.code, " div b\n"); 01074 /* bytecode*/ 01075 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01076 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01077 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01078 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01079 add_bytecode(yyval.code.bytecode, 0x28); /* add register2*/ 01080 } 01081 break; 01082 case 33: 01083 #line 354 "rowo.y" 01084 { 01085 strcpy(yyval.code.code, yyvsp[-2].code.code); 01086 strcat(yyval.code.code, " push a\n"); 01087 strcat(yyval.code.code, yyvsp[0].code.code); 01088 strcat(yyval.code.code, " pop b\n"); 01089 strcat(yyval.code.code, " eq b // a=0 if a!=b, a=1 if a==b\n"); 01090 /* bytecode*/ 01091 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01092 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01093 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01094 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01095 add_bytecode(yyval.code.bytecode, 0x29); /* add register2*/ 01096 } 01097 break; 01098 case 34: 01099 #line 367 "rowo.y" 01100 { 01101 int x = uniq++; 01102 strcpy(yyval.code.code, yyvsp[-4].code.code); 01103 sprintf(yyval.code.code + strlen(yyval.code.code), " jz label_second_%d\n", x); 01104 strcat(yyval.code.code, yyvsp[-2].code.code); 01105 sprintf(yyval.code.code + strlen(yyval.code.code), " jmp label_%d\n", x); 01106 sprintf(yyval.code.code + strlen(yyval.code.code), "label_second_%d:\n", x); 01107 strcat(yyval.code.code, yyvsp[0].code.code); 01108 sprintf(yyval.code.code + strlen(yyval.code.code), "label_%d:\n", x); 01109 /* bytecode*/ 01110 strcpy(yyval.code.bytecode, yyvsp[-4].code.bytecode); /* get expression*/ 01111 short len = strlen(yyvsp[-2].code.bytecode) / 2 + 3; /* first block + jmp*/ 01112 add_bytecode(yyval.code.bytecode, 0x0a, len); /* jz*/ 01113 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01114 len = strlen(yyvsp[0].code.bytecode) / 2; 01115 add_bytecode(yyval.code.bytecode, 0x81, len); /* jmp*/ 01116 strcat(yyval.code.bytecode, yyvsp[0].code.bytecode); 01117 } 01118 break; 01119 case 35: 01120 #line 385 "rowo.y" 01121 { 01122 strcpy(yyval.code.code, yyvsp[-1].code.code); 01123 /* bytecode*/ 01124 strcpy(yyval.code.bytecode, yyvsp[-1].code.bytecode); 01125 } 01126 break; 01127 case 36: 01128 #line 390 "rowo.y" 01129 { 01130 *yyval.code.bytecode = 0; 01131 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01132 add_bytecode(yyval.code.bytecode, 0x12); /* not*/ 01133 } 01134 break; 01135 case 37: 01136 #line 395 "rowo.y" 01137 { 01138 *yyval.code.bytecode = 0; 01139 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01140 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01141 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01142 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01143 add_bytecode(yyval.code.bytecode, 0x33); /* neq register2*/ 01144 } 01145 break; 01146 case 38: 01147 #line 403 "rowo.y" 01148 { 01149 *yyval.code.bytecode = 0; 01150 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01151 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01152 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01153 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01154 add_bytecode(yyval.code.bytecode, 0x34); /* and register2*/ 01155 } 01156 break; 01157 case 39: 01158 #line 411 "rowo.y" 01159 { 01160 *yyval.code.bytecode = 0; 01161 strcpy(yyval.code.bytecode, yyvsp[0].code.bytecode); 01162 add_bytecode(yyval.code.bytecode, 0x02); /* push register1*/ 01163 strcat(yyval.code.bytecode, yyvsp[-2].code.bytecode); 01164 add_bytecode(yyval.code.bytecode, 0x24); /* pop register2*/ 01165 add_bytecode(yyval.code.bytecode, 0x35); /* or register2*/ 01166 } 01167 break; 01168 #line 1169 "y.tab.c" 01169 } 01170 yyssp -= yym; 01171 yystate = *yyssp; 01172 yyvsp -= yym; 01173 yym = yylhs[yyn]; 01174 if (yystate == 0 && yym == 0) 01175 { 01176 #if YYDEBUG 01177 if (yydebug) 01178 printf("%sdebug: after reduction, shifting from state 0 to\ 01179 state %d\n", YYPREFIX, YYFINAL); 01180 #endif 01181 yystate = YYFINAL; 01182 *++yyssp = YYFINAL; 01183 *++yyvsp = yyval; 01184 if (yychar < 0) 01185 { 01186 if ((yychar = yylex()) < 0) yychar = 0; 01187 #if YYDEBUG 01188 if (yydebug) 01189 { 01190 yys = 0; 01191 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 01192 if (!yys) yys = "illegal-symbol"; 01193 printf("%sdebug: state %d, reading %d (%s)\n", 01194 YYPREFIX, YYFINAL, yychar, yys); 01195 } 01196 #endif 01197 } 01198 if (yychar == 0) goto yyaccept; 01199 goto yyloop; 01200 } 01201 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && 01202 yyn <= YYTABLESIZE && yycheck[yyn] == yystate) 01203 yystate = yytable[yyn]; 01204 else 01205 yystate = yydgoto[yym]; 01206 #if YYDEBUG 01207 if (yydebug) 01208 printf("%sdebug: after reduction, shifting from state %d \ 01209 to state %d\n", YYPREFIX, *yyssp, yystate); 01210 #endif 01211 if (yyssp >= yyss + yystacksize - 1) 01212 { 01213 goto yyoverflow; 01214 } 01215 *++yyssp = yystate; 01216 *++yyvsp = yyval; 01217 goto yyloop; 01218 yyoverflow: 01219 yyerror("yacc stack overflow"); 01220 yyabort: 01221 return (1); 01222 yyaccept: 01223 return (0); 01224 }
std::map<std::string, int> codemap [static] |
std::string codestr [static] |
bool failed [static] |
Definition at line 31 of file rowo.cpp.
Referenced by add_bytecode(), GetFailed(), parse_file(), and yyerror().
FILE* fil [static] |
Definition at line 26 of file rowo.cpp.
Referenced by GetMyUid(), main(), InjectSocket::OnConnect(), parse_file(), and yylex().
int line [static] |
int the_ptr [static] |
char the_str[1000] [static] |
int uniq [static] |
Definition at line 28 of file rowo.cpp.
Referenced by GetVariables(), parse_file(), and reg_variable().
short yydefred[] |
Initial value:
{ 0, 0, 0, 0, 2, 0, 4, 3, 0, 13, 0, 0, 5, 0, 7, 9, 10, 11, 12, 0, 0, 0, 6, 8, 24, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 26, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 31, 32, 0, 0, 21, 0, 14, 0, 0, 0, 19, 0, 18, 17, 0, 22, }
Definition at line 84 of file rowo.cpp.
Referenced by yyparse().
short yydgoto[] |
short yygindex[] |
short yylen[] |
short yylhs[] |
short yyrindex[] |
Initial value:
{ 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -29, 0, 0, 0, 0, 0, -92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -36, 0, 0, 0, 0, 0, 0, 0, 12, 25, 39, 46, 0, -15, -1, 0, 0, -24, 0, 0, -84, 0, 0, 0, 0, 0, 0, 0, 0, 53, 0, }
Definition at line 108 of file rowo.cpp.
Referenced by yyparse().
char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" [static] |
short yysindex[] |
Initial value:
{ -257, -121, 0, -257, 0, -106, 0, 0, -53, 0, -26, -19, 0, -103, 0, 0, 0, 0, 0, -33, -233, 75, 0, 0, 0, -14, -11, 0, -249, 75, 75, 86, -34, 58, -227, -222, -9, -8, 0, 71, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, -121, 0, 0, -219, -213, 0, 4, 4, 97, 97, 80, -32, -32, 0, 0, 86, -37, 0, 86, 0, -121, -121, 75, 0, 75, 0, 0, 86, 0, }
Definition at line 98 of file rowo.cpp.
Referenced by yyparse().