blob: 5e8d5e530fb050b68ae62807bdbe5c5807368a7c (
plain) (
blame)
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
|
%{
#include <err.h>
#include <stdbool.h>
#include <stdlib.h>
#include "parser.h"
#include "pinocchio.h"
#define YY_USER_INIT \
do { \
if (!interactive) \
BEGIN(linecont); \
} while (false);
#define LOC_STEP \
do { \
yylloc.first_line = yylloc.last_line; \
yylloc.first_column = yylloc.last_column; \
} while (false)
#define LOC_LINE \
do { \
yylloc.last_line++; \
yylloc.last_column = 1; \
} while (false)
#define YY_USER_ACTION yylloc.last_column += yyleng;
extern bool interactive;
extern const char *current_file;
%}
%option nodefault
%option noinput nounput noyywrap
ws [ \t]
%x error
%s linecont
%%
%{
LOC_STEP;
%}
¬|! { return NOT; }
∧|&& { return AND; }
∨|\|\| { return OR; }
⊻|⊕|~ { return XOR; }
⇒|=> { return IMPL; }
\<=>|⇔ { return EQUIV; }
\( { return OPAR; }
\) { return CPAR; }
\| { return '|'; }
\\ { return '\\'; }
\n {
LOC_LINE;
return EOL;
}
/* Allow line-continuation when the newline is suffixed by a
backslash, but not in interactive mode! Interactive usage should
have this functionality disabled so that you get instant feedback
after hitting the enter key. */
<linecont>\n{ws}*\\ {
LOC_LINE;
yylloc.last_column = yyleng;
}
[a-zA-Z] {
yylval.ch = *yytext;
return IDENT;
}
{ws}+ { LOC_STEP; }
/* Throw an error on an invalid token. When in interactive mode we
should slurp up all data on the current line after reporting the
error so that lexing/parsing doesn’t continue right after the
offending token but instead on the next line typed by the user. */
. {
user_error("%s:%d:%d: Unrecognized character ‘%c’",
current_file, yylloc.first_line, yylloc.first_column, *yytext);
BEGIN(error);
return YYerror;
}
<error>.*|\n { BEGIN(0); }
%%
|