-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLexer.l
131 lines (113 loc) · 3.5 KB
/
Lexer.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%{
/*
// Copyright (c) 2002 Tweak Films
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <WFObj/generated/Grammar.h>
#include <WFObj/Reader.h>
/* Redefine input and output so it can come from an iostream somewhere */
#define YY_INPUT(b,r,ms) (r = WFObjInput(b,ms))
//#define YY_ALWAYS_INTERACTIVE 1
#define YY_NO_UNPUT 1
#define yylval wfobjlval
#define yydebug wfobjdebug
#define yyparse wfobjparse
#define yyLineNum wfobjLineNum
#define yyReader wfobjReader
#define yyInputStream wfobjInputStream
#define YY_NO_UNISTD_H
extern int isatty (int );
using namespace std;
int yyparse();
int yyLineNum;
extern int yydebug;
extern WFObj::Reader* yyReader;
istream * yyInputStream;
int WFObjInput(char *buffer, int max_size);
void WFObjParse(istream &i);
%}
%option always-interactive
%option prefix="wfobj"
WhiteSpace [[:blank:]]+
FloatPart [0-9]+\.?[0-9]*
FloatExp [eE][-+]?[0-9]+
IntNum -?[0-9]+
Name [a-zA-Z0-9_.]+
%x continuation
%%
^{WhiteSpace}?f |
^{WhiteSpace}?fo { return FACE; }
^{WhiteSpace}?l { return LINE; }
^{WhiteSpace}?p { return POINT; }
^{WhiteSpace}?v { return VERTEX; }
^{WhiteSpace}?vn { return VNORMAL; }
^{WhiteSpace}?vt { return VTEXTURE; }
^{WhiteSpace}?g { return GROUP; }
^{WhiteSpace}?s { return SGROUP; }
^{WhiteSpace}?o { return OGROUP; }
^{WhiteSpace}?bevel { return BEVEL; }
^{WhiteSpace}?c_interp { return CINTERP; }
^{WhiteSpace}?d_interp { return DINTERP; }
^{WhiteSpace}?usemtl { return USEMTL; }
^{WhiteSpace}?usemap { return USEMAP; }
^{WhiteSpace}?mtllib { return MTLLIB; }
^{WhiteSpace}?maplib { return MAPLIB; }
^{WhiteSpace}?lod { return LOD; }
^{WhiteSpace}?shadow_obj { return SHADOW_OBJ; }
^{WhiteSpace}?trace_obj { return TRACE_OBJ; }
^{WhiteSpace}?\$.* { /* assumed comment -- appears in some viewpoint models*/ }
"{%%debug%%}" { yydebug=1; }
{WhiteSpace} {}
-?{IntNum} { yylval._int = strtol(yytext,0,0); return INTEGER; }
-?{FloatPart}{FloatExp}? { yylval._float = atof(yytext);return SCALAR; }
-?{IntNum}{FloatExp} { yylval._float = atof(yytext);return SCALAR; }
{Name} { yylval._name = yytext; return NAME; }
"\\" { BEGIN(continuation); }
"\n" { return ENDLINE; }
#.* { /*comment*/ }
. { return *yytext; }
<continuation>{
. { BEGIN(0); /*scarf anything */ }
}
%%
int
WFObjInput(char *buffer, int max_size)
{
int count=0,sfail=0;
while (max_size && !(sfail=yyInputStream->fail()))
{
int c = yyInputStream->get();
if (c == EOF) { sfail=true; break; }
buffer[count++] = c;
max_size--;
}
if (sfail) buffer[count]=0;
return count;
}
void
WFObjParse(istream &i, WFObj::Reader *reader)
{
yyInputStream = &i;
yyLineNum = 1;
yyReader = reader;
int result = yyparse();
}
int yywrap() { return 1; }