-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger_lex.lex
100 lines (86 loc) · 2.36 KB
/
trigger_lex.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
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
/*
* Lexer for trigger definitions.
*
* This file is part of oblsc.
*
* Copyright (C) 2010-2011 Frej Drejhammar <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
%option 8bit bison-bridge bison-locations reentrant
%option warn nodefault
%option outfile="trigger_lex.c" header-file="trigger_lex.h"
%option nounput noyywrap noinput
%option extra-type="struct state *"
%{
#include <glib.h>
#include "state.h"
#include "trigger_type.h"
#include "trigger_parse.h"
%}
DIGIT [0-9]
HEX_DIGIT [0-9a-fA-F]
OCTAL_DIGIT [0-7]
NAME [a-zA-Z][A-Za-z0-9]*
WHITESPACE [ \t\n]
%%
"," { return COMMA; }
"[" { return LBRACKET; }
"]" { return RBRACKET; }
"(" { return LPARA; }
")" { return RPARA; }
"{" { return LBRACE; }
"}" { return RBRACE; }
"=" { return EQUALS; }
"/"{DIGIT}+("."{DIGIT}*)?(""|"s"|"ms"|"us"|"ns"|"ps") {
gchar *tail;
yylval->time = strtod(yytext+1, &tail);
if (tail[0] == 's')
; /* The value does need to be scaled */
else if (tail[0] == 'm')
yylval->time *= 1e-3;
else if (tail[0] == 'u')
yylval->time *= 1e-6;
else if (tail[0] == 'n')
yylval->time *= 1e-9;
else if (tail[0] == 'p')
yylval->time *= 1e-12;
else { /* This is raw samples, convert to time */
sscanf(yytext + 1, "%d", &yylval->samples);
return SAMPLE_CNT;
}
return TIME;
}
"0x"{HEX_DIGIT}+ {
sscanf(yytext, "%x", &yylval->value);
return VALUE;
}
"0"{OCTAL_DIGIT}+ {
sscanf(yytext, "%o", &yylval->value);
return VALUE;
}
{DIGIT}+ {
sscanf(yytext, "%u", &yylval->value);
return VALUE;
}
{NAME} {
yylval->signal = state_lookup_signal(yyextra, yytext);
if (yylval->signal == NULL)
fprintf(stderr, "Error: Signal %s is not defined\n", yytext);
return SIGNAL;
}
{WHITESPACE}+ /* Ignore */
. /* Ignore */
%%