File: eof_04_u.c

package info (click to toggle)
re2c 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 50,052 kB
  • sloc: cpp: 32,477; ml: 8,279; sh: 5,265; makefile: 968; haskell: 612; python: 428; ansic: 227; javascript: 111; java: 3
file content (111 lines) | stat: -rw-r--r-- 1,897 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Generated by re2c */
// re2c $INPUT -o $OUTPUT -iu
#include <stdio.h>
#include <stdint.h>
#include <string.h>

static const size_t SIZE = 4096;

struct input_t {
    uint32_t buf[SIZE + 1];
    uint32_t *lim;
    uint32_t *cur;
    uint32_t *mar;
    uint32_t *tok;
    bool eof;

    input_t()
        : buf()
        , lim(buf + SIZE)
        , cur(lim)
        , mar(lim)
        , tok(lim)
        , eof(false)
    {
        fill();
    }
    int fill()
    {
        if (eof) {
            return 1;
        }
        const size_t free = tok - buf;
        if (free < 1) {
            return 2;
        }
        memmove(buf, tok, lim - tok);
        lim -= free;
        cur -= free;
        mar -= free;
        tok -= free;
        lim += fread(lim, sizeof(uint32_t), free, stdin);
        lim[0] = 1114111;
        if (lim < buf + SIZE) {
            eof = true;
        }
        return 0;
    }
};

static bool lex(input_t & in, unsigned int &count)
{
    for (count = 0;;) {
        in.tok = in.cur;
        
{
	uint32_t yych;
yyFillLabel0:
	yych = *in.cur;
	if (yych == '\n') goto yy3;
	if (yych >= 0x0010FFFF) {
		if (in.lim <= in.cur) {
			if (in.fill() == 0) goto yyFillLabel0;
			goto yy5;
		}
		goto yy1;
	}
yy1:
	++in.cur;
yyFillLabel1:
	yych = *in.cur;
	if (yych == '\n') goto yy2;
	if (yych <= 0x0010FFFE) goto yy1;
	if (in.lim <= in.cur) {
		if (in.fill() == 0) goto yyFillLabel1;
		goto yy2;
	}
	goto yy1;
yy2:
	{ ++count; continue; }
yy3:
	++in.cur;
yyFillLabel2:
	yych = *in.cur;
	if (yych == '\n') goto yy3;
	if (yych >= 0x0010FFFF) {
		if (in.lim <= in.cur) {
			if (in.fill() == 0) goto yyFillLabel2;
		}
		goto yy4;
	}
yy4:
	{ continue; }
yy5:
	{ return true; }
}

    }
}

int main()
{
    input_t in;
    unsigned int count;
    if (lex(in, count)) {
        printf("glorious %u numbers!\n", count);
    } else {
        printf("error\n");
    }

    return 0;
}