5 #include "parser.tab.h"
10 void lexer_pushtok(int, YYSTYPE);
12 int lexer_setdirection(uint8_t*, int);
13 int lexer_lexstring(uint8_t*, int);
14 int lexer_setstr(uint8_t*, int);
19 # set up yylval and tok_t to be pushed to stack
20 action push_ref { te = NULL; errno = 0;
21 yylval.ref = strtoll((char*)ts,(char**)&te,16);
22 if (errno | (te != NULL))
23 { fprintf(stderr, "Invalid hex number in file %s\n",(char*)str);
31 lexer_pushtok(REF, yylval); ntok++;
33 action push_link { lexer_pushtok(LINK,(YYSTYPE)0); ntok++; }
34 action push_val { te = NULL; errno = 0;
35 yylval.val = strtoll((char*)ts,(char**)&te,10);
37 { fprintf(stderr, "strtoll could not parse %s\n", (char*)str);
40 lexer_pushtok(NUM, yylval);
42 action push_name { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
43 lexer_pushtok(NAME, yylval);
46 action push_map { printf("Lexer_lexstring:: action:push_map: pushing map token\n");
47 yylval.str = (uint8_t*) '~';
48 lexer_pushtok(MOPEN, yylval);
51 action set_ts { printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p); ts = p; }
52 action push_SS { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
53 yylval.str = (uint8_t*) "SS";
54 lexer_pushtok(SS, yylval);
57 action push_S { printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
59 lexer_pushtok(D, yylval);
61 action push_SW { printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
63 lexer_pushtok(D, yylval);
65 action push_W { printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
67 lexer_pushtok(D, yylval);
69 action push_NW { printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
71 lexer_pushtok(D, yylval);
73 action push_N { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
75 lexer_pushtok(D, yylval);
77 action push_NE { printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
79 lexer_pushtok(D, yylval);
81 action push_E { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
83 lexer_pushtok(D, yylval);
85 action push_SE { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
87 lexer_pushtok(D, yylval);
89 action push_height { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
91 action push_width { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
93 #action lex_error { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
94 action p { printf("Lexer_lexstring:: p = %s\n", p);}
105 #what goes in between tokens in a filename
108 #types of tokes a filename can contain
109 direction = (N | W | S | E | NW | NE | SW | SE) ;
110 #make sure 0x123123 doesnt get mistaken for a ref
111 dimensions = (digit+ - '0') >set_ts %push_val 'x' (digit+ - '0') >set_ts %push_val;
112 link = '#' %push_link;
113 SS = ('+SS' %to(push_SS)) | ('+SS' %to(push_SS) link ) ;
114 ref = '0x' >set_ts alnum+ %push_ref;
115 val = digit+ >set_ts %push_val ;
116 name = (lower+ >set_ts) %push_name ;
117 map = '+MAP' %to(push_map);
118 tok = (name | val | ref | dimensions | map | link | SS | direction);
121 main := (tok tok_delimiter)+ tok [\0];
123 write data nofinal noerror noprefix;
132 uint8_t *ts, *pe, *te;
133 int cs, ntok;//, tok_t;
139 printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
144 printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
150 /**************************/
151 /****Abandon All Hope******/
152 /**************************/
162 machine setdirection;
164 action ret_north {printf("Lexer_setdirection:: direction is north, returning 4\n"); return 4;; }
165 action ret_west { printf("Lexer_setdirection:: direction is west, returning 2\n");return 2;}
166 action ret_east { printf("Lexer_setdirection:: direction is east, returning 6\n");return 6;}
167 action ret_south { printf("Lexer_setdirection:: direction is south, returning 0\n");return 0;}
168 action ret_northeast { printf("Lexer_setdirection:: direction is northeast, returning 5\n");return 5 ;}
169 action ret_northwest { printf("Lexer_setdirection:: direction is northwest, returning 3\n");return 3;}
170 action ret_southeast { printf("Lexer_setdirection:: direction is southeast, returning 7\n");return 7;}
171 action ret_southwest { printf("Lexer_setdirection:: direction is southwest, returning 1\n");return 1;}
173 def = [_\0] %to(ret_south);
174 N = 'N'[_\0] %to(ret_north);
175 W = 'W' [_\0] %to(ret_west);
176 S = 'S' [_\0] %to(ret_south);
177 E = 'E' [_\0] %to(ret_east);
178 NW = 'NW' [_\0] %to(ret_northwest);
179 NE = 'NE' [_\0] %to(ret_northeast);
180 SW = 'SW' [_\0] %to(ret_southwest);
181 SE = 'SE' [_\0] %to(ret_southeast);
183 direction = (N | W | S | E | NW | NE | SW | SE | def);
187 write data nofinal noprefix noerror;
195 (uint8_t* str, int size)
196 { uint8_t *p, *pe, *eof;
203 printf("|--- Begin lexer_setdirection str = %s, p = %s, pe = %s ---|\n", str,p, pe);
208 printf("|--- Error in: lexer_setdirection ---|\n");
219 action lex_setvlink {printf("Lexer_setstr:: Returning setvlink filetype for %s\n", str); type = 5; newstrt = lexer_lexsetvlink(str); fbreak;}
220 action lex_elevlink {printf("Lexer_setstr:: Returning elevlink filetype for %s\n", str); type = 6; newstrt = lexer_lexelevlink(str); fbreak;}
221 action lex_setmodel {printf("Lexer_setstr:: Returning setmodel filetype\n"); newstrt = lexer_lexsetmodel(str); type = 1; fbreak;}
222 action lex_setmap {printf("Lexer_setstr:: Returning setmap filetype\n"); newstrt = lexer_lexsetmap(str); type = 2; fbreak;}
223 action lex_elemodel {printf("Lexer_setstr:: Returning elemodel filetype for %s\n", str); newstrt = lexer_lexelemodel(str); type = 3; fbreak;}
224 action lex_elemap {printf("Lexer_setstr:: Returning elemap filetype for %s\n", str); newstrt = lexer_lexelemap(str); type = 4; fbreak;}
225 action lex_setolink { printf("Lexer_setstr:: Returning setolink filetype\n"); type = 8; newstrt = lexer_lexsetolink(str); fbreak;}
226 action lex_eleolink { printf("Lexer_setstr:: Returning eleolink filetype\n"); type = 7; newstrt = lexer_lexeleolink(str); fbreak;}
227 action p {printf("p = %s \n",p);}
228 action name_error {printf("In %s, there is a syntactic error. Make sure your set/element names dont conflict with the reserved keywords.\n", str);}
241 direction = (N | W | S | E | NW | NE | SW | SE) $p;
247 name = alpha+ $p - SSD $p;
249 ref = '0x' $p alnum+ $p;
252 set_label = name | (name '_' ref);
253 ele_label = name | (name '_' ref);
255 model_types = (name) | (name '_' num '_' num) | (name '_' num);
258 set_model = set_label '_' SS %to(lex_setmodel);
259 set_map = set_label '_' '~' %to(lex_setmap);
260 ele_model = set_label '_' ele_label '_' SS %to(lex_elemodel);
261 ele_map = set_label '_' ele_label '_' '~' %to(lex_elemap);
262 set_olink = ref %to(lex_setolink) [\0] ;
263 ele_olink = set_label '_' '~' '_' ref [\0] %to(lex_eleolink);
264 set_vlink = set_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_setvlink);
265 ele_vlink = set_label '_' ele_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_elevlink);
267 main := (ele_map | set_model | set_map |ele_model | ele_vlink | set_vlink | set_olink | ele_olink);
276 (uint8_t* str, int size)
277 { uint8_t *p, *pe, *eof;
278 int cs, type, newstrt;
285 printf("|--- Begin lexer_setstr with str = %s, p = %s, pe = %s ---|\n", str,p, pe);
290 printf("|--- End lexer_setstr. Incrementing str by %d, type is %d ---|\n", newstrt, type);
299 /* machine file_matcher; */
301 /* action call_ml { ts = p; fgoto set_hw ;} */
302 /* action call_tl { return 0;} */
303 /* action set_height {height = ttov(p, p-ts+1); ts = p;} */
304 /* action set_width { width = ttov(p, p-ts+1);} */
305 /* action call_lmf {lexer_lexmapfile(height, width); } */
306 /* action lex_error {printf("input error: character %c in filename %s is invalid\n = %s\n", fc, str, p);} */
308 /* #This machine determines the type of file we are lexing */
309 /* #and calls the appropriate machine to handle it. */
311 /* #TODO add mapping name */
312 /* width = digit+ %set_width; */
313 /* height = digit+ %set_height; */
315 /* set_hw := height . '_' . width [\0] %to(call_lmf); */
317 /* tok_segment = alnum; */
318 /* map_end = 'm' . '_' %to(call_ml); */
319 /* tok_end = alnum+ . [\0] %to(call_tl); */
321 /* file_matcher := (tok_segment+ . '_' )+ ( map_end | tok_end ); */
327 /* lexer_matchfile */
328 /* (char* str, int size) */
331 /* int cs, ntok, height, width; */
335 /* height = width = 0; */
337 /* printf("Checking if filename is a map file:: filename = %s, p = %c, pe = %c\n", str, *p, *pe); */
340 /* %%write exec noend; */
342 /* printf("Ending lexer_ismapfile on %s\n", str); */
348 /* machine vartype; */
350 /* action isele {return 0;} */
351 /* action ismodel {return 1;} */
353 /* set_name = alpha+; */
354 /* ele_name = alpha+; */
355 /* model_name = alpha+; */
357 /* ele = set_name '_' model_name '_' ele_name %isele; */
358 /* model = set_name '_' model_name [\0] %ismodel; */
361 /* ismodel := (ele | model); */
369 /* (uint8_t* str, int size) */
370 /* { uint8_t *p, *pe, *eof; */
374 /* pe = p + size + 1; */