3 #include <apc/parser.tab.h>
8 extern void lexer_pushtok(int, YYSTYPE);
9 extern int lexer_lexmapfile(int, int);
10 extern int ipower(int, int);
11 extern int ttov(uint8_t*, int);
12 extern struct name* tton(const uint8_t*, int);
14 int lexer_setdirection(uint8_t*, int);
15 int lexer_lexstring(uint8_t*, int);
16 int lexer_setstr(uint8_t*, int);
19 #define PUSHTOK(TOK,LFUNC,UTYPE) \
21 printf("Lexer_lexstring:: PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \
23 yylval.UTYPE = LFUNC(ts, p-ts); \
24 lexer_pushtok(tok_t, yylval); \
31 # set up yylval and tok_t to be pushed to stack
32 action push_ref { PUSHTOK(REF, ttov, ref); }
33 action push_val { PUSHTOK(NUM, ttov, val); }
34 action push_name { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
35 PUSHTOK(NAME, tton, str);
37 action push_map { printf("Lexer_lexstring:: action:push_map: pushing '~'\n");
38 yylval.str = (uint8_t*) '~';
39 lexer_pushtok(MOPEN, yylval);
42 action set_ts { printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p); ts = p; }
43 action push_SS { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
44 yylval.str = (uint8_t*) "SS";
45 lexer_pushtok(SS, yylval);
48 action push_S { printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
50 lexer_pushtok(D, yylval);
52 action push_SW { printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
54 lexer_pushtok(D, yylval);
56 action push_W { printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
58 lexer_pushtok(D, yylval);
60 action push_NW { printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
62 lexer_pushtok(D, yylval);
64 action push_N { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
66 lexer_pushtok(D, yylval);
68 action push_NE { printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
70 lexer_pushtok(D, yylval);
72 action push_E { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
74 lexer_pushtok(D, yylval);
76 action push_SE { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
78 lexer_pushtok(D, yylval);
80 action push_height { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
81 PUSHTOK(HEIGHT, ttov, val);
83 action push_width { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
84 PUSHTOK(WIDTH, ttov, val);
86 action push_link {yylval.str = (uint8_t*) '#'; lexer_pushtok(LINK),yylval); }
87 action lex_error { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
88 action p { printf("Lexer_lexstring:: p = %s\n", p);}
90 # Parses a regular filename (not a mapping) and pushes
91 # tokens to the parser
102 direction = (N | W | S | E | NW | NE | SW | SE) ;
103 #make sure 0x123123 doesnt get mistaken for a ref
104 dimensions = (digit+ - '0') >set_ts %push_height 'x' (digit+ - '0') >set_ts %push_width;
105 link = '#' %push_link;
106 SS = ('+SS' %to(push_SS)) | ('+SS' %to(push_SS) link ) ;
107 ref = '0x' >set_ts alnum+ %push_ref;
108 val = digit+ >set_ts %push_val ;
109 name = (lower+ >set_ts) %push_name ;
110 map = '+MAP' %to(push_map);
111 tok = name %to(push_name) ;
114 tok_lexer := ((name | val | ref | dimensions | map) tok_delimiter)+ tok [\0];
122 (uint8_t* str, int size)
124 uint8_t *ts, *pe, *eof;
125 int cs, ntok, tok_t, direction;
127 ntok = direction = 0;
131 printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
136 printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
143 machine setdirection;
145 action ret_north {printf("Lexer_setdirection:: direction is north, returning 4\n"); return 4;; }
146 action ret_west { printf("Lexer_setdirection:: direction is west, returning 2\n");return 2;}
147 action ret_east { printf("Lexer_setdirection:: direction is east, returning 6\n");return 6;}
148 action ret_south { printf("Lexer_setdirection:: direction is south, returning 0\n");return 0;}
149 action ret_northeast { printf("Lexer_setdirection:: direction is northeast, returning 5\n");return 5 ;}
150 action ret_northwest { printf("Lexer_setdirection:: direction is northwest, returning 3\n");return 3;}
151 action ret_southeast { printf("Lexer_setdirection:: direction is southeast, returning 7\n");return 7;}
152 action ret_southwest { printf("Lexer_setdirection:: direction is southwest, returning 1\n");return 1;}
154 def = [_\0] %to(ret_south);
155 N = 'N'[_\0] %to(ret_north);
156 W = 'W' [_\0] %to(ret_west);
157 S = 'S' [_\0] %to(ret_south);
158 E = 'E' [_\0] %to(ret_east);
159 NW = 'NW' [_\0] %to(ret_northwest);
160 NE = 'NE' [_\0] %to(ret_northeast);
161 SW = 'SW' [_\0] %to(ret_southwest);
162 SE = 'SE' [_\0] %to(ret_southeast);
164 direction = (N | W | S | E | NW | NE | SW | SE | def);
174 (uint8_t* str, int size)
175 { uint8_t *p, *pe, *eof;
182 printf("|--- Begin lexer_setdirection str = %s, p = %s, pe = %s ---|\n", str,p, pe);
187 printf("|--- Error in: lexer_setdirection ---|\n");
194 /**************************/
195 /****Abandon All Hope******/
196 /**************************/
208 action lex_setvlink {printf("Lexer_setstr:: Returning setvlink filetype for %s\n", str); type = 5; newstrt = lexer_lexsetvlink(str); fbreak;}
209 action lex_elevlink {printf("Lexer_setstr:: Returning elevlink filetype for %s\n", str); type = 6; newstrt = lexer_lexelevlink(str); fbreak;}
210 action lex_setmodel {printf("Lexer_setstr:: Returning setmodel filetype\n"); newstrt = lexer_lexsetmodel(str); type = 1; fbreak;}
211 action lex_setmap {printf("Lexer_setstr:: Returning setmap filetype\n"); newstrt = lexer_lexsetmap(str); type = 2; fbreak;}
212 action lex_elemodel {printf("Lexer_setstr:: Returning elemodel filetype for %s\n", str); newstrt = lexer_lexelemodel(str); type = 3; fbreak;}
213 action lex_elemap {printf("Lexer_setstr:: Returning elemap filetype for %s\n", str); newstrt = lexer_lexelemap(str); type = 4; fbreak;}
214 action lex_setolink { printf("Lexer_setstr:: Returning setolink filetype\n"); type = 8; newstrt = lexer_lexsetolink(str); fbreak;}
215 action lex_eleolink { printf("Lexer_setstr:: Returning eleolink filetype\n"); type = 7; newstrt = lexer_lexeleolink(str); fbreak;}
216 action p {printf("p = %s \n",p);}
217 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);}
230 direction = (N | W | S | E | NW | NE | SW | SE) $p;
236 name = alpha+ $p - SSD $p;
238 ref = '0x' $p alnum+ $p;
241 set_label = name | (name '_' ref);
242 ele_label = name | (name '_' ref);
244 model_types = (name) | (name '_' num '_' num) | (name '_' num);
247 set_model = set_label '_' SS %to(lex_setmodel);
248 set_map = set_label '_' '~' %to(lex_setmap);
249 ele_model = set_label '_' ele_label '_' SS %to(lex_elemodel);
250 ele_map = set_label '_' ele_label '_' '~' %to(lex_elemap);
251 set_olink = ref %to(lex_setolink) [\0] ;
252 ele_olink = set_label '_' '~' '_' ref [\0] %to(lex_eleolink);
253 set_vlink = set_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_setvlink);
254 ele_vlink = set_label '_' ele_label '_' '#' '_' (ref | ref '_' name) [\0] %to(lex_elevlink);
256 main := (ele_map | set_model | set_map |ele_model | ele_vlink | set_vlink | set_olink | ele_olink);
265 (uint8_t* str, int size)
266 { uint8_t *p, *pe, *eof;
267 int cs, type, newstrt;
274 printf("|--- Begin lexer_setstr with str = %s, p = %s, pe = %s ---|\n", str,p, pe);
279 printf("|--- End lexer_setstr. Incrementing str by %d, type is %d ---|\n", newstrt, type);
288 /* machine file_matcher; */
290 /* action call_ml { ts = p; fgoto set_hw ;} */
291 /* action call_tl { return 0;} */
292 /* action set_height {height = ttov(p, p-ts+1); ts = p;} */
293 /* action set_width { width = ttov(p, p-ts+1);} */
294 /* action call_lmf {lexer_lexmapfile(height, width); } */
295 /* action lex_error {printf("input error: character %c in filename %s is invalid\n = %s\n", fc, str, p);} */
297 /* #This machine determines the type of file we are lexing */
298 /* #and calls the appropriate machine to handle it. */
300 /* #TODO add mapping name */
301 /* width = digit+ %set_width; */
302 /* height = digit+ %set_height; */
304 /* set_hw := height . '_' . width [\0] %to(call_lmf); */
306 /* tok_segment = alnum; */
307 /* map_end = 'm' . '_' %to(call_ml); */
308 /* tok_end = alnum+ . [\0] %to(call_tl); */
310 /* file_matcher := (tok_segment+ . '_' )+ ( map_end | tok_end ); */
316 /* lexer_matchfile */
317 /* (char* str, int size) */
320 /* int cs, ntok, height, width; */
324 /* height = width = 0; */
326 /* printf("Checking if filename is a map file:: filename = %s, p = %c, pe = %c\n", str, *p, *pe); */
329 /* %%write exec noend; */
331 /* printf("Ending lexer_ismapfile on %s\n", str); */
337 /* machine vartype; */
339 /* action isele {return 0;} */
340 /* action ismodel {return 1;} */
342 /* set_name = alpha+; */
343 /* ele_name = alpha+; */
344 /* model_name = alpha+; */
346 /* ele = set_name '_' model_name '_' ele_name %isele; */
347 /* model = set_name '_' model_name [\0] %ismodel; */
350 /* ismodel := (ele | model); */
358 /* (uint8_t* str, int size) */
359 /* { uint8_t *p, *pe, *eof; */
363 /* pe = p + size + 1; */