-
Notifications
You must be signed in to change notification settings - Fork 0
/
sia2graph.lex
55 lines (45 loc) · 1.14 KB
/
sia2graph.lex
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
/*
* The scanner for sia description language
*
* @file sia2graph.lex
* @author Simon Maurer
*
* */
%{
#include <stdio.h>
#include "sia2graph.tab.h" // to get the token types that we return
#define ZZ_DECL extern int zzlex()
void zzerror ( void** sias, const char* s )
{
printf( "%d: %s\n", zzlineno, s );
}
%}
%option noinput
%option nounput
%option yylineno
%option prefix="zz"
%option noyywrap
%x comment
%%
/* skip whitespaces and CR */
[ \t] ;
\n ++zzlloc.last_line;
/* ignore comments */
"/*" BEGIN(comment);
<comment>[^*\n]* /* eat anything that's not a '*' */
<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
<comment>\n ++zzlloc.last_line;
<comment>"*"+"/" BEGIN(INITIAL);
"//".* { /* DO NOTHING */ }
/* keywords */
sia return KW_SIA;
/* identifiers */
[a-zA-Z_$0-9]* {
zzlval.sval = strdup( zztext );
return IDENTIFIER;
}
/* operators */
[.|!?;:{}] return *zztext;
/* anything else is an error */
. zzerror( NULL, "invalid character" );
%%