cleanup
[advent21.git] / 02b.l
1 %option noyywrap
2 %option noinput
3 %option nounput
4 %{
5 #include <stdio.h>
6 int x = 0, z = 0, aim = 0;
7 %}
8
9 %%
10 forward\ [0-9] {
11 int num = atoi(yytext+sizeof("forward"));
12 x += num;
13 z += aim*num;
14 }
15 up\ [0-9] aim -= atoi(yytext+sizeof("up"));
16 down\ [0-9] aim += atoi(yytext+sizeof("down"));
17 \n ;
18 %%
19
20 int main (void)
21 {
22 yylex();
23 printf("%d\n", x*z);
24 return 0;
25 }