home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Photo CD Demo 1
/
Demo.bin
/
graphtal
/
lex.l
< prev
next >
Wrap
Text File
|
1992-11-02
|
6KB
|
205 lines
%{
/*
* lex.l - lexical analyser for graphtal.
*
* Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
* All rights reserved.
*
* This software may be freely copied, modified, and redistributed
* provided that this copyright notice is preserved on all copies.
*
* You may not distribute this software, in whole or in part, as part of
* any commercial product without the express consent of the authors.
*
* There is no warranty or other guarantee of fitness of this software
* for any purpose. It is provided solely "as is".
*
*/
#include <math.h>
#include "rcString.h"
#include "LSystem.h"
#include "Value.h"
#include "Hull.h"
#include "yacc.tab.h"
#include "yyerror.h"
int lineno = 1;
%}
%x C_COMMENT CPP_COMMENT EXTFILE
DIGIT [0-9]
E [Ee][+-]?{DIGIT}+
LETTER [a-zA-Z_]
SPECIAL [\.\_-]
STRING {LETTER}({LETTER}|{DIGIT}|{SPECIAL})*
FILENAME "/"{0,2}(("."|".."|{STRING})"/")*{STRING}
%%
^# BEGIN(EXTFILE);
<EXTFILE>{DIGIT}+ lineno = atoi(yytext);
<EXTFILE>{FILENAME} currentFilename = yytext;
<EXTFILE>. ;
<EXTFILE>\n BEGIN 0;
"/*" BEGIN(C_COMMENT);
"//" BEGIN(CPP_COMMENT);
"," { return *yytext; }
";" { return *yytext; }
"=" { return *yytext; }
"(" { return *yytext; }
")" { return *yytext; }
"[" { return *yytext; }
"]" { return *yytext; }
"{" { return *yytext; }
"}" { return *yytext; }
"+" { return *yytext; }
"-" { return *yytext; }
"*" { return *yytext; }
"/" { return *yytext; }
"%" { return *yytext; }
"!" { return *yytext; }
":" { return *yytext; }
"^" { return *yytext; }
"&" { return *yytext; }
"\\" { return *yytext; }
"|" { return *yytext; }
"$" { return *yytext; }
"." { return *yytext; }
"~" { return *yytext; }
"::" { return tSCOPE; }
"**" { return tPOW; }
"&&" { return tAND; }
"||" { return tOR; }
"==" { return tEQ; }
"!=" { return tNEQ; }
">=" { return tGEQ; }
"<=" { return tLEQ; }
"<" { return *yytext; }
">" { return *yytext; }
"->" { return tARROW; }
sin { return tSIN; }
cos { return tCOS; }
tan { return tTAN; }
asin { return tASIN; }
acos { return tACOS; }
atan { return tATAN; }
abs { return tABS; }
sqrt { return tSQRT; }
exp { return tEXP; }
log { return tLOG; }
log10 { return tLOG10; }
rand { return tRAND; }
gauss { return tGAUSS; }
if { return tIF; }
M_PI { yylval.value = new Value(M_PI); return tVALUE; }
M_PI_2 { yylval.value = new Value(M_PI_2); return tVALUE; }
M_PI_4 { yylval.value = new Value(M_PI_4); return tVALUE; }
M_E { yylval.value = new Value(M_E); return tVALUE; }
M_SQRT2 { yylval.value = new Value(M_SQRT2); return tVALUE; }
M_LN2 { yylval.value = new Value(M_LN2); return tVALUE; }
M_LN10 { yylval.value = new Value(M_LN10); return tVALUE; }
true { yylval.value = new Value(1.0); return tVALUE; }
false { yylval.value = new Value(0.0); return tVALUE; }
tx { return tTURTLEX; }
ty { return tTURTLEY; }
tz { return tTURTLEZ; }
infinity { return tINFINITY; }
lsystem { return tLSYSTEM; }
table { return tTABLE; }
const { return tCONST; }
attributes { return tATTRIBUTES; }
derivation { return tDERIVATION; }
axiom { return tAXIOM; }
pitch { return tPITCH; }
roll { return tROLL; }
turn { return tTURN; }
angle { return tANGLE; }
forward { return tFORWARD; }
randomize { return tRANDOMIZE; }
tropism { return tTROPISM; }
weight { return tWEIGHT; }
eye { return tEYE; }
lookat { return tLOOKAT; }
up { return tUP; }
fov { return tFOV; }
hull { return tHULL; }
sphere { return tSPHERE; }
triangle { return tTRIANGLE; }
plane { return tPLANE; }
cylinder { return tCYLINDER; }
cone { return tCONE; }
coneres { return tCONERES; }
sphereres { return tSPHERERES;}
translate { return tTRANSLATE; }
scale { return tSCALE; }
rotate { return tROTATE; }
transform { return tTRANSFORM; }
{LETTER}({LETTER}|{DIGIT})*/([ \t]*=[^=]) {
yylval.name = new rcString(yytext);
return tCONSTANT;
}
{LETTER}({LETTER}|{DIGIT})* { yylval.name = new rcString(yytext);
return tNAME;
}
\"([^\n\"])*\" { rcString str(yytext);
yylval.value = new Value(str(1, str.length()-1));
return tVALUE;
}
{DIGIT}*"."{DIGIT}+({E})? |
{DIGIT}+"."{DIGIT}*({E})? |
{DIGIT}+({E})? {
yylval.value = new Value(atof(yytext));
return tVALUE;
}
[ \t]+ ;
\n lineno++;
. { // eat the bad characters
cerr << "[WARNING] : '" << *yytext
<< "' is a bad character found at line "
<< lineno << "\n";
}
<C_COMMENT>"*/" BEGIN(0);
<C_COMMENT>"/*" {
yyerror("Found '/*' while looking for '*/'");
BEGIN(0);
}
<C_COMMENT>\n lineno++;
<C_COMMENT>. ;
<C_COMMENT><<EOF>> {
yyerror("EOF while looking for '*/'");
BEGIN(0);
}
<CPP_COMMENT>\n {
lineno++;
BEGIN(0);
}
<CPP_COMMENT>. ;
<CPP_COMMENT><<EOF>> {
yyerror("Unexpected EOF");
BEGIN(0);
}
%%