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 lex_error { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
90 action p { printf("Lexer_lexstring:: p = %s\n", p);}
101 #what goes in between tokens in a filename
104 #types of tokes a filename can contain
105 direction = (N | W | S | E | NW | NE | SW | SE) ;
106 #make sure 0x123123 doesnt get mistaken for a ref
107 dimensions = (digit+ - '0') >set_ts %push_val 'x' (digit+ - '0') >set_ts %push_val;
108 link = '#' %push_link;
109 SS = ('+SS' %to(push_SS)) | ('+SS' %to(push_SS) link ) ;
110 ref = '0x' >set_ts alnum+ %push_ref;
111 val = digit+ >set_ts %push_val ;
112 name = (lower+ >set_ts) %push_name ;
113 map = '+MAP' %to(push_map);
114 tok = (name | val | ref | dimensions | map | link | SS | direction);
117 main := (tok tok_delimiter)+ tok [\0];
119 write data nofinal noerror noprefix;
128 uint8_t *ts, *pe, *te;
129 int cs, ntok;//, tok_t;
135 printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
140 printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
146 /**************************/
147 /****Abandon All Hope******/
148 /**************************/
158 machine setdirection;
160 action ret_north {printf("Lexer_setdirection:: direction is north, returning 4\n"); return 4;; }
161 action ret_west { printf("Lexer_setdirection:: direction is west, returning 2\n");return 2;}
162 action ret_east { printf("Lexer_setdirection:: direction is east, returning 6\n");return 6;}
163 action ret_south { printf("Lexer_setdirection:: direction is south, returning 0\n");return 0;}
164 action ret_northeast { printf("Lexer_setdirection:: direction is northeast, returning 5\n");return 5 ;}
165 action ret_northwest { printf("Lexer_setdirection:: direction is northwest, returning 3\n");return 3;}
166 action ret_southeast { printf("Lexer_setdirection:: direction is southeast, returning 7\n");return 7;}
167 action ret_southwest { printf("Lexer_setdirection:: direction is southwest, returning 1\n");return 1;}
169 def = [_\0] %to(ret_south);
170 N = 'N'[_\0] %to(ret_north);
171 W = 'W' [_\0] %to(ret_west);
172 S = 'S' [_\0] %to(ret_south);
173 E = 'E' [_\0] %to(ret_east);
174 NW = 'NW' [_\0] %to(ret_northwest);
175 NE = 'NE' [_\0] %to(ret_northeast);
176 SW = 'SW' [_\0] %to(ret_southwest);
177 SE = 'SE' [_\0] %to(ret_southeast);
179 direction = (N | W | S | E | NW | NE | SW | SE | def);
183 write data nofinal noprefix noerror;
191 (uint8_t* str, int size)
192 { uint8_t *p, *pe, *eof;
199 printf("|--- Begin lexer_setdirection str = %s, p = %s, pe = %s ---|\n", str,p, pe);
204 printf("|--- Error in: lexer_setdirection ---|\n");
215 action lex_setvlink {printf("Lexer_setstr:: Returning setvlink filetype for %s\n", str); type = 5; newstrt = lexer_lexsetvlink(str); fbreak;}
216 action lex_elevlink {printf("Lexer_setstr:: Returning elevlink filetype for %s\n", str); type = 6; newstrt = lexer_lexelevlink(str); fbreak;}
217 action lex_setmodel {printf("Lexer_setstr:: Returning setmodel filetype\n"); newstrt = lexer_lexsetmodel(str); type = 1; fbreak;}
218 action lex_setmap {printf("Lexer_setstr:: Returning setmap filetype\n"); newstrt = lexer_lexsetmap(str); type = 2; fbreak;}
219 action lex_elemodel {printf("Lexer_setstr:: Returning elemodel filetype for %s\n", str); newstrt = lexer_lexelemodel(str); type = 3; fbreak;}
220 action lex_elemap {printf("Lexer_setstr:: Returning elemap filetype for %s\n", str); newstrt = lexer_lexelemap(str); type = 4; fbreak;}
221 action lex_setolink { printf("Lexer_setstr:: Returning setolink filetype\n"); type = 8; newstrt = lexer_lexsetolink(str); fbreak;}
222 action lex_eleolink { printf("Lexer_setstr:: Returning eleolink filetype\n"); type = 7; newstrt = lexer_lexeleolink(str); fbreak;}
223 action p {printf("p = %s \n",p);}
224 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);}
237 direction = (N | W | S | E | NW | NE | SW | SE) $p;
243 name = alpha+ $p - SSD $p;
245 ref = '0x' $p alnum+ $p;
248 set_label = name | (name '_' ref);
249 ele_label = name | (name '_' ref);
251 model_types = (name) | (name '_' num '_' num) | (name '_' num);
254 set_model = set_label '_' SS %to(lex_setmodel);
255 set_map = set_label '_' '~' %to(lex_setmap);
256 ele_model = set_label '_' ele_label '_' SS %to(lex_elemodel);
257 ele_map = set_label '_' ele_label '_' '~' %to(lex_elemap);
258 set_olink = ref %to(lex_setolink) [\0] ;
259 ele_olink = set_label '_' '~' '_' ref [\0] %to(lex_eleolink);
260 set_vlink = set_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_setvlink);
261 ele_vlink = set_label '_' ele_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_elevlink);
263 main := (ele_map | set_model | set_map |ele_model | ele_vlink | set_vlink | set_olink | ele_olink);
272 (uint8_t* str, int size)
273 { uint8_t *p, *pe, *eof;
274 int cs, type, newstrt;
281 printf("|--- Begin lexer_setstr with str = %s, p = %s, pe = %s ---|\n", str,p, pe);
286 printf("|--- End lexer_setstr. Incrementing str by %d, type is %d ---|\n", newstrt, type);
295 /* machine file_matcher; */
297 /* action call_ml { ts = p; fgoto set_hw ;} */
298 /* action call_tl { return 0;} */
299 /* action set_height {height = ttov(p, p-ts+1); ts = p;} */
300 /* action set_width { width = ttov(p, p-ts+1);} */
301 /* action call_lmf {lexer_lexmapfile(height, width); } */
302 /* action lex_error {printf("input error: character %c in filename %s is invalid\n = %s\n", fc, str, p);} */
304 /* #This machine determines the type of file we are lexing */
305 /* #and calls the appropriate machine to handle it. */
307 /* #TODO add mapping name */
308 /* width = digit+ %set_width; */
309 /* height = digit+ %set_height; */
311 /* set_hw := height . '_' . width [\0] %to(call_lmf); */
313 /* tok_segment = alnum; */
314 /* map_end = 'm' . '_' %to(call_ml); */
315 /* tok_end = alnum+ . [\0] %to(call_tl); */
317 /* file_matcher := (tok_segment+ . '_' )+ ( map_end | tok_end ); */
323 /* lexer_matchfile */
324 /* (char* str, int size) */
327 /* int cs, ntok, height, width; */
331 /* height = width = 0; */
333 /* printf("Checking if filename is a map file:: filename = %s, p = %c, pe = %c\n", str, *p, *pe); */
336 /* %%write exec noend; */
338 /* printf("Ending lexer_ismapfile on %s\n", str); */
344 /* machine vartype; */
346 /* action isele {return 0;} */
347 /* action ismodel {return 1;} */
349 /* set_name = alpha+; */
350 /* ele_name = alpha+; */
351 /* model_name = alpha+; */
353 /* ele = set_name '_' model_name '_' ele_name %isele; */
354 /* model = set_name '_' model_name [\0] %ismodel; */
357 /* ismodel := (ele | model); */
365 /* (uint8_t* str, int size) */
366 /* { uint8_t *p, *pe, *eof; */
370 /* pe = p + size + 1; */