home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / lex.l < prev    next >
Text File  |  1992-11-02  |  6KB  |  205 lines

  1. %{
  2. /*
  3.  * lex.l - lexical analyser for graphtal.
  4.  *
  5.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #include <math.h>
  20.  
  21. #include "rcString.h"
  22. #include "LSystem.h"
  23. #include "Value.h"
  24. #include "Hull.h"
  25. #include "yacc.tab.h"
  26. #include "yyerror.h"
  27.  
  28. int lineno = 1;
  29. %}
  30.  
  31. %x C_COMMENT CPP_COMMENT EXTFILE
  32.  
  33. DIGIT            [0-9]
  34. E                [Ee][+-]?{DIGIT}+
  35. LETTER           [a-zA-Z_]
  36. SPECIAL          [\.\_-]
  37. STRING           {LETTER}({LETTER}|{DIGIT}|{SPECIAL})*
  38. FILENAME         "/"{0,2}(("."|".."|{STRING})"/")*{STRING}
  39.           
  40.  
  41. %%
  42.  
  43. ^#          BEGIN(EXTFILE);
  44. <EXTFILE>{DIGIT}+    lineno = atoi(yytext); 
  45. <EXTFILE>{FILENAME}  currentFilename = yytext; 
  46. <EXTFILE>.           ;
  47. <EXTFILE>\n       BEGIN 0;
  48.  
  49. "/*"        BEGIN(C_COMMENT);
  50. "//"        BEGIN(CPP_COMMENT); 
  51.  
  52. ","        { return *yytext; }   
  53. ";"        { return *yytext; }  
  54. "="        { return *yytext; }
  55. "("        { return *yytext; }
  56. ")"        { return *yytext; }
  57. "["        { return *yytext; }
  58. "]"        { return *yytext; }
  59. "{"        { return *yytext; }
  60. "}"        { return *yytext; }
  61. "+"        { return *yytext; }
  62. "-"        { return *yytext; }
  63. "*"        { return *yytext; }
  64. "/"        { return *yytext; }
  65. "%"        { return *yytext; }
  66. "!"        { return *yytext; }
  67. ":"       { return *yytext; }
  68. "^"       { return *yytext; }
  69. "&"       { return *yytext; }
  70. "\\"       { return *yytext; }
  71. "|"       { return *yytext; }
  72. "$"       { return *yytext; }
  73. "."       { return *yytext; }
  74. "~"       { return *yytext; }
  75.  
  76. "::"       { return tSCOPE;  }
  77. "**"       { return tPOW;    }
  78. "&&"       { return tAND;    }
  79. "||"       { return tOR;     }        
  80. "=="       { return tEQ;     }    
  81. "!="       { return tNEQ;    } 
  82. ">="       { return tGEQ;    } 
  83. "<="       { return tLEQ;    } 
  84. "<"       { return *yytext; }
  85. ">"       { return *yytext; }
  86. "->"       { return tARROW;  } 
  87.  
  88. sin       { return tSIN;   }
  89. cos       { return tCOS;   }   
  90. tan       { return tTAN;   } 
  91. asin       { return tASIN;  } 
  92. acos       { return tACOS;  } 
  93. atan       { return tATAN;  } 
  94. abs       { return tABS;   }
  95. sqrt       { return tSQRT;  }
  96. exp       { return tEXP;   }
  97. log       { return tLOG;   }
  98. log10       { return tLOG10; }
  99. rand       { return tRAND;  }
  100. gauss      { return tGAUSS; }
  101. if         { return tIF;    }
  102.  
  103. M_PI    { yylval.value = new Value(M_PI);    return tVALUE; }
  104. M_PI_2  { yylval.value = new Value(M_PI_2);  return tVALUE; }
  105. M_PI_4  { yylval.value = new Value(M_PI_4);  return tVALUE; }
  106. M_E    { yylval.value = new Value(M_E);     return tVALUE; }
  107. M_SQRT2 { yylval.value = new Value(M_SQRT2); return tVALUE; }
  108. M_LN2    { yylval.value = new Value(M_LN2);   return tVALUE; }
  109. M_LN10  { yylval.value = new Value(M_LN10);  return tVALUE; }
  110. true    { yylval.value = new Value(1.0);     return tVALUE; }
  111. false   { yylval.value = new Value(0.0);     return tVALUE; }
  112. tx      { return tTURTLEX; }
  113. ty      { return tTURTLEY; }
  114. tz      { return tTURTLEZ; }
  115.  
  116. infinity    { return tINFINITY; } 
  117.  
  118. lsystem     { return tLSYSTEM; }
  119. table        { return tTABLE; } 
  120. const        { return tCONST; }  
  121. attributes  { return tATTRIBUTES; }
  122. derivation  { return tDERIVATION; }
  123. axiom        { return tAXIOM; }
  124. pitch        { return tPITCH; }
  125. roll        { return tROLL; }
  126. turn        { return tTURN;    }
  127. angle       { return tANGLE; }
  128. forward     { return tFORWARD; }
  129. randomize   { return tRANDOMIZE; }
  130. tropism     { return tTROPISM; }
  131. weight      { return tWEIGHT; }
  132. eye         { return tEYE; }
  133. lookat      { return tLOOKAT; }
  134. up          { return tUP; }
  135. fov         { return tFOV; }
  136.  
  137. hull        { return tHULL;     }
  138. sphere      { return tSPHERE;   }
  139. triangle    { return tTRIANGLE; }
  140. plane       { return tPLANE;    }
  141. cylinder    { return tCYLINDER; }
  142. cone        { return tCONE;     }
  143. coneres     { return tCONERES;  }
  144. sphereres   { return tSPHERERES;}
  145.  
  146. translate   { return tTRANSLATE; }
  147. scale       { return tSCALE;     }
  148. rotate      { return tROTATE;    }
  149. transform   { return tTRANSFORM; }
  150.  
  151. {LETTER}({LETTER}|{DIGIT})*/([ \t]*=[^=]) {
  152.                  yylval.name = new rcString(yytext);
  153.                  return tCONSTANT; 
  154.                   }
  155.  
  156. {LETTER}({LETTER}|{DIGIT})*   { yylval.name = new rcString(yytext);
  157.                 return tNAME; 
  158.                   }
  159.  
  160. \"([^\n\"])*\" { rcString str(yytext);
  161.          yylval.value = new Value(str(1, str.length()-1));
  162.                  return tVALUE;
  163.                }
  164.  
  165. {DIGIT}*"."{DIGIT}+({E})? |
  166. {DIGIT}+"."{DIGIT}*({E})? |
  167. {DIGIT}+({E})? {
  168.                  yylval.value = new Value(atof(yytext));
  169.                  return tVALUE;
  170.            }
  171.  
  172. [ \t]+        ;
  173.  
  174. \n            lineno++;
  175.  
  176. .             { // eat the bad characters 
  177.                 cerr << "[WARNING] : '" << *yytext 
  178.              << "' is a bad character found at line "
  179.                      << lineno << "\n";
  180.               }
  181.  
  182.  
  183. <C_COMMENT>"*/"       BEGIN(0);
  184. <C_COMMENT>"/*"       {
  185.                         yyerror("Found '/*' while looking for '*/'");
  186.                         BEGIN(0);
  187.                       }
  188. <C_COMMENT>\n         lineno++;
  189. <C_COMMENT>.          ;
  190. <C_COMMENT><<EOF>>    {
  191.                         yyerror("EOF while looking for '*/'");
  192.                         BEGIN(0);
  193.                       }
  194.  
  195. <CPP_COMMENT>\n       {
  196.                         lineno++;
  197.                         BEGIN(0);
  198.               }
  199. <CPP_COMMENT>.        ;
  200. <CPP_COMMENT><<EOF>>  {
  201.                         yyerror("Unexpected EOF");
  202.                         BEGIN(0);
  203.                       }
  204. %% 
  205.