1 %{
2 /*
3  * Copyright (C) 2002 Laird Breyer
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * Author:   Laird Breyer <laird@lbreyer.com>
20  */
21 
22 #include <stdlib.h>
23 #include <string.h>
24 #include "bayesol.h"
25 #include "risk-parser.h"
26   int yyerror(char *);
27   int current_lineno = 1;
28   YY_BUFFER_STATE handle;
29 %}
30 
31 EXP                "E"|"e"
32 DIGIT              [0-9]
33 DECIMAL            "."
34 SIGN               "+"|"-"
35 INF                "INF"|"inf"
36 
37 NUMBER1            {DIGIT}+{DECIMAL}{DIGIT}*{EXP}{SIGN}?{DIGIT}+|{INF}
38 NUMBER2            {DIGIT}+{DECIMAL}{DIGIT}*
39 NUMBER3            {DIGIT}+
40 NAME               [A-Za-z][A-Za-z0-9]*
41 REGEX              \"[^\"\\]*(\\.[^\"\\]*)*\"
42 VEC                \[[^\[\]]*\]
43 
44 %%
45 
46 "categories"       { return tCATEGORIES; }
47 "loss_matrix"      { return tLOSS; }
48 "prior"            { return tPRIOR; }
49 \$[0-9]            { yylval.numval = atoi(yytext + 1); if(yylval.numval > 0) yylval.numval--; return tMATCH; }
50 "complexity"       { return tCOMPLEXITY; }
51 "exp"              { return tEXP; }
52 "log"              { return tLOG; }
53 [ \t]              /* ignore white space */
54 [\n]               { current_lineno++; }
55 ^\#.*$             /* ignore comments */
56 {NUMBER1}          { yylval.numval = strtod(yytext, NULL); return tNUMBER; }
57 {NUMBER2}          { yylval.numval = strtod(yytext, NULL); return tNUMBER; }
58 {NUMBER3}          { yylval.numval = strtod(yytext, NULL); return tNUMBER; }
59 {NAME}             { yylval.strval = strdup(yytext); return tNAME; }
60 {REGEX}            { yylval.strval = strdup(yytext+1);
61                      yylval.strval[yyleng - 2] = '\0'; return tREGEX; }
62 {VEC}              { yylval.strval = strdup(yytext+1);
63                      yylval.strval[yyleng -2] = '\0'; return tVEC; }
64 .                  { return *yytext; }
65 
66 %%
67 
68 void reset_lexer() {
69   current_lineno = 1;
70 }
71 
72 void lexer_prepare_string(char *buf) {
73   handle = yy_scan_string(buf);
74 }
75 
76 void lexer_free_string() {
77   yy_delete_buffer(handle);
78 }
79