File: scanner.ll

package info (click to toggle)
fityk 0.4.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,472 kB
  • ctags: 2,617
  • sloc: cpp: 19,705; sh: 5,965; xml: 2,325; yacc: 356; makefile: 183; lex: 178
file content (180 lines) | stat: -rw-r--r-- 5,819 bytes parent folder | download
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* This file is part of fityk program. Copyright (C) Marcin Wojdyr */

%{
#include "common.h"
RCSID("$Id: scanner.ll,v 1.4 2004/05/20 12:58:54 wojdyr Exp $")
#include <string>
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
#include "pag.h"
#include "parser.tab.hh"
char str_tb[1024+1];
 // table for saving strings (yytext(iptext) can be changed - %array)
 // it has to be ensured that one string is not overwritten
 // by another one before parsing expression with this string
std::string last_cmd;
void r_cmd ()
{
  last_cmd = std::string (iptext, 0, ipleng);
}
  
void start_of_string_parsing(const char *s)
{
    yy_scan_string (s);
}

void end_of_string_parsing()
{
    ip_delete_buffer(YY_CURRENT_BUFFER);
}

extern bool new_line;

%}

%option never-interactive
%option noyywrap
%option prefix="ip"
%array
%x SET_COND
%s D_UI_SLASH
%s FILE_COND
%s D_LOAD_COND

UINT [[:digit:]]+
INT [+|-]?[[:digit:]]+
FLOAT {INT}("."[[:digit:]]*)?([e|E]{INT})?
ws [ \t\v\f\r]* 
ws_ [ \t\v\f\r]+ 

%%

<*>{ws_} 	   /* ignore */
<*>(#[^\n]*)?[\n]+  BEGIN(0); last_cmd=""; new_line = true; return SEP;   
  /*<*>#[^\n]*[\n]   BEGIN(0); last_cmd.clear(); new_line = true; return SEP; */
								/*comments*/
<*>[;]+          BEGIN(0); last_cmd=""; return SEP;
<*>","           { unput (' '); /*FIXME how to do it without unput() ? */
                   for (int i = last_cmd.size() - 1; i >= 0; i--) {
                       unput(last_cmd[i]);
		   }
                   return SEP;
                 }
[dfsmoc]\.s(et)?   r_cmd(); BEGIN(SET_COND); iplval.c = iptext[0]; return SET;
d\.l(oad)?	   r_cmd(); BEGIN(D_LOAD_COND); return D_LOAD;
d\.a(ctivate)?     r_cmd(); return D_ACTIVATE;
d\.b(ackground)?   r_cmd(); return D_BACKGROUND;
d\.c(alibrate)?    r_cmd(); return D_CALIBRATE;
d\.r(ange)?	   r_cmd(); return D_RANGE;
d\.d(eviation)?    r_cmd(); return D_DEVIATION;
d\.i(nfo)?	   r_cmd(); return D_INFO;
d\.e(xport)?       r_cmd(); BEGIN(FILE_COND); return D_EXPORT;
f\.r(un)?	   r_cmd(); return F_RUN;
f\.c(ontinue)?	   r_cmd(); return F_CONTINUE;
f\.m(ethod)?	   r_cmd(); return F_METHOD;
f\.i(nfo)?	   r_cmd(); return F_INFO;
s\.a(dd)?	   r_cmd(); return S_ADD; 
s\.h(istory)?      r_cmd(); BEGIN(D_UI_SLASH); return S_HISTORY;
s\.i(nfo)?	   r_cmd(); return S_INFO;
s\.g(uess)?        r_cmd(); return S_GUESS;
s\.r(emove)?	   r_cmd(); return S_REMOVE;
s\.c(hange)?	   r_cmd(); return S_CHANGE; 
s\.f(reeze)?	   r_cmd(); return S_FREEZE;
s\.v(alue)?        r_cmd(); return S_VALUE;
s\.e(xport)?       r_cmd(); BEGIN(FILE_COND); return S_EXPORT;
m\.f(indpeak)?     r_cmd(); return M_FINDPEAK;
o\.p(lot)?	   r_cmd(); return O_PLOT; 
o\.l(og)?	   r_cmd(); BEGIN(FILE_COND); return O_LOG; 
o\.i(nclude)?	   r_cmd(); BEGIN(FILE_COND); return O_INCLUDE; 
o\.w(ait)?	   r_cmd(); return O_WAIT;
o\.d(ump)?	   r_cmd(); BEGIN(FILE_COND); return O_DUMP;
(q(uit)?)|(exit)   r_cmd(); return QUIT;

c\.w(avelength)?   r_cmd(); return C_WAVELENGTH; 
c\.a(dd)?	   r_cmd(); return C_ADD; 
c\.i(nfo)?	   r_cmd(); return C_INFO; 
c\.r(emove)?	   r_cmd(); return C_REMOVE; 
c\.e(stimate)?     r_cmd(); return C_FIND;

  
{UINT}     iplval.i = atoi (iptext); return UINt; 
{INT}      iplval.i = atoi (iptext); return INt; 
{FLOAT}    iplval.f = atof (iptext); return FLOAt; 
({UINT}"-")|({UINT}{ws_}"-"{ws_})   iplval.i = atoi (iptext); return UI_DASH; 
<D_UI_SLASH,D_LOAD_COND>{UINT}{ws}"/"  iplval.i = atoi(iptext); return UI_SLASH;
":"        return ':'; 
"/"        return '/'; 
"!"        return '!'; 
"%"        return '%'; 
"["        return '['; 
"]"        return ']'; 
"*"        return '*'; 
"."        return '.'; 
"@"        return '@'; 
"$"        return '$'; 
"^"        return '^'; 
"<"        return '<'; 
"+-"       return PLUS_MINUS; 
"}"        return '}'; 
"+"        return '+'; 
"-"        return '-'; 
"("        return '(';
")"        return ')';
"::"       return TWO_COLONS;
{ws_}[[:lower:]]/({ws_}|\n|\0)  { int i=0; while (isspace (iptext[i])) ++i; 
                             iplval.c = iptext[i]; return LOWERCASE; 
		           }
"_"{FLOAT} iplval.f = atof (iptext + 1); return P_NUM; 
"~"{FLOAT} iplval.f = atof (iptext + 1); return NEW_A; 
"@"{UINT}  iplval.i = atoi (iptext + 1); return A_NUM;
"@*"       iplval.i = -1; return A_NUM; 
"$"{UINT}  iplval.i = atoi (iptext + 1); return G_NUM; 
"$*"       iplval.i = -1; return G_NUM; 
"^"{UINT}  iplval.i = atoi (iptext + 1); return F_NUM; 
"^*"       iplval.i = -1; return F_NUM; 
"<"{UINT}  iplval.i = atoi (iptext + 1); return Z_NUM; 
"<*"       iplval.i = -1; return Z_NUM; 
"%"{UINT}  iplval.i = atoi (iptext + 1); return PH_NUM; 
"%*"       iplval.i = -1; return PH_NUM; 
"$"[[:alpha:]]  iplval.c = *(iptext + 1); return G_TYPE; 
"^"[[:alpha:]]  iplval.c = *(iptext + 1); return F_TYPE; 
"<"[[:alpha:]]  iplval.c = *(iptext + 1); return Z_TYPE; 
"%"[[:alpha:]]  iplval.c = *(iptext + 1); return PH_TYPE; 
'[^']+'    { /* 'filename' */
           strncpy (str_tb, iptext + 1, 256);
           iplval.s.c = str_tb; 
	   iplval.s.l = ipleng - 2;
	   return FILENAME;
	   }
<FILE_COND,D_LOAD_COND>[[:alpha:]./\\_][[:alnum:]./\\_-]{2,255} { /* filename */
           strncpy (str_tb, iptext, 256);
           iplval.s.c = str_tb; 
	   iplval.s.l = ipleng;
	   return FILENAME;
	   }
<SET_COND>[[:alpha:]_-]+  {
		strncpy (str_tb, iptext, 256);
	        iplval.s.c = str_tb; 
		iplval.s.l = ipleng;
		return DASH_STRING;
		}
<SET_COND>={ws}[[:alnum:].\"+-]+  {
	        strncpy (str_tb + 512, iptext + 1, 256);
	        iplval.s.c = str_tb + 512; 
		iplval.s.l = ipleng - 1;
		while (isspace(*iplval.s.c)) {
		    iplval.s.c++;
		    iplval.s.l--;
		}
		return EQ_STRING;
	       }


<*>([[:alnum:]]+|.)   { /* last rule - error */
	        strncpy (str_tb, iptext, 256);
	        iplval.s.c = str_tb; 
		iplval.s.l = ipleng;
		return LEX_ERROR;
		}