00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 %{
00026
00027 #define YY_MAIN 0
00028 #define YY_NEVER_INTERACTIVE 1
00029
00030 #include <sstream>
00031 #include "lux.h"
00032 #include "api.h"
00033 #include "error.h"
00034
00035 struct ParamArray;
00036
00037 #include "luxparse.hpp"
00038
00039
00040
00041
00042
00043
00044
00045 #if defined(WIN32) && !defined(__CYGWIN__)
00046 #pragma warning ( disable: 4244 )
00047 #endif
00048
00049 struct IncludeInfo {
00050 string filename;
00051 YY_BUFFER_STATE bufState;
00052 int lineNum;
00053 };
00054 vector<IncludeInfo> includeStack;
00055
00056 extern int line_num;
00057 int str_pos;
00058
00059 void add_string_char( char c )
00060 {
00061 yylval.string[str_pos++] = c;
00062 yylval.string[str_pos] = '\0';
00063 }
00064
00065 extern void yyerror( const char *str );
00066
00067
00068 void include_push(char *filename) {
00069 if (includeStack.size() > 32)
00070 luxError(LUX_NESTING,LUX_SEVERE,"Only 32 levels of nested Include allowed in scene files.");
00071 IncludeInfo ii;
00072 extern string current_file;
00073 ii.filename = current_file;
00074 ii.bufState = YY_CURRENT_BUFFER;
00075 ii.lineNum = line_num;
00076 includeStack.push_back(ii);
00077
00078 current_file = filename;
00079 line_num = 1;
00080
00081 yyin = fopen(filename, "r");
00082 if (!yyin)
00083 {
00084
00085 std::stringstream ss;
00086 ss<<"Unable to open included scene file "<<filename;
00087 luxError(LUX_NOFILE,LUX_SEVERE,ss.str().c_str());
00088 }
00089 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
00090 }
00091
00092 void include_pop(void)
00093 {
00094 extern int line_num;
00095 extern string current_file;
00096 yy_delete_buffer(YY_CURRENT_BUFFER);
00097 yy_switch_to_buffer(includeStack.back().bufState);
00098 current_file = includeStack.back().filename;
00099 line_num = includeStack.back().lineNum;
00100 includeStack.pop_back();
00101 }
00102 %}
00103 %option nounput
00104 WHITESPACE [ \t\0xa]+
00105 NUMBER [-+]?([0-9]+|(([0-9]+\.[0-9]*)|(\.[0-9]+)))([eE][-+]?[0-9]+)?
00106 IDENT [a-zA-Z_][a-zA-Z_0-9]*
00107 %x STR COMMENT INCL INCL_FILE
00108 %%
00109 Include { BEGIN(INCL); }
00110 <INCL>{WHITESPACE} ;
00111 <INCL>\" { BEGIN(INCL_FILE); }
00112 <INCL>. { luxError( LUX_SYNTAX,LUX_SEVERE,"Illegal character following Include directive" ); }
00113 <INCL_FILE>\" { BEGIN INITIAL; }
00114 <INCL_FILE>. { luxError( LUX_SYNTAX,LUX_SEVERE,"Illegal character in Include file name" ); }
00115 <INCL_FILE>[\-a-zA-Z_\.0-9/ \t'\\\:]+ {
00116 BEGIN(INITIAL);
00117 include_push(yytext);
00118 }
00119 "#" { BEGIN COMMENT; }
00120 <COMMENT>. /* eat it up */
00121 <COMMENT>\n { line_num++; BEGIN INITIAL; }
00122 Accelerator { return ACCELERATOR; }
00123 AreaLightSource { return AREALIGHTSOURCE; }
00124 AttributeBegin { return ATTRIBUTEBEGIN; }
00125 AttributeEnd { return ATTRIBUTEEND; }
00126 Camera { return CAMERA; }
00127 ConcatTransform { return CONCATTRANSFORM; }
00128 CoordinateSystem { return COORDINATESYSTEM; }
00129 CoordSysTransform { return COORDSYSTRANSFORM; }
00130 Film { return FILM; }
00131 Identity { return IDENTITY; }
00132 LightSource { return LIGHTSOURCE; }
00133 LookAt { return LOOKAT; }
00134 Material { return MATERIAL; }
00135 MakeNamedMaterial { return MAKENAMEDMATERIAL; }
00136 NamedMaterial { return NAMEDMATERIAL; }
00137 ObjectBegin { return OBJECTBEGIN; }
00138 ObjectEnd { return OBJECTEND; }
00139 ObjectInstance { return OBJECTINSTANCE; }
00140 PixelFilter { return PIXELFILTER; }
00141 ReverseOrientation { return REVERSEORIENTATION; }
00142 Rotate { return ROTATE; }
00143 Sampler { return SAMPLER; }
00144 SearchPath { return SEARCHPATH; }
00145 Scale { return SCALE; }
00146 PortalShape { return PORTALSHAPE; }
00147 Shape { return SHAPE; }
00148 SurfaceIntegrator { return SURFACEINTEGRATOR; }
00149 Texture { return TEXTURE; }
00150 TransformBegin { return TRANSFORMBEGIN; }
00151 TransformEnd { return TRANSFORMEND; }
00152 Transform { return TRANSFORM; }
00153 Translate { return TRANSLATE; }
00154 Volume { return VOLUME; }
00155 VolumeIntegrator { return VOLUMEINTEGRATOR; }
00156 WorldBegin { return WORLDBEGIN; }
00157 WorldEnd { return WORLDEND; }
00158 {WHITESPACE} /* do nothing */
00159 \r /* jromang - do nothing */
00160 \n { line_num++; }
00161 {NUMBER} {
00162 yylval.num = (float) atof(yytext);
00163 return NUM;
00164 }
00165 {IDENT} {
00166 strcpy( yylval.string, yytext );
00167 return ID;
00168 }
00169 "[" { return LBRACK; }
00170 "]" { return RBRACK; }
00171 \" { BEGIN STR; str_pos = 0; }
00172 <STR>\\n {add_string_char('\n');}
00173 <STR>\\t {add_string_char('\t');}
00174 <STR>\\r {add_string_char('\r');}
00175 <STR>\\b {add_string_char('\b');}
00176 <STR>\\f {add_string_char('\f');}
00177 <STR>\\\" {add_string_char('\"');}
00178 <STR>\\\\ {add_string_char('\\');}
00179 <STR>\\[0-9]{3} {
00180 int val = atoi(yytext+1);
00181 while(val > 256)
00182 val -= 256;
00183 add_string_char(val);
00184 }
00185 <STR>\\\n {line_num++;}
00186 <STR>\\. { add_string_char(yytext[1]);}
00187 <STR>\" {BEGIN INITIAL; return STRING;}
00188 <STR>. {add_string_char(yytext[0]);}
00189 <STR>\n {luxError( LUX_SYNTAX,LUX_SEVERE,"Unterminated string!");}
00190
00191 . { std::stringstream ss; ss<<"Illegal character: "<<yytext[0]; luxError( LUX_SYNTAX,LUX_SEVERE,ss.str().c_str()); }
00192 %%
00193 int yywrap(void)
00194 {
00195 if (includeStack.size() ==0) return 1;
00196 include_pop();
00197 BEGIN(INCL_FILE);
00198 return 0;
00199 }
00200