Changes for v5.8.20; see the ChangeLog and NEWS files for more details.
[gcalctool.git] / gcalctool / ce_tokeniser.l
blob1405578c209033937d0937cc0e7ede746bb2014c
1 %option noyywrap
3 %{
5 /*  $Header$
6  *
7  *  Copyright (C) 2004-2005 Sami Pietila
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2, or (at your option)
12  *  any later version.
13  *           
14  *  This program is distributed in the hope that it will be useful, but 
15  *  WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
17  *  General Public License for more details.
18  *           
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  *  02111-1307, USA.
23  */
25 #include <stdlib.h>
26 #include <locale.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #include "calctool.h"
30 #include "extern.h"
31 #include "ce_parser.h"
32 #include "ce_parser.tab.h"
35 DIGIT   [0-9]
36 DECIMAL "."|","
37 SIGN    "+"|"-" 
38 CHARACTER [a-z]|[A-Z]
39 HEX     [0-9]|[A-F]
40 BIN     "0"|"1"
41 OCT     [0-7]
42 NUMBER  [DIGIT}*{DECIMAL}{DIGIT}+|{DIGIT}
43 SEPARATOR "e+"|"e-"
47 "Abs" {return tABS;}
48 "Acosh" {return tACOSH;}
49 "Acos" {return tACOS;}
50 "And" {return tAND;}
51 "Ans" {return tANS;}
52 "Asinh" {return tASINH;}
53 "Asin" {return tASIN;}
54 "Atanh" {return tATANH;}
55 "Atan" {return tATAN;}
56 "Cbrt" {return tCBRT;}
57 "Chs" {return tCHS;}
58 "Clr" {return tCLR;}
59 "Cosh" {return tCOSH;}
60 "Cos" {return tCOS;}
61 "Ctrm" {return tCTRM;}
62 "Ddb" {return tDDB;}
63 "Eng" {return tEXP;}
64 "Frac" {return tFRAC;}
65 "Fv" {return tFV;}
66 "Int" {return tINT;}
67 "Ln" {return tLN;}
68 "Log" {return tLOG10;}
69 "Mod" {return tMOD;}
70 "Not" {return tNOT;}
71 "Or" {return tOR;}
72 "Pi" {return tPI;}
73 "Pmt" {return tPMT;}
74 "Pv" {return tPV;}
75 "Rand" {return tRAND;}
76 "Rate" {return tRATE;}
77 "Rcl" {return tRCL;}
78 "Sinh" {return tSINH;}
79 "Sin" {return tSIN;}
80 "Sln" {return tSLN;}
81 "Sqrt" {return tSQRT;}
82 "Sto" {return tSTO;}
83 "Syd" {return tSYD;}
84 "Tanh" {return tTANH;}
85 "Tan" {return tTAN;}
86 "Term" {return tTERM;}
87 "u16" {return tU16;}
88 "u32" {return tU32;}
89 "Xnor" {return tXNOR;}
90 "Xor" {return tXOR;}
92 "R"{DIGIT}+ {
93 celval.integer = atoi(yytext+1);  
94 return tREG;
98 {DIGIT}+|{HEX}+ {
99 if (strlen(yytext) > 40) parser_state.error = -PARSER_ERR_TOO_LONG_NUMBER;
100 check_numbase(yytext);
101 MPstr_to_num(yytext, v->base, celval.int_t);
102 return tINUMBER;
105 {DIGIT}*{DECIMAL}{DIGIT}+ {
106 if (strlen(yytext) > 40) parser_state.error = -PARSER_ERR_TOO_LONG_NUMBER;
107 check_numbase(yytext);
108 MPstr_to_num(yytext, v->base, celval.int_t);
109 return tDNUMBER;
113 [ \t\n]
114 .        {return *yytext; }
116 %% 
118 void
119 reset_ce_tokeniser()
121 ce_flush_buffer(YY_CURRENT_BUFFER);
125 #if 0
126 // TO BE USED LATER
128 {DIGIT}*{DECIMAL}*{DIGIT}+{SEPARATOR}{DIGIT}+ {
129 check_numbase(yytext);
130 MPstr_to_num(yytext, v->base, celval.int_t);
131 return tDNUMBER;
134 {HEX}+"h" {
135 // TODO: fix memory leak (look also following sections)
136 char *number = ce_strndup(yytext, strlen(yytext)-1);
137 MPstr_to_num(number, HEX, celval.int_t);
138 free(number);
139 return tINUMBER;
142 {BIN}+"b" {
143 char *number = ce_strndup(yytext, strlen(yytext)-1);
144 MPstr_to_num(number, BIN, celval.int_t);
145 free(number);
146 return tINUMBER;
149 {OCT}+"o" {
150 char *number = ce_strndup(yytext, strlen(yytext)-1);
151 MPstr_to_num(number, OCT, celval.int_t);
152 free(number);
153 return tINUMBER;
156 {DIGIT}+"d" {
157 char *number = ce_strndup(yytext, strlen(yytext)-1);
158 MPstr_to_num(number, DEC, celval.int_t);
159 free(number);
160 return tINUMBER;
163 {DIGIT}*{DECIMAL}{DIGIT}+"d" {
164 char *number = ce_strndup(yytext, strlen(yytext)-1);
165 MPstr_to_num(number, DEC, celval.int_t);
166 free(number);
167 return tDNUMBER;
170 #endif