1 %{
2 /**************************************************************************\
3  * Copyright (c) Kongsberg Oil & Gas Technologies AS
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 \**************************************************************************/
33 
34 #ifndef COIN_INTERNAL
35 #error this is a private header file
36 #endif /* !COIN_INTERNAL */
37 
38 /*
39  * Lexical scanner for SoCalculator. Compile into lexical scanner
40  * lex.so_eval.c with
41  *
42  *             flex -oso_eval.ic -L evaluator.l
43  *
44  * (Note: flex version should be 2.5.4, since this is what is
45  * installed on nfs.sim.no).
46  *
47  * Flex 2.5.4 generates code that includes unitstd.h. unistd.h does
48  * not exist on the windows platform. You therefore need to apply
49  * a patch after running flex:
50  *
51  *             patch -p0 < so_eval.diff
52  *
53  */
54 
55 #include <Inventor/C/basic.h>
56 #include <float.h>
57 #include <stdlib.h>
58 #include "engines/evaluator.h"
59 %}
60 
61 %option noyywrap
62 %option prefix="so_eval"
63 
64 Digit                           [0-9]
65 Space                           [ \t\n]
66 Exp                             [eE][+-]?{Digit}+
67 
68 %%
69 {Space}+                        ;
70 "<="                            { yylval.id = ID_LEQ; return LEX_COMPARE; }
71 ">="                            { yylval.id = ID_GEQ; return LEX_COMPARE; }
72 "<"                             { yylval.id = ID_LT; return LEX_COMPARE; }
73 ">"                             { yylval.id = ID_GT; return LEX_COMPARE; }
74 "=="                            return LEX_EQ;
75 "!="                            return LEX_NEQ;
76 "&&"                            return LEX_AND;
77 "||"                            return LEX_OR;
78 "-"                             return '-';
79 [!+*/=\[\]%?:(),;]              return(yytext[0]);
80 MAXFLOAT                        { yylval.value = FLT_MAX; return LEX_VALUE; }
81 MINFLOAT                        { yylval.value = FLT_MIN; return LEX_VALUE; }
82 M_E                             { yylval.value = (float)M_E; return LEX_VALUE; }
83 M_LOG2E                         { yylval.value = (float)M_LOG2E; return LEX_VALUE; }
84 M_LOG10E                        { yylval.value = (float)M_LOG10E; return LEX_VALUE; }
85 M_LN2                           { yylval.value = (float)M_LN2; return LEX_VALUE; }
86 M_PI                            { yylval.value = (float)M_PI; return LEX_VALUE; }
87 M_SQRT2                         { yylval.value = (float)M_SQRT2; return LEX_VALUE; }
88 M_SQRT1_2                       { yylval.value = (float)M_SQRT1_2; return LEX_VALUE; }
89 cos                             { yylval.id = ID_COS; return LEX_FLTFUNC; }
90 sin                             { yylval.id = ID_SIN; return LEX_FLTFUNC; }
91 tan                             { yylval.id = ID_TAN; return LEX_FLTFUNC; }
92 acos                            { yylval.id = ID_ACOS; return LEX_FLTFUNC; }
93 asin                            { yylval.id = ID_ASIN; return LEX_FLTFUNC; }
94 atan                            { yylval.id = ID_ATAN; return LEX_FLTFUNC; }
95 atan2                           return LEX_ATAN2;
96 cosh                            { yylval.id = ID_COSH; return LEX_FLTFUNC; }
97 sinh                            { yylval.id = ID_SINH; return LEX_FLTFUNC; }
98 tanh                            { yylval.id = ID_TANH; return LEX_FLTFUNC; }
99 sqrt                            { yylval.id = ID_SQRT; return LEX_FLTFUNC; }
100 pow                             return LEX_POW;
101 exp                             { yylval.id = ID_EXP; return LEX_FLTFUNC; }
102 log                             { yylval.id = ID_LOG; return LEX_FLTFUNC; }
103 log10                           { yylval.id = ID_LOG10; return LEX_FLTFUNC; }
104 ceil                            { yylval.id = ID_CEIL; return LEX_FLTFUNC; }
105 floor                           { yylval.id = ID_FLOOR; return LEX_FLTFUNC; }
106 fabs                            { yylval.id = ID_FABS; return LEX_FLTFUNC; }
107 fmod                            return LEX_FMOD;
108 rand                            { yylval.id = ID_RAND; return LEX_FLTFUNC; }
109 cross                           { return LEX_CROSS; }
110 dot                             { return LEX_DOT; }
111 length                          { return LEX_LEN; }
112 normalize                       { return LEX_NORMALIZE; }
113 vec3f                           { return LEX_VEC3F; }
114 {Digit}*"."{Digit}*{Exp}?  { yylval.value = (float)atof(yytext); return LEX_VALUE; }
115 {Digit}+{Exp}?             { yylval.value = (float)atof(yytext); return LEX_VALUE; }
116 t[a-h]                          { yylval.reg = yytext[1]; return LEX_TMP_FLT_REG; }
117 o[a-d]                          { yylval.reg = yytext[1]; return LEX_OUT_FLT_REG; }
118 [a-h]                           { yylval.reg = yytext[0]; return LEX_IN_FLT_REG; }
119 t[A-H]                          { yylval.reg = yytext[1]; return LEX_TMP_VEC_REG; }
120 o[A-D]                          { yylval.reg = yytext[1]; return LEX_OUT_VEC_REG; }
121 [A-H]                           { yylval.reg = yytext[0]; return LEX_IN_VEC_REG; }
122 .                               { return LEX_ERROR; }
123 %%
124