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);
21 /* Lexstring is the main lexer for APC and is generated by ragel. It lexes file names of files
22 that have been scanned and pushes their types and values into the tok_stack, which yyparse
23 eventually calls during parsing. */
28 # set up yylval and tok_t to be pushed to stack
29 action push_ref { long long ref;
31 ref = strtoll((char*)ts,(char**)&te,16);
32 if (errno | (te != NULL))
33 { fprintf(stderr, "Invalid hex number in file %s\n",(char*)str);
41 yypush_parse(apc_pstate, REF, &ref, apc_cstate);
44 action push_link { yypush_parse(apc_pstate, LINK, (YYSTYPE) 0, apc_cstate);}
45 action push_val { int val;
47 val = strtoll((char*)ts,(char**)&te,10);
49 { fprintf(stderr, "strtoll could not parse %s\n", (char*)str);
52 yypush_parse(apc_pstate, NUM, &val, apc_cstate);
55 action push_name { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
56 yypush_parse( apc_pstate, NAME, strdndup(ts, p-ts), apc_cstate);
59 action push_map { printf("Lexer_lexstring:: action:push_map: pushing map token\n");
60 yypush_parse(apc_pstate, MAP, (uint8_t*) '~', apc_cstate);
63 action set_ts { printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p); ts = p; }
64 action push_SS { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
65 yypush_parse(apc_pstate, SS, (uint8_t*) "SS", apc_cstate);
68 action push_S { printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
69 yypush_parse(apc_pstate, FACING, (YYSTYPE) 0, apc_cstate);
72 action push_SW { printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
73 yypush_parse(apc_pstate, FACING, (YYSTYPE) 1, apc_cstate);
76 action push_W { printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
77 yypush_parse(apc_pstate, FACING, (YYSTYPE) 2, apc_cstate);
80 action push_NW { printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
81 yypush_parse(apc_pstate, FACING, (YYSTYPE) 3, apc_cstate);
84 action push_N { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
85 yypush_parse(apc_pstate, FACING, (YYSTYPE) 4, apc_cstate);
88 action push_NE { printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
89 yypush_parse(apc_pstate, FACING, (YYSTYPE) 5, apc_cstate);
92 action push_E { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
93 yypush_parse(apc_pstate, FACING, (YYSTYPE) 6, apc_cstate);
96 action push_SE { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
97 ypush_parse(apc_pstate, FACING, (YYSTYPE) 7, apc_cstate);
100 action ref_error { printf("ref from %s to %s has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
103 action p { printf("Lexer_lexstring:: p = %s\n", p);}
116 direction = (N | W | S | E | NW | NE | SW | SE) ;
117 dimensions = (digit+ - '0') >set_ts %push_val 'x' (digit+ - '0') >set_ts %push_val;
118 link = '#' %push_link;
119 SS = ('+SS' %to(push_SS)) | ('+SS' %to(push_SS) link ) ;
120 ref = '0x' >set_ts alnum{8} $err(ref_error) %push_ref ;
121 val = digit+ >set_ts %push_val ;
122 name = (lower+ >set_ts) %push_name ;
123 map = '+MAP' %to(push_map);
124 tok = (name | val | ref | dimensions | map | link | SS | direction);
127 main := (tok tok_delimiter)+ tok [\0];
129 write data nofinal noerror noprefix;
138 uint8_t *ts, *pe, *te;
139 int cs, ntok, eof;//, tok_t;
145 printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
150 printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
156 /**************************/
157 /****Abandon All Hope******/
158 /**************************/
168 machine setdirection;
170 action ret_north {printf("Lexer_setdirection:: direction is north, returning 4\n"); return 4;; }
171 action ret_west { printf("Lexer_setdirection:: direction is west, returning 2\n");return 2;}
172 action ret_east { printf("Lexer_setdirection:: direction is east, returning 6\n");return 6;}
173 action ret_south { printf("Lexer_setdirection:: direction is south, returning 0\n");return 0;}
174 action ret_northeast { printf("Lexer_setdirection:: direction is northeast, returning 5\n");return 5 ;}
175 action ret_northwest { printf("Lexer_setdirection:: direction is northwest, returning 3\n");return 3;}
176 action ret_southeast { printf("Lexer_setdirection:: direction is southeast, returning 7\n");return 7;}
177 action ret_southwest { printf("Lexer_setdirection:: direction is southwest, returning 1\n");return 1;}
179 def = [_\0] %to(ret_south);
180 N = 'N'[_\0] %to(ret_north);
181 W = 'W' [_\0] %to(ret_west);
182 S = 'S' [_\0] %to(ret_south);
183 E = 'E' [_\0] %to(ret_east);
184 NW = 'NW' [_\0] %to(ret_northwest);
185 NE = 'NE' [_\0] %to(ret_northeast);
186 SW = 'SW' [_\0] %to(ret_southwest);
187 SE = 'SE' [_\0] %to(ret_southeast);
189 direction = (N | W | S | E | NW | NE | SW | SE | def);
193 write data nofinal noprefix noerror;
201 (uint8_t* str, int size)
202 { uint8_t *p, *pe, *eof;
209 printf("|--- Begin lexer_setdirection str = %s, p = %s, pe = %s ---|\n", str,p, pe);
214 printf("|--- Error in: lexer_setdirection ---|\n");
225 action lex_setvlink {printf("Lexer_setstr:: Returning setvlink filetype for %s\n", str); type = 5; newstrt = lexer_lexsetvlink(str); fbreak;}
226 action lex_elevlink {printf("Lexer_setstr:: Returning elevlink filetype for %s\n", str); type = 6; newstrt = lexer_lexelevlink(str); fbreak;}
227 action lex_setmodel {printf("Lexer_setstr:: Returning setmodel filetype\n"); newstrt = lexer_lexsetmodel(str); type = 1; fbreak;}
228 action lex_setmap {printf("Lexer_setstr:: Returning setmap filetype\n"); newstrt = lexer_lexsetmap(str); type = 2; fbreak;}
229 action lex_elemodel {printf("Lexer_setstr:: Returning elemodel filetype for %s\n", str); newstrt = lexer_lexelemodel(str); type = 3; fbreak;}
230 action lex_elemap {printf("Lexer_setstr:: Returning elemap filetype for %s\n", str); newstrt = lexer_lexelemap(str); type = 4; fbreak;}
231 action lex_setolink { printf("Lexer_setstr:: Returning setolink filetype\n"); type = 8; newstrt = lexer_lexsetolink(str); fbreak;}
232 action lex_eleolink { printf("Lexer_setstr:: Returning eleolink filetype\n"); type = 7; newstrt = lexer_lexeleolink(str); fbreak;}
233 action p {printf("p = %s \n",p);}
234 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);}
247 direction = (N | W | S | E | NW | NE | SW | SE) $p;
253 name = alpha+ $p - SSD $p;
255 ref = '0x' $p alnum+ $p;
258 set_label = name | (name '_' ref);
259 ele_label = name | (name '_' ref);
261 model_types = (name) | (name '_' num '_' num) | (name '_' num);
264 set_model = set_label '_' SS %to(lex_setmodel);
265 set_map = set_label '_' '~' %to(lex_setmap);
266 ele_model = set_label '_' ele_label '_' SS %to(lex_elemodel);
267 ele_map = set_label '_' ele_label '_' '~' %to(lex_elemap);
268 set_olink = ref %to(lex_setolink) [\0] ;
269 ele_olink = set_label '_' '~' '_' ref [\0] %to(lex_eleolink);
270 set_vlink = set_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_setvlink);
271 ele_vlink = set_label '_' ele_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_elevlink);
273 main := (ele_map | set_model | set_map |ele_model | ele_vlink | set_vlink | set_olink | ele_olink);
282 (uint8_t* str, int size)
283 { uint8_t *p, *pe, *eof;
284 int cs, type, newstrt;
291 printf("|--- Begin lexer_setstr with str = %s, p = %s, pe = %s ---|\n", str,p, pe);
296 printf("|--- End lexer_setstr. Incrementing str by %d, type is %d ---|\n", newstrt, type);
305 /* machine file_matcher; */
307 /* action call_ml { ts = p; fgoto set_hw ;} */
308 /* action call_tl { return 0;} */
309 /* action set_height {height = ttov(p, p-ts+1); ts = p;} */
310 /* action set_width { width = ttov(p, p-ts+1);} */
311 /* action call_lmf {lexer_lexmapfile(height, width); } */
312 /* action lex_error {printf("input error: character %c in filename %s is invalid\n = %s\n", fc, str, p);} */
314 /* #This machine determines the type of file we are lexing */
315 /* #and calls the appropriate machine to handle it. */
317 /* #TODO add mapping name */
318 /* width = digit+ %set_width; */
319 /* height = digit+ %set_height; */
321 /* set_hw := height . '_' . width [\0] %to(call_lmf); */
323 /* tok_segment = alnum; */
324 /* map_end = 'm' . '_' %to(call_ml); */
325 /* tok_end = alnum+ . [\0] %to(call_tl); */
327 /* file_matcher := (tok_segment+ . '_' )+ ( map_end | tok_end ); */
333 /* lexer_matchfile */
334 /* (char* str, int size) */
337 /* int cs, ntok, height, width; */
341 /* height = width = 0; */
343 /* printf("Checking if filename is a map file:: filename = %s, p = %c, pe = %c\n", str, *p, *pe); */
346 /* %%write exec noend; */
348 /* printf("Ending lexer_ismapfile on %s\n", str); */
354 /* machine vartype; */
356 /* action isele {return 0;} */
357 /* action ismodel {return 1;} */
359 /* set_name = alpha+; */
360 /* ele_name = alpha+; */
361 /* model_name = alpha+; */
363 /* ele = set_name '_' model_name '_' ele_name %isele; */
364 /* model = set_name '_' model_name [\0] %ismodel; */
367 /* ismodel := (ele | model); */
375 /* (uint8_t* str, int size) */
376 /* { uint8_t *p, *pe, *eof; */
380 /* pe = p + size + 1; */