action set_val { PUSHTOK(NUM, ttov, val); }
action set_name { PUSHTOK(NAME, ttos, str); }
action set_ts { ts = p; }
+ action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);}
# instantiate machines for each possible token
ref = '0x' xdigit+ %set_ref;
tok = ref | val | name;
segment = (tok . '_') %set_ts;
- main := segment* . tok;
+ main := segment* . tok $lerr(lex_error);
}%%
int cs, tok_t, ntok = 0;
printf ("Lexing: %s\n",str);
p = ts = str;
- pe = p + strlen(str) + 1;
+ pe = p + strlen(str);
%%write init;
%%write exec;
printf ("Lexed %i tokens\n",ntok);