Line data Source code
1 : %{ /* -*- C++ -*- */
2 : # include <cstdlib>
3 : # include <errno.h>
4 : # include <limits.h>
5 : # include <string>
6 : # include "Gspn-Reader.hpp"
7 : //# include "Gspn-parser.tab.hh"
8 :
9 :
10 : # undef yywrap
11 : # define yywrap() 1
12 :
13 : # define YY_DECL GSPN_DECL
14 :
15 : /* By default gspnlex returns int, we use token_type.
16 : Unfortunately gspnterminate by default returns 0, which is
17 : not of token_type. */
18 : #define yyterminate() return token::END
19 : #ifndef __clang_analyzer__
20 : %}
21 :
22 : %option noyywrap nounput batch debug
23 :
24 : STR [a-zA-Z][a-zA-Z_0-9]*
25 : INT [0-9]+|[0-9]*
26 : REAL ([0-9]+|[0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?
27 : blank [ \t]
28 :
29 :
30 : %{
31 : # define GSPN_USER_ACTION gspnlloc->columns (gspnleng);
32 : %}
33 : %%
34 : %{
35 3659 : gspnlloc->step ();
36 : %}
37 1036 : {blank}+ gspnlloc->step ();
38 1479 : [\n]+ gspnlloc->lines (gspnleng); gspnlloc->step ();
39 443 : [\%][^\n]*[\n]
40 1 :
41 : %{
42 : typedef gspn::Gspn_parser::token token;
43 : %}
44 : /* Convert ints to the actual type of tokens. */
45 132 : [{}] return gspn::Gspn_parser::token_type (gspntext[0]);
46 :
47 428 : ";" {gspnlval->name = new std::string (gspntext); return token::SEMICOLON;
48 : Reader.error (*gspnlloc, "; expected");}
49 :
50 790 : "," {gspnlval->name = new std::string (gspntext); return token::COMMA;
51 : Reader.error (*gspnlloc, ", expected");}
52 :
53 363 : "(" {gspnlval->name = new std::string (gspntext); return token::LB;
54 : Reader.error (*gspnlloc, "( expected");}
55 363 : ")" {gspnlval->name = new std::string (gspntext); return token::RB;
56 : Reader.error (*gspnlloc, ") expected");}
57 :
58 123 : "=" {gspnlval->name = new std::string (gspntext); return token::EQ;
59 : Reader.error (*gspnlloc, "= expected");}
60 :
61 0 : "/" {gspnlval->name = new std::string (gspntext); return token::DIV;
62 : Reader.error (*gspnlloc, "/ expected");}
63 12 : "*" {gspnlval->name = new std::string (gspntext); return token::MUL;
64 : Reader.error (*gspnlloc, "* expected");}
65 0 : "+" {gspnlval->name = new std::string (gspntext); return token::PLUS;
66 : Reader.error (*gspnlloc, "+ expected");}
67 0 : "-" {gspnlval->name = new std::string (gspntext); return token::MINUS;
68 : Reader.error (*gspnlloc, "- expected");}
69 0 : "^" {gspnlval->name = new std::string (gspntext); return token::POWER;
70 : Reader.error (*gspnlloc, "^ expected");}
71 :
72 0 : "GspnName" {gspnlval->name = new std::string (gspntext); return token::GspnName;
73 : Reader.error (*gspnlloc, "GspnName expected");}
74 :
75 :
76 :
77 11 : "NbPlaces" {gspnlval->name = new std::string (gspntext); return token::NbPl;
78 : Reader.error (*gspnlloc, "NbPlces expected");}
79 :
80 11 : "NbTransitions" {gspnlval->name = new std::string (gspntext); return token::NbTr;
81 : Reader.error (*gspnlloc, "NbTransitions expected");}
82 :
83 11 : "PlacesList" {gspnlval->name = new std::string (gspntext); return token::PList;
84 : Reader.error (*gspnlloc, "PlacesList expected");}
85 :
86 11 : "TransitionsList" {gspnlval->name = new std::string (gspntext); return token::TList;
87 : Reader.error (*gspnlloc, "TransitionsList expected");}
88 :
89 11 : "Marking" {gspnlval->name = new std::string (gspntext); return token::marking;
90 : Reader.error (*gspnlloc, "marking expected");}
91 :
92 11 : "Transitions" {gspnlval->name = new std::string (gspntext); return token::transitions;
93 : Reader.error (*gspnlloc, "Transitions expected");}
94 :
95 11 : "InArcs" {gspnlval->name = new std::string (gspntext); return token::in;
96 : Reader.error (*gspnlloc, "InArcs expected");}
97 :
98 11 : "OutArcs" {gspnlval->name = new std::string (gspntext); return token::out;
99 : Reader.error (*gspnlloc, "OutArcs expected");}
100 :
101 0 : "InhibitorArcs" {gspnlval->name = new std::string (gspntext); return token::inhibitor;
102 : Reader.error (*gspnlloc, "InhibitorArcs expected");}
103 :
104 :
105 :
106 :
107 :
108 0 : "min" {gspnlval->name = new std::string (gspntext); return token::MIN;
109 : Reader.error (*gspnlloc, "min expected");}
110 :
111 0 : "max" {gspnlval->name = new std::string (gspntext); return token::MAX;
112 : Reader.error (*gspnlloc, "max expected");}
113 :
114 35 : "const" {gspnlval->name = new std::string (gspntext); return token::Const;
115 : Reader.error (*gspnlloc, "Const expected");}
116 :
117 11 : "int" {gspnlval->name = new std::string (gspntext); return token::INT;
118 : Reader.error (*gspnlloc, "int expected");}
119 :
120 24 : "double" {gspnlval->name = new std::string (gspntext); return token::DOUBLE;
121 : Reader.error (*gspnlloc, "double expected");}
122 :
123 0 : "floor" {gspnlval->name = new std::string (gspntext); return token::FLOOR;
124 : Reader.error (*gspnlloc, "floor expected");}
125 :
126 56 : "SINGLE" {gspnlval->name = new std::string (gspntext); return token::SINGLE;
127 : Reader.error (*gspnlloc, "SINGLE expected");}
128 :
129 0 : "MULTIPLE" {gspnlval->name = new std::string (gspntext); return token::MULTIPLE;
130 : Reader.error (*gspnlloc, "MULTIPLE expected");}
131 :
132 0 : "INFINITE" {gspnlval->name = new std::string (gspntext); return token::INFINITE;
133 : Reader.error (*gspnlloc, "INFINITE expected");}
134 :
135 0 : "ENABLINGMEMORY" {gspnlval->name = new std::string (gspntext); return token::ENABLINGMEMORY;
136 : Reader.error (*gspnlloc, "ENABLINGMEMORY expected");}
137 :
138 0 : "AGEMEMORY" {gspnlval->name = new std::string (gspntext); return token::AGEMEMORY;
139 : Reader.error (*gspnlloc, "AGEMEMORY expected");}
140 :
141 15 : "IMMEDIATE" {gspnlval->name = new std::string (gspntext); return token::IMDT;
142 : Reader.error (*gspnlloc, "IMMEDIATE expected");}
143 56 : "EXPONENTIAL" {gspnlval->name = new std::string (gspntext); return token::EXPO;
144 : Reader.error (*gspnlloc, "EXPONENTIAL expected");}
145 :
146 :
147 :
148 :
149 : {INT} {
150 423 : errno = 0;
151 423 : int x=atoi(gspntext);
152 423 : gspnlval->IntVal = x;
153 423 : return token::ival;
154 : }
155 :
156 : {REAL} {
157 28 : errno = 0;
158 28 : double x=atof(gspntext);
159 28 : gspnlval->RealVal = x;
160 28 : return token::rval;
161 : }
162 :
163 :
164 701 : {STR} {gspnlval->name = new std::string (gspntext); return token::str;
165 : Reader.error (*gspnlloc, "invalid character");}
166 :
167 0 : %%
168 0 :
169 :
170 :
171 :
172 : void
173 : Gspn_Reader::scan_end ()
174 11 : {
175 : gspnlex_destroy();
176 11 : }
177 11 :
178 :
179 : void Gspn_Reader::scan_expression (const std::string& f){
180 11 : const char* ch=f.c_str();
181 11 : gspnset_debug(trace_scanning);
182 11 :
183 : // GSPN_BUFFER_STATE b=gspn_scan_string(ch);
184 : // gspn_switch_to_buffer(b);
185 : gspn_scan_string(ch);
186 11 :
187 : }
188 116 : #endif // not __clang_analyzer__
189 :
|