1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
/* Generated by re2c */
// re2c $INPUT -o $OUTPUT -i --header lexer/state.h
#include <assert.h>
#include <stddef.h>
#include "lexer/state.h" // the header is generated by re2c
long lex(LexerState* st) {
const char *t;
{
unsigned char yych;
goto yy0;
yy1:
++st->cur;
yy0:
yych = *st->cur;
switch (yych) {
case 'a': goto yy1;
case 'b':
st->yyt1 = st->cur;
goto yy3;
default:
st->yyt1 = st->cur;
goto yy2;
}
yy2:
t = st->yyt1;
{ return t - st->str; }
yy3:
yych = *++st->cur;
switch (yych) {
case 'b': goto yy3;
default: goto yy2;
}
}
}
int main() {
const char *s = "ab";
LexerState st = { s, s , NULL };
assert(lex(&st) == 1);
return 0;
}
/* Generated by re2c */
typedef struct {
const char *str, *cur;
const char *yyt1;
} LexerState;
c/headers/header.re:23:21: warning: rule matches empty string [-Wmatch-empty-string]
|