Advertisement
ZoriaRPG

Parser Stuff for Gray

Dec 23rd, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.62 KB | None | 0 0
  1. //For ffscript.lpp
  2.  
  3. case    {doLines(); return CASE;}
  4. switch  {doLines(); return SWITCH;}
  5. npcdata {doLines(); return NPCDATA;}
  6. \# { ; } //will be replaced by DIRECTIVE
  7. \:          { doLines();return COLON; }
  8. \:\-        { doLines();return ASSIGN; }
  9. \:\:        { doLines(); return ARROW;} //This is to be replaced by RESCOPE
  10. define { doLines() return DEFINE; } //In the future, this should onyl work in the DIRECTIVE rule.
  11.  
  12. //Comment block or comment
  13. (/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*) { ; }
  14.  
  15.  
  16.  
  17.  
  18. /* Stuff that can surely wait.
  19. \!\<    {doLines(); return NOTLESS; }
  20. \!\>    {doLines(); return NOTGREATER; }
  21.  
  22. \!\<\=    {doLines(); return NOTLESSOREQUAL; }
  23. \!\>\=    {doLines(); return NOTGREATEROREQUAL; }
  24. ptr { doLines(); return POINTER; }
  25. until           { doLines(); return UNTIL; }
  26. unless          { doLines(); return UNLESS; }
  27. repeat          { doLines(); return REPEAT; }
  28. begin          { doLines(); return BEGIN; }
  29. end          { doLines(); return END; }
  30. "/*" { commentblock(); }
  31.  
  32. void commentblock(void) {
  33.     char c, prev = 0;
  34.     while ( ( c = input() ) != 0 ) {
  35.         if ( c == '/' && prev == '*' ) return;
  36.         prev = c;
  37.     }
  38. }
  39.  
  40. */
  41.  
  42.  
  43.  
  44. //For ffscript.ypp
  45.  
  46. //%token NPCDATA //for later
  47.  
  48. //If the simple token for ffscript.lpp doesn't work, we can fall back on a function.
  49. //%token COMMENTBLOCK
  50.  
  51. %token SWITCH
  52. %token CASE
  53. %token DEFINE
  54.  
  55. Type : FLOAT {$$ = new ASTTypeFloat(@1);}
  56.     | BOOL {$$ = new ASTTypeBool(@1);}
  57.     | VOID {$$ = new ASTTypeVoid(@1);}
  58.     | FFC {$$ = new ASTTypeFFC(@1);}
  59.     | ITEM {$$ = new ASTTypeItem(@1);}
  60.     | ITEMCLASS {$$ = new ASTTypeItemclass(@1);}
  61.     | NPC       {$$ = new ASTTypeNPC(@1);}
  62.     | LWEAPON   {$$ = new ASTTypeLWpn(@1);}
  63.     | EWEAPON   {$$ = new ASTTypeEWpn(@1);}
  64. `   | NPCDATA {$$ = new ASTTypeNPCData(@1);}
  65.     ;
  66.  
  67. Stmt : VarDecl SEMICOLON {$$ = $1;}
  68.     | ArrayDecl SEMICOLON {$$ = $1;}
  69.     | AssignStmt SEMICOLON {$$ = $1;}
  70.     | ShortcutAssignStmt SEMICOLON {$$=$1;}
  71.     | ForStmt {$$ = $1;}
  72.     | IfStmt {$$ = $1;}
  73.     | Block {$$ = $1;}
  74.     | ReturnStmt SEMICOLON {$$ = $1;}
  75.     | WhileStmt {$$ = $1;}
  76.     | DoStmt {$$ = $1;}
  77.     | SwitchStmt {$$ = $1;}
  78.     | SEMICOLON {$$ = new ASTStmtEmpty(@1);}
  79.     | Expr SEMICOLON {$$=$1;}
  80.     | BREAK SEMICOLON {$$ = new ASTStmtBreak(@1);}
  81.     | CONTINUE SEMICOLON {$$ = new ASTStmtContinue(@1);}
  82.     ;
  83.  
  84.    
  85. StmtNoSemi : VarDecl {$$ = $1;}
  86.     | ArrayDecl {$$ = $1;}
  87.     | AssignStmt {$$ = $1;}
  88.     | ShortcutAssignStmt {$$=$1;}
  89.     | ForStmt {$$ = $1;}
  90.     | IfStmt {$$ = $1;}
  91.     | Block {$$ = $1;}
  92.     | ReturnStmt {$$ = $1;}
  93.     | WhileStmt {$$ = $1;}
  94.     | DoStmt {$$ = $1;}
  95.     | {$$ = new ASTStmtEmpty(noloc);}
  96.     | Expr {$$=$1;}
  97.     | BREAK {$$ = new ASTStmtBreak(@1);}
  98.     | CONTINUE {$$ = new ASTStmtContinue(@1);}
  99.     | CASE  {$$ = new ASTStmtCase(@1);}
  100.     ;
  101.    
  102.  
  103. DefineDecl : DEFINE IDENTIFIER NUMBER   {   ASTString *name = (ASTString *)$3;
  104.                         ASTFloat *val = (ASTFloat *)$5;
  105.                         $$ = new ASTtDecl(name->getValue(), val,@1);
  106.                         delete name;
  107.                     }
  108.     |
  109.         DEFINE IDENTIFIER MINUS NUMBER  {   ASTString *name = (ASTString *)$3;
  110.                             ASTFloat *val = (ASTFloat *)$6;
  111.                             val->set_negative(true);
  112.                             $$ = new ASTDefineDecl(name->getValue(), val,@1);
  113.                             delete name;
  114.                         }
  115.                    
  116.    
  117. ConstDecl : CONST FLOAT IDENTIFIER ASSIGN NUMBER SEMICOLON {ASTString *name = (ASTString *)$3;
  118.                                                             ASTFloat *val = (ASTFloat *)$5;
  119.                                                             $$ = new ASTConstDecl(name->getValue(), val,@1);
  120.                                                             delete name;}
  121.           | CONST FLOAT IDENTIFIER ASSIGN MINUS NUMBER SEMICOLON {ASTString *name = (ASTString *)$3;
  122.                                                                   ASTFloat *val = (ASTFloat *)$6;
  123.                                                                   val->set_negative(true);
  124.                                                                   $$ = new ASTConstDecl(name->getValue(), val,@1);
  125.                                                                 delete name;}
  126. /* This won't work anyway.
  127.     | CONST FLOAT IDENTIFIER ASSIGN IDENTIFIER SEMICOLON    {  ASTString *name = (ASTString *)$3;
  128.                                    ASTFloat *val = (ASTFloat *)$5;
  129.                                 //This needs a check to find out of the value of the identifier
  130.                                 //is negative! and to do
  131.                                 // val->set_negative(true);
  132.                                    $$ = new ASTConstDecl(name->getValue(), val,@1);
  133.                                    delete name;
  134.                                 }
  135.    
  136.           | CONST FLOAT IDENTIFIER ASSIGN MINUS IDENTIFIER SEMICOLON    { ASTString *name = (ASTString *)$3;
  137.                                       ASTFloat *val = (ASTFloat *)$6;
  138.                                       val->set_negative(true);
  139.                                       $$ = new ASTConstDecl(name->getValue(), val,@1);
  140.                                       delete name;
  141.                                     }
  142.     */
  143.  
  144. Case Decl : CASE NUMBER COLON {ASTString *name = (ASTString *)$3;
  145.     | CASE IDENTIFIER COLON {ASTString *name = (ASTString *)$3;
  146.    
  147.  
  148. SwitchStmt : SWITCH LPAREN Expr RPAREN Stmt {ASTExpr *cond = (ASTExpr *)$3;
  149.                                            ASTStmt *stmt = (ASTStmt *)$5;
  150.                                            $$ = new ASTStmtWhile(cond,stmt,@1);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement