ZoriaRPG

ffscript.lpp build 6

Dec 7th, 2016
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  use this file to generate lex.yy.c
  3. command: flex -B -olex.yy.cpp ffscript.lpp
  4.  
  5. Rev 2016-v24 : 18JUNE2016
  6. This file needs reorganisation, to structure the proposed additions into chapters.
  7. */
  8.  
  9. //We need GetPointer() as a function to return the internal pointer ID of any type.
  10. //used as int x = n->GetPointer(); to typecast the pointer from a custom type to x.
  11.  
  12. %option yylineno
  13. %option noyywrap
  14. %option never-interactive
  15. WS  [ \t\n\r]
  16.  
  17. %{
  18. #include <stdlib.h>
  19. #include "AST.h"
  20. #include "../zsyssimple.h"
  21. #include "y.tab.hpp"
  22. YYLTYPE noloc = {0,0,0,0};
  23. void doLines();
  24. %}
  25.  
  26. %%
  27.  
  28. script                    { doLines();return SCRIPT; }
  29. float                 { doLines(); return FLOAT; }
  30. int                   { doLines(); return FLOAT; }
  31.  
  32. for               { doLines(); return FOR; }
  33. bool                  { doLines();return BOOL; }
  34. void                  { doLines();return VOID; }
  35. if                { doLines();return IF; }
  36. else                  { doLines();return ELSE; }
  37. return            { doLines();return RETURN; }
  38. c
  39. true                  { doLines();return TRUE; }
  40. false                 { doLines();return FALSE; }
  41. while               {doLines(); return WHILE;}
  42. ffc                 {doLines(); return FFC;}
  43. itemdata            {doLines(); return ITEMCLASS;}
  44. item                {doLines(); return ITEM;}
  45. global              {doLines(); return GLOBAL;}
  46. break               {doLines(); return BREAK;}
  47. continue            {doLines(); return CONTINUE;}
  48. const               {doLines(); return CONST;}
  49. do                  {doLines(); return DO;}
  50. npc                 {doLines(); return NPC;}
  51. lweapon                 {doLines(); return LWEAPON;}
  52. eweapon                 {doLines(); return EWEAPON;}
  53. case    {doLines(); return CASE;}
  54. switch  {doLines(); return SWITCH;}
  55.  
  56.  
  57. [/*].*          { commentblock(); }
  58. \:      { doLieas(); return COLON; }
  59. \-\>        { doLines(); return ARROW;}
  60. \<\<=       { doLines(); return LSHIFTASSIGN; }
  61. \>\>=       { doLines(); return RSHIFTASSIGN; }
  62. \<\<        { doLines(); return LSHIFT; }
  63. \>\>        { doLines(); return RSHIFT; }
  64. \<=         { doLines();return LE; }
  65. \<          { doLines();return LT; }
  66. \>=         { doLines();return GE; }
  67. \>          { doLines();return GT; }
  68. ==          { doLines();return EQ; }
  69.  
  70. \!=         { doLines();return NE; }
  71. \=          { doLines();return ASSIGN; }
  72.  
  73. \+=         { doLines();return PLUSASSIGN; }
  74. \-=         { doLines();return MINUSASSIGN; }
  75. \*=         { doLines();return TIMESASSIGN; }
  76. \/=         { doLines();return DIVIDEASSIGN; }
  77. \&\&=       { doLines();return ANDASSIGN; }
  78. \|\|=       { doLines();return ORASSIGN; }
  79. \&=         { doLines();return BITANDASSIGN; }
  80. \|=         { doLines();return BITORASSIGN; }
  81. \^=         { doLines();return BITXORASSIGN; }
  82. \%=         { doLines();return MODULOASSIGN; }
  83. \;          { doLines();return SEMICOLON; }
  84. \,          { doLines();return COMMA; }
  85. \[          { doLines();return LBRACKET; }
  86. \]          { doLines();return RBRACKET; }
  87. \(          { doLines();return LPAREN; }
  88. \)          { doLines();return RPAREN; }
  89. \+\+        { doLines();return INCREMENT; }
  90. \-\-        { doLines();return DECREMENT; }
  91. \.          { doLines();return DOT; }
  92. \+          { doLines();return PLUS; }
  93. \-                { doLines();return MINUS; }
  94. \*          { doLines();return TIMES; }
  95. \/\/.*            { ; }
  96. \/                { doLines();return DIVIDE; }
  97. \{                { doLines();return LBRACE; }
  98. \}                { doLines();return RBRACE; }
  99. \&\&            { doLines();return AND; }
  100. \|\|            { doLines();return OR; }
  101.  
  102. \&              { doLines(); return BITAND; }
  103. \|              { doLines(); return BITOR; }
  104. \~              { doLines(); return BITNOT; }
  105. \^              { doLines(); return BITXOR; }
  106. \!          { doLines();return NOT; }
  107. \%          { doLines(); return MODULO; }
  108.  
  109.  
  110.  
  111.  
  112. // Additions to the symbol table that are usable:
  113.  
  114. \<\>            { doLines();return EQ; }
  115. \:\-        { doLines();return ASSIGN; }
  116. // \:\-\   { doLines(); return ARROW;}  //Deprecated to use as ASSIGN
  117. \:\:        { doLines(); return ARROW;} //This is to be replaced by RESCOPE
  118.  
  119.  
  120. //Token additions that should work.
  121.  
  122. SCRIPT                    { doLines();return SCRIPT; }
  123. FLOAT                 { doLines(); return FLOAT; }
  124. INT                   { doLines(); return FLOAT; }
  125.  
  126. FOR               { doLines(); return FOR; }
  127. BOOL                  { doLines();return BOOL; }
  128. VOID                  { doLines();return VOID; }
  129. IF                { doLines();return IF; }
  130. ELSE                  { doLines();return ELSE; }
  131. RETURN            { doLines();return RETURN; }
  132. IMPORT            { doLines();return IMPORT; }
  133. \#\i\m\p\o\r\t            { doLines();return IMPORT; }
  134. \#\I\M\P\O\R\T            { doLines();return IMPORT; }
  135. TRUE                  { doLines();return TRUE; }
  136. FALSE                 { doLines();return FALSE; }
  137. WHILE               {doLines(); return WHILE;}
  138. FFC                 {doLines(); return FFC;}
  139. ITEMDATA            {doLines(); return ITEMCLASS;}
  140. ITEM                {doLines(); return ITEM;}
  141. GLOBAL              {doLines(); return GLOBAL;}
  142. BREAK               {doLines(); return BREAK;}
  143. CONTINUE            {doLines(); return CONTINUE;}
  144. CONST               {doLines(); return CONST;}
  145. DO                  {doLines(); return DO;}
  146. NPC                 {doLines(); return NPC;}
  147. LWEAPON                 {doLines(); return LWEAPON;}
  148. EWEAPON                 {doLines(); return EWEAPON;}
  149.  
  150. and         { doLines();return AND; }
  151. or          { doLines();return OR; }
  152.  
  153. AND         { doLines();return AND; }
  154. OR          { doLines();return OR; }
  155.  
  156. //These may conflict with identifiers, and become useless, so we probably won;t use them
  157. not         { doLines();return NOT; }
  158. NOT         { doLines();return NOT; }
  159.  
  160.  
  161.  
  162. \#\i\n\c\l\u\d\e { doLines();return IMPORT; } //We need an actual include directive.
  163.  
  164.  
  165. /* Additions by ZoriaRPG
  166.  
  167. Note: New definitions need to be added to lex.yy.cpp
  168. The comments with line number refs in that file that ref lines in this
  169. file are now incorrect!
  170. We likely need to expand YY_NUM_RULES 79 to whatever number we eventually have as well.
  171. This is on line 293 of lex.yy.cpp
  172.  
  173. THe real 'fun' is modifying: static yyconst short int yy_acclist[276]
  174. yy_accept[174] =[174]
  175. etc.
  176. These hold yy_current_state and other values, I think, as redirects?
  177. I need to read more of the flex manual.
  178. */
  179.  
  180. /* These do not have a peroper case statement at present, or any handlers.
  181.  
  182. \!\<    {doLines(); return NOTLESS; }
  183. \!\>    {doLines(); return NOTGREATER; }
  184.  
  185. \!\<\=    {doLines(); return NOTLESSOREQUAL; }
  186. \!\>\=    {doLines(); return NOTGREATEROREQUAL; }
  187.  
  188. npcdata { doLines(); return NPCDATA; }
  189. NPCDATA { doLines(); return NPCDATA; }
  190.  
  191. setflag         { doLines();return SETFLAG; }
  192. setflagfalse    { doLines();return SETFLAGFALSE; }
  193. setflagtrue     { doLines();return SETFLAGTRUE; }
  194. setflagmore     { doLines();return SETFLAGMORE; }
  195. setflagless     { doLines();return SETFLAGLESS; }
  196. goto            { doLines();return GOTO; }
  197. gototrue        { doLines();return GOTOTRUE; }
  198. gotofalse       { doLines();return GOTOFALSE; }
  199. gotoless        { doLines();return GOTOLESS; }
  200. gotomore        { doLines();return GOTOMORE; }
  201.  
  202. arraytoindex    { doLines();return ARRAYTOINDEX; } //Store array in an index of another array..
  203.  
  204. POINTER         { doLines();return POINTER; }
  205.  
  206. SETFLAG         { doLines();return SETFLAG; }
  207. SETFLAGFALSE    { doLines();return SETFLAGFALSE; }
  208. SETFLAGTRUE     { doLines();return SETFLAGTRUE; }
  209. SETFLAGMORE     { doLines();return SETFLAGMORE; }
  210. SETFLAGLESS     { doLines();return SETFLAGLESS; }
  211. GOTO            { doLines();return GOTO; }
  212. GOTOTRUE        { doLines();return GOTOTRUE; }
  213. GOTOFALSE       { doLines();return GOTOFALSE; }
  214. GOTOLESS        { doLines();return GOTOLESS; }
  215. GOTOMORE        { doLines();return GOTOMORE; }
  216.  
  217. ARRAYTOINDEX    { doLines();return ARRAYTOINDEX; } //Store array in an index of another array..
  218.  
  219. POINTER         { doLines();return POINTER; }
  220.  
  221. until           { doLines(); return UNTIL; }
  222. UNTIL           { doLines(); return UNTIL; }
  223.  
  224. unless          { doLines(); return UNLESS; }
  225. UNLESS          { doLines(); return UNLESS; }
  226.  
  227. repeat          { doLines(); return REPEAT; }
  228. REPEAT          { doLines(); return REPEAT; }
  229.  
  230. switch          { doLines(); return SWITCH; }
  231. SWITCH          { doLines(); return SWITCH; }
  232.  
  233. begin          { doLines(); return BEGIN; }
  234. BEGIN          { doLines(); return BEGIN; }
  235.  
  236. end          { doLines(); return END; }
  237. END          { doLines(); return END; }
  238.  
  239. \#\d\e\f\i\n\e { doLines();return DEFINE; } //We need an actual include directive.
  240. \#\c\a\s\e{ doLines();return CASE; } //We need an actual include directive.
  241. case { doLines();return CASE; }
  242. CASE { doLines();return CASE; }
  243. /// char { doLines();return CHAR; }
  244. \#\c\h\a\r { doLines();return CHAR; }
  245. CHAR { doLines();return CHAR; }
  246. /// array { doLines();return NEWARRAY; } //This could be a problem if the parser reads something like '
  247. int array[]', picking uo the identifier 'array' as a token. :(
  248. \#\a\r\r\a\y { doLines();return NEWARRAY; }
  249. ARRAY { doLines();return NEWARRAY; }
  250. /// string { doLines();return NEWSTRING; } //For the same reason...
  251. \#\s\t\r\i\n\g { doLines();return NEWSTRING; }
  252. STRING { doLines();return NEWSTRING; }
  253.  
  254. obj                     {doLines(); return OBJECT;}
  255. object                     {doLines(); return OBJECT;}
  256. OBJ                     {doLines(); return OBJECT;}
  257. OBJECT                     {doLines(); return OBJECT;}
  258.  
  259. // 'int'type Integer that is automatically truncated
  260. igr                     {doLines(); return INTEGER; }
  261. IGR                     {doLines(); return INTEGER; }
  262.  
  263. //Signed integer types
  264. int8                    {doLines(); return SIGNEDINTEGER8BIT; }
  265. INT8                    {doLines(); return SIGNEDINTEGER8BIT; }
  266. int16                   {doLines(); return SIGNEDINTEGER16BIT; }
  267. INT16                   {doLines(); return SIGNEDINTEGER16BIT; }
  268. int32                   {doLines(); return SIGNEDINTEGER32BIT; }
  269. INT32                   {doLines(); return SIGNEDINTEGER32BIT; }
  270.  
  271. //Do we want to support 64b values? I don't even believe that we *can* do that.
  272. INT64                   {doLines(); return SIGNEDINTEGER64BIT; }
  273. int64                   {doLines(); return SIGNEDINTEGER64BIT; }
  274.  
  275. uint8                   {doLines(); return UNSIGNEDINTEGER8BIT; }
  276. UINT8                   {doLines(); return UNSIGNEDINTEGER8BIT; }
  277. uint16                  {doLines(); return UNSIGNEDINTEGER16BIT; }
  278. UINT16                  {doLines(); return UNSIGNEDINTEGER16BIT; }
  279. uint32                  {doLines(); return UNSIGNEDINTEGER32BIT; }
  280. UINT32                  {doLines(); return UNSIGNEDINTEGER32BIT; }
  281.  
  282. //Do we want to support 64b values? I don't even believe that we *can* do that.
  283. uint64                  {doLines(); return UNSIGNEDINTEGER64BIT; }
  284. UINT64                  {doLines(); return UNSIGNEDINTEGER64BIT; }
  285.  
  286. //Floating point values.
  287. float32                 {doLines(); return SIGNEDFLOAT32BIT; }
  288. FLOAT32                 {doLines(); return SIGNEDFLOAT32BIT; }
  289.  
  290. //Fix and Fixed
  291.  
  292. "signed fix"            {doLines(); return SIGNEDINTEGER32BIT; }
  293. "SIGNED FIX"            {doLines(); return SIGNEDINTEGER32BIT; }
  294. signed FIX              {doLines(); return SIGNEDINTEGER32BIT; }
  295. SIGNED fix              {doLines(); return SIGNEDINTEGER32BIT; }
  296. fix                     {doLines(); return SIGNEDINTEGER32BIT; }
  297.  
  298. "unsigned fix"            {doLines(); return UNSIGNEDINTEGER32BIT; }
  299. "UNSIGNED FIX"            {doLines(); return UNSIGNEDINTEGER32BIT; }
  300. "unsigned FIX"              {doLines(); return UNSIGNEDINTEGER32BIT; }
  301. "UNSIGNED fix"              {doLines(); return UNSIGNEDINTEGER32BIT; }
  302. ufix                     {doLines(); return UNSIGNEDINTEGER32BIT; }
  303.  
  304. "signed fixed"            {doLines(); return SIGNEDINTEGER32BIT; }
  305. "SIGNED FIXED"            {doLines(); return SIGNEDINTEGER32BIT; }
  306. "signed FIXED"              {doLines(); return SIGNEDINTEGER32BIT; }
  307. SIGNED fixed              {doLines(); return SIGNEDINTEGER32BIT; }
  308. fixed                     {doLines(); return SIGNEDINTEGER32BIT; }
  309.  
  310. "unsigned fixed"            {doLines(); return UNSIGNEDINTEGER32BIT; }
  311. "UNSIGNED FIXED"            {doLines(); return UNSIGNEDINTEGER32BIT; }
  312. "unsigned FIXED"              {doLines(); return UNSIGNEDINTEGER32BIT; }
  313. "UNSIGNED fixed"              {doLines(); return UNSIGNEDINTEGER32BIT; }
  314. ufixed                     {doLines(); return UNSIGNEDINTEGER32BIT; }
  315.  
  316. //Double
  317.  
  318. double                  {doLines(); return SIGNEDDOUBLE; }
  319. DOUBLE                  {doLines(); return SIGNEDDOUBLE; }
  320. udouble                  {doLines(); return UNSIGNEDDOUBLE; }
  321. UDOUBLE                  {doLines(); return UNSIGNEDDOUBLE; }
  322.  
  323. //More object tokens
  324. private             {doLines(); return PRIVATE; }
  325. PRIVATE             {doLines(); return PRIVATE; }
  326. get                 {doLines(); return GET; }
  327. GET                 {doLines(); return GET; }
  328.  
  329. //New types for numerical values
  330. \u\n\s\i\g\n\e\d\ \l\o\n\g   {doLines(); return UNSINGLEDLONG; }
  331. \u\n\s\i\g\n\e\d\ \i\n\t   {doLines(); return UNSINGLEDINT; }
  332. \u\n\s\i\g\n\e\d\ \f\l\o\a\t   {doLines(); return UNSINGLEDFLOAT; }
  333. \u\n\s\i\g\n\e\d\ \i\g\r   {doLines(); return UNSINGLEDIGR; }
  334.  
  335. \s\i\g\n\e\d\ \i\g\r  {doLines(); return SINGLEDIGR; }
  336.  
  337. \s\i\g\n\e\d\ \l\o\n\g   {doLines(); return SINGLEDLONG; }
  338. \s\i\g\n\e\d\ \i\n\t   {doLines(); return SINGLEDINT; }
  339. s\i\g\n\e\d\ \f\l\o\a\t   {doLines(); return SINGLEDFLOAT; }
  340.  
  341.  
  342.  
  343. \^\^            { doLines();return LOGICALXOR; }
  344. XOR         { doLines();return LOGICALXOR; }
  345. xor         { doLines();return LOGICALXOR; }
  346. // If we can add XOR, with a custom function, this would be nice.
  347.  
  348. //Other logical operators
  349. NOR         { doLines();return LOGICALNOR; }
  350. nor         { doLines();return LOGICALNOR; }
  351.  
  352. NAND            { doLines();return LOGICALNAND; }
  353. nand            { doLines();return LOGICALNAND; }
  354.  
  355. //Check if two things are identical. This is not the same as ==, but
  356. determines if two pointers are the same object, etc.
  357. //This is usedul for conversionto AngelScript for handles.
  358. IS          { doLines();return ISTHESAME; }
  359. is          { doLines();return ISTHESAME; }
  360.  
  361. ([*][_a-zA-Z])  {        doLines();
  362.                         yylval = new ASTString(yytext, yylloc);
  363.                         return USERPOINTER;
  364.                     }
  365.                    
  366. \?      { doLines(); return QMARK; }
  367.  
  368.  
  369. ///Loaads a quest into the present save file. as load "name.qst"
  370. LOAD              { doLines();return LOAD; }
  371. load              { doLines();return LOAD; }
  372. \#\l\o\a\d            { doLines();return LOAD; }
  373. \#L\O\A\D             { doLines();return LOAD; }
  374.  
  375. //Add comment blocks. We need a comment block function, for the parser.
  376. //Begin vomment block.
  377. \/\*.*             { ; } //We need to have a special { doLines(); return COMMENTBLOCK } routine here.
  378. //End comment block.
  379. \*\/             { ; } //We need to have a special { doLines(); return COMMENTBLOCK } routine here.
  380.  
  381.  
  382. // END SECTION
  383. */
  384.  
  385.  
  386. /* BEGIN DECTION
  387. \:\:        { doLines(); return RESSCOPE;}  This is for AngelScript compat. Note that if we
  388.                                             add scope resolution, we will need to change this
  389.                                             to reflect that addition. otherwise, we can use this
  390.                                             as a pointer dereferencing token. */
  391.                                            
  392.  
  393.  
  394. ([?]|[_a-zA-Z]|[0-9]|[@][$]+)([?]|[_a-zA-Z]|[0-9]|[@]|[$])*{
  395.                         doLines();
  396.                         yylval = new ASTString(yytext, yylloc);
  397.                         return IDENTIFIER;
  398.                     }
  399.        
  400. //Add * to the identifier class, but only if at the end of an identifier, and no other alpha
  401. //or numeric chars follow it. This should prevent it being mistaken for a MULTIPLY token.
  402.  
  403. ([?]|[_a-zA-Z]|[0-9]|[@][$]+)([?]|[_a-zA-Z]|[0-9]|[@]|[$])*[*^([?]|[_a-zA-Z]|[0-9]|[@][$]+)([?]|[_a-zA-Z]|[0-9]|[@]|[$])]
  404. {
  405.                         doLines();
  406.                         yylval = new ASTString(yytext, yylloc);
  407.                         return IDENTIFIER;
  408.                     }
  409.  
  410. /*
  411. [^([?]|[_a-zA-Z]|[0-9]|[@][$]+)([?]|[_a-zA-Z]|[0-9]|[@]|[$])*][*]([?]|[_a-zA-Z]|[0-9]|[@][$]+)([?]|[_a-zA-Z]|[0-9]|[@]|[$])*
  412. {                       doLines();
  413.                         yylval = new ASTString(yytext, yylloc);
  414.                         return USERPOINTER;
  415.                     }
  416. // END SECTION
  417. */
  418.  
  419. ([0-9]*\.?[0-9]+)       { doLines();yylval = new ASTFloat(yytext, ASTFloat::TYPE_DECIMAL, yylloc); return NUMBER; }
  420.  
  421. (0x[0-9a-fA-F]+)        { doLines();yylval = new ASTFloat(yytext, ASTFloat::TYPE_HEX, yylloc); return NUMBER; }
  422.  
  423. ([0-1]+b)               { doLines();yylval = new ASTFloat(yytext, ASTFloat::TYPE_BINARY, yylloc); return NUMBER; }
  424.  
  425. (o[0-7])                { doLines();yylval = new ASTFloat(yytext, ASTFloat::TYPE_OCTAL, yylloc); return NUMBER; }
  426.                         //We should add TYPE_OCTAL here, (and thus we need to define the return)
  427.  
  428.  
  429. \"[^\"]+\"              { doLines();yylval = new ASTString(yytext, yylloc); return QUOTEDSTRING; }
  430. \"\"                    { doLines();yylval = new ASTString(yytext, yylloc); return QUOTEDSTRING; }
  431.  
  432. //Is there a reason that an empty QUOTEDSTRING was not allowed?
  433.  
  434. \'[^\']?\'              { doLines();yylval = new ASTString(yytext, yylloc); return SINGLECHAR; }
  435.  
  436. [\x80-\xFF]             { ; }//ASCII chars above 127 register as Whitespace.
  437.  
  438. {WS}                    { ; } //Whitespace
  439.  
  440.  
  441. .       {
  442.     char temp[512];
  443.     sprintf(temp, "Scanner, line %d: lexical error '%s'.\n", yylineno, yytext);
  444.     box_out(temp);
  445.     box_eol();
  446.     }
  447. %%
  448. void resetLexer(){
  449. YY_FLUSH_BUFFER;
  450. yylineno=1;
  451. }
  452. void doLines()
  453. {
  454. YYLTYPE rval = {yylineno, 0, yylineno, 0};
  455. yylloc = rval;
  456. }
  457.  
  458.  
  459.  
  460. //void comment(void) {
  461. //  char c; prev = 0;
  462. //  while ( ( c = input() ) != 0 ) {
  463. //      if ( c == '/' && prev == '*' ) return;
  464. //      prev = c;
  465. //  }
  466. //  error("Unterminated Comment");
  467. //}
  468.  
  469. void commentblock(void) {
  470.     int c;
  471.    
  472.     while ( ( c = input() ) != 0 )
  473.         if  ( c == '*' ) {
  474.             while ( ( c = input() == '*' )
  475.                 ;
  476.             if ( c == '/' )
  477.                 return;
  478.             if ( c == 0 )
  479.                 break;
  480.         }
  481.         yyerror("unterminated comment");
  482. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×