157 lines
4.2 KiB
Plaintext
157 lines
4.2 KiB
Plaintext
|
|
%option nounput
|
|
%option bison-locations
|
|
|
|
%{
|
|
|
|
#include <string>
|
|
|
|
#include "nodes.h"
|
|
#include "parser.h"
|
|
#include "parser.tab.h"
|
|
|
|
#define YY_USER_ACTION yylloc->first_column += yyleng;
|
|
|
|
static std::string build_string;
|
|
|
|
%}
|
|
|
|
%x str
|
|
|
|
%%
|
|
|
|
\+ return PLUS;
|
|
- return MINUS;
|
|
\* return TIMES;
|
|
\/ return DIVIDE;
|
|
% return MOD;
|
|
\^ return POW;
|
|
= return ASSIGN;
|
|
== return EQUALS;
|
|
!= return NOTEQUALS;
|
|
\< return LESS;
|
|
\<= return LESSEQ;
|
|
\> return GREATER;
|
|
\>= return GREATEREQ;
|
|
&& return AND;
|
|
\|\| return OR;
|
|
! return NOT;
|
|
|
|
; return SEMICOLON;
|
|
: return COLON;
|
|
\? return QUESTION;
|
|
\$ return DOLLAR;
|
|
\. return DOT;
|
|
, return COMMA;
|
|
|
|
\{ return LCURLY;
|
|
\} return RCURLY;
|
|
\[ return LBRACKET;
|
|
\] return RBRACKET;
|
|
\( return LPAREN;
|
|
\) return RPAREN;
|
|
|
|
[0-9]+ *yylval = new NumberNode(atof(yytext)); return REAL_NUMBER;
|
|
[0-9]*\.[0-9]+ *yylval = new NumberNode(atof(yytext)); return REAL_NUMBER;
|
|
|
|
ambient return AMBIENT;
|
|
ambient_occlusion return AMBIENT_OCCLUSION;
|
|
box return BOX;
|
|
camera return CAMERA;
|
|
color return COLOR;
|
|
cyl return CYL;
|
|
define return DEFINE;
|
|
diffuse return DIFFUSE;
|
|
exposure return EXPOSURE;
|
|
extrude return EXTRUDE;
|
|
height return HEIGHT;
|
|
intersect return INTERSECT;
|
|
jitter return JITTER;
|
|
light return LIGHT;
|
|
look_at return LOOKAT;
|
|
material return MATERIAL;
|
|
max_depth return MAXDEPTH;
|
|
multisample return MULTISAMPLE;
|
|
ngon return NGON;
|
|
offset return OFFSET;
|
|
options return OPTIONS;
|
|
plane return PLANE;
|
|
polygon return POLYGON;
|
|
position return POSITION;
|
|
radius return RADIUS;
|
|
reflectance return REFLECTANCE;
|
|
refraction return REFRACTION;
|
|
rotate return ROTATE;
|
|
scale return SCALE;
|
|
scene return SCENE;
|
|
shape return SHAPE;
|
|
shininess return SHININESS;
|
|
size return SIZE;
|
|
specular return SPECULAR;
|
|
sphere return SPHERE;
|
|
subtract return SUBTRACT;
|
|
texture return TEXTURE;
|
|
translate return TRANSLATE;
|
|
transparency return TRANSPARENCY;
|
|
union return UNION;
|
|
up return UP;
|
|
vfov return VFOV;
|
|
width return WIDTH;
|
|
|
|
else return ELSE;
|
|
elsif return ELSIF;
|
|
for return FOR;
|
|
if return IF;
|
|
while return WHILE;
|
|
local return LOCAL;
|
|
|
|
[a-zA-Z_][a-zA-Z_0-9]* {
|
|
*yylval = new IdentifierNode(yytext);
|
|
return IDENTIFIER;
|
|
}
|
|
\$[a-zA-Z_][a-zA-Z_0-9]* {
|
|
*yylval = new VarRefNode(yytext+1);
|
|
return VARREF;
|
|
}
|
|
|
|
#.*\n {
|
|
yylloc->first_line++; yylloc->last_line++;
|
|
yylloc->first_column = yylloc->last_column = 0;
|
|
}
|
|
\n {
|
|
yylloc->first_line++; yylloc->last_line++;
|
|
yylloc->first_column = yylloc->last_column = 0;
|
|
}
|
|
[ \t\v] /* ignore whitespace */
|
|
|
|
/* strings */
|
|
\" build_string = ""; BEGIN(str);
|
|
|
|
<str>{
|
|
|
|
\" {
|
|
/* end of the string literal */
|
|
BEGIN(INITIAL);
|
|
*yylval = new IdentifierNode(build_string);
|
|
return STRING;
|
|
}
|
|
\\x[0-9A-Fa-f]{2} {
|
|
/* hexadecimal escape code */
|
|
unsigned int val;
|
|
(void) sscanf(yytext + 2, "%x", &val);
|
|
build_string += (char) val;
|
|
}
|
|
\\n build_string += '\n';
|
|
\\t build_string += '\t';
|
|
\\r build_string += '\r';
|
|
\\b build_string += '\b';
|
|
\\f build_string += '\f';
|
|
\\(.|\n) build_string += yytext[1];
|
|
[^\\\"]+ build_string += yytext;
|
|
|
|
}
|
|
|
|
. return yytext[0];
|
|
|
|
%%
|