1 %top{
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 /* Run 'flex eval-coin.l' to generate the compilable source files */
35 
36 #include <cmath>
37 #include <cfloat>
38 #include "soscxml/eval-coin.h"
39 #ifndef SCXML_COIN_OP_ADD
40 #include "soscxml/eval-coin-tab.hpp"
41 #else
42 #endif // !SCXML_COIN_OP_ADD
43 }
44 
45 %option outfile="eval-coin.cpp"
46 %option prefix="scxml_coin_"
47 %option case-sensitive
48 %option never-interactive
49 %option noyywrap
50 %option nounput
51 %option noinput
52 
53 DIGIT               [0123456789]
54 DIGITS              ({DIGIT})+
55 LETTER              [aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ]
56 LETTERS             ({LETTER})+
57 
58 SIGN                ([+-])?
59 EXP                 [eE]{SIGN}{DIGITS}
60 FLOAT               {SIGN}{DIGITS}("."{DIGITS})?({EXP})?
61 WHITE               [ \t]*
62 WS                  [ \t]{WHITE}
63 LINE                [^\n]*
64 
65 ID                  {LETTER}({LETTER}|{DIGIT}|[_])*("()")?
66 MLID                {ID}("."{ID})*
67 
68 TRUE                ("TRUE"|"True"|"true")
69 FALSE               ("FALSE"|"False"|"false")
70 EVENTSCOPE          "_event."
71 DATASCOPE           "_data."
72 CAMERASCOPE         "coin:camera."
73 
74 %%
75 
76 {WS}                { }
77 {TRUE}              { return SCXML_COIN_BOOL_TRUE; }
78 {FALSE}             { return SCXML_COIN_BOOL_FALSE; }
79 {FLOAT}             { scxml_coin_lval.real = atof(yytext); return SCXML_COIN_REAL; }
80 M_PI                { scxml_coin_lval.real = M_PI; return SCXML_COIN_REAL; }
81 M_PI_2              { scxml_coin_lval.real = M_PI_2; return SCXML_COIN_REAL; }
82 FLT_MAX             { scxml_coin_lval.real = FLT_MAX; return SCXML_COIN_REAL; }
83 FLT_MIN             { scxml_coin_lval.real = FLT_MIN; return SCXML_COIN_REAL; }
84 M_E                 { scxml_coin_lval.real = M_E; return SCXML_COIN_REAL; }
85 M_LOG2E             { scxml_coin_lval.real = M_LOG2E; return SCXML_COIN_REAL; }
86 M_LOG10E            { scxml_coin_lval.real = M_LOG10E; return SCXML_COIN_REAL; }
87 M_LN2               { scxml_coin_lval.real = M_LN2; return SCXML_COIN_REAL; }
88 M_SQRT2             { scxml_coin_lval.real = M_SQRT2; return SCXML_COIN_REAL; }
89 M_SQRT1_2           { scxml_coin_lval.real = M_SQRT1_2; return SCXML_COIN_REAL; }
90 Sb[^(]*"("[^)]*")"  { scxml_coin_lval.stringptr = yytext; return SCXML_COIN_SBVALUE; }
91 "'"[^']*"'"         { scxml_coin_lval.stringptr = yytext; return SCXML_COIN_STRING; }
92 "("                 { return SCXML_COIN_PAREN_OPEN; }
93 ")"                 { return SCXML_COIN_PAREN_CLOSE; }
94 
95 In                  { return SCXML_COIN_IN_FUNC; }
96 Length              { return SCXML_COIN_LENGTH_FUNC; }
97 _event"."{MLID}     { scxml_coin_lval.stringptr = yytext;
98                       return SCXML_COIN_IDENTIFIER; }
99 _data"."{ID}        { scxml_coin_lval.stringptr = yytext;
100                       return SCXML_COIN_IDENTIFIER; }
101 coin:camera"."{MLID} { scxml_coin_lval.stringptr = yytext;
102                       return SCXML_COIN_IDENTIFIER; }
103 coin:temp"."{ID}    { scxml_coin_lval.stringptr = yytext;
104                       return SCXML_COIN_IDENTIFIER; }
105 {ID}                { scxml_coin_lval.stringptr = yytext;
106                       return SCXML_COIN_IDENTIFIER; }
107 
108 "=="                { return SCXML_COIN_OP_EQUALS; }
109 "!="                { return SCXML_COIN_OP_NOT_EQUALS; }
110 "||"                { return SCXML_COIN_OP_OR; }
111 "&&"                { return SCXML_COIN_OP_AND; }
112 "+"                 { return SCXML_COIN_OP_ADD; }
113 "-"                 { return SCXML_COIN_OP_SUBTRACT; }
114 "*"                 { return SCXML_COIN_OP_MULTIPLY; }
115 "/"                 { return SCXML_COIN_OP_DIVIDE; }
116 "!"                 { return SCXML_COIN_OP_NOT; }
117 
118  /* <<EOF>>             { return SCXML_COIN_END; } */
119 
120 %%
121 
122 
123 int
124 scxml_coin_error(const char * error)
125 {
126   printf("\nscxml_coin error: %s\n", error);
127   return 0;
128 }
129 
130 ScXMLDataObj *
131 scxml_coin_parse(const char * buffer)
132 {
133   YY_BUFFER_STATE yybuf = scxml_coin__scan_string(buffer);
134   scxml_coin__switch_to_buffer(yybuf);
135   scxml_coin_parse(); // the bison function
136   scxml_coin__delete_buffer(yybuf);
137   ScXMLDataObj * dataobj = scxml_coin_get_root_obj();
138   scxml_coin_clear_root_obj();
139   return dataobj;
140 }
141 
142