#include <stdio.h>
#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
#include "parser.tab.h"
#include "apc.h"
#include <unistdio.h>
#include <unistr.h>
-
-extern void lexer_pushtok(int, YYSTYPE);
-extern int lexer_lexmapfile(int, int);
-extern int ipower(int, int);
-extern int ttov(uint8_t*, int);
-
+extern //lexer.c
+void lexer_pushtok(int, YYSTYPE);
+/* Public */
int lexer_setdirection(uint8_t*, int);
int lexer_lexstring(uint8_t*, int);
int lexer_setstr(uint8_t*, int);
-#define $($)#$
-#define PUSHTOK(TOK,LFUNC,UTYPE) \
- do { \
- printf("Lexer_lexstring:: PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \
- tok_t = TOK; \
- yylval.UTYPE = LFUNC(ts, p-ts); \
- lexer_pushtok(tok_t, yylval); \
- ++ntok; \
- } while (0);
-
%%{
machine lexstring;
# set up yylval and tok_t to be pushed to stack
- action push_ref { PUSHTOK(REF, ttov, ref); }
- action push_val { PUSHTOK(NUM, ttov, val); }
+ action push_ref { te = NULL; errno = 0;
+ yylval.ref = strtoll((char*)ts,(char**)&te,16);
+ if (errno | (te != NULL))
+ { fprintf(stderr, "Invalid hex number in file %s\n",(char*)str);
+ if (te != NULL)
+ { while (str++ < te)
+ fputc(' ', stderr);
+ fputc('^', stderr);
+ }
+ exit(1);
+ }
+ lexer_pushtok(REF, yylval); ntok++;
+ }
+ action push_link { lexer_pushtok(LINK,(YYSTYPE)0); ntok++; }
+ action push_val { te = NULL; errno = 0;
+ yylval.val = strtoll((char*)ts,(char**)&te,10);
+ if (errno)
+ { fprintf(stderr, "strtoll could not parse %s\n", (char*)str);
+ exit(1);
+ }
+ lexer_pushtok(NUM, yylval);
+ }
action push_name { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
lexer_pushtok(NAME, yylval);
ntok++;
lexer_pushtok(D, yylval);
}
action push_height { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
- PUSHTOK(HEIGHT, ttov, val);
}
action push_width { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
- PUSHTOK(WIDTH, ttov, val);
}
- action push_link {yylval.str = (uint8_t*) '#'; lexer_pushtok(LINK,yylval); }
#action lex_error { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
action p { printf("Lexer_lexstring:: p = %s\n", p);}
#types of tokes a filename can contain
direction = (N | W | S | E | NW | NE | SW | SE) ;
#make sure 0x123123 doesnt get mistaken for a ref
- dimensions = (digit+ - '0') >set_ts %push_height 'x' (digit+ - '0') >set_ts %push_width;
+ dimensions = (digit+ - '0') >set_ts %push_val 'x' (digit+ - '0') >set_ts %push_val;
link = '#' %push_link;
SS = ('+SS' %to(push_SS)) | ('+SS' %to(push_SS) link ) ;
ref = '0x' >set_ts alnum+ %push_ref;
}%%
-int
-lexer_lexstring
-(uint8_t* str, int size)
+int lexer_lexstring
+( uint8_t* str,
+ int size
+)
{ uint8_t *p;
- uint8_t *ts, *pe;
- int cs, ntok, tok_t;
+ uint8_t *ts, *pe, *te;
+ int cs, ntok;//, tok_t;
ntok = 0;
p = ts = str;