Changes for v5.8.20; see the ChangeLog and NEWS files for more details.
[gcalctool.git] / gcalctool / lr_parser.y
blob5120fc0a5bbd1b841a74b315b9ae9d21db63de45
1 %{
3 /* $Header$
5 * Copyright (C) 2004-2006 Sami Pietila
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <math.h>
26 #include <errno.h>
27 #include "calctool.h"
28 #include "functions.h"
29 #include "mpmath.h"
31 #include "parser.h"
32 #include "parser_mac.h"
33 #include "lr_parser.h"
35 extern struct parser_state parser_state;
39 %union {
40 int int_t[MP_SIZE];
43 %token NEG
45 %token tABS
46 %token tACOS
47 %token tACOSH
48 %token tAND
49 %token tANS
50 %token tASIN
51 %token tASINH
52 %token tATAN
53 %token tATANH
54 %token tCBRT
55 %token tCHS
56 %token tCOS
57 %token tCOSH
58 %token tDDB
59 %token tEXP
60 %token tFRAC
61 %token tFV
62 %token tINT
63 %token tLN
64 %token tLOG10
65 %token tNOT
66 %token tOR
67 %token tPI
68 %token tPMT
69 %token tPV
70 %token tRAND
71 %token tRATE
72 %token tSIN
73 %token tSINH
74 %token tSLN
75 %token tSQRT
76 %token tSYD
77 %token tTAN
78 %token tTANH
79 %token tTERM
80 %token tU16
81 %token tU32
82 %token tXNOR
83 %token tXOR
85 %token tRCL
86 %token tSTO
87 %token tCLR
89 %token <int_t> tINUMBER
90 %token <int_t> tDNUMBER
92 %type <int_t> exp value term rcl number parenthesis func
94 %start statement
95 %left '+' '-' '*' '/' '&' '|' 'n' 'x' '^' 'e'
96 %left NEG
97 %left POS
101 statement:
103 | value {ret($1);}
104 | error {
105 yyclearin;
106 reset_lr_tokeniser();
107 parser_state.error = EINVAL;
108 YYABORT;
112 seq:
114 | seq udf
117 udf:
118 value '=' {
119 cp($1, v->MPdisp_val);
120 show_display(v->MPdisp_val);
122 | value '=' tSTO '(' tINUMBER ')' {
123 int val;
124 mpcmi($5, &val);
125 do_sto_reg(val, $1);
127 | value tSTO '(' tINUMBER ')' {
128 int val;
129 mpcmi($4, &val);
130 do_sto_reg(val, $1);
132 | tCLR {
133 initialise();
134 show_display(v->MPdisp_val);
138 value:
139 exp {cp($1, $$);}
142 exp:
143 term {cp($1, $$);}
144 | exp '+' exp {mpadd($1, $3, $$);}
145 | exp '-' exp {mpsub($1, $3, $$);}
146 | exp '*' exp {mpmul($1, $3, $$);}
147 | exp '/' exp {mpdiv($1, $3, $$);}
148 | exp '&' exp {calc_and($$, $1, $3);}
149 | exp '|' exp {calc_or($$, $1, $3);}
150 | exp 'n' exp {calc_xnor($$, $1, $3);}
151 | exp 'x' exp {calc_xor($$, $1, $3);}
153 | exp '^' exp {calc_xpowy($1, $3, $$);}
154 | exp 'e' exp {calc_xtimestenpowx($1, $3, $$);}
156 | exp 'K' {do_tfunc($1, $$, SIN);}
157 | exp 'J' {do_tfunc($1, $$, COS);}
158 | exp 'L' {do_tfunc($1, $$, TAN);}
160 | exp 'G' {mplog10($1, $$);}
161 | exp 's' {mpsqrt($1, $$);}
162 | exp 'N' {mpln($1, $$);}
163 | exp 'u' {mpabs($1, $$);}
164 | exp ':' {mpcmf($1, $$);}
165 | exp 'i' {mpcmim($1, $$);}
166 | exp 'c' {mpneg($1, $$);}
167 | exp '!' {do_factorial($1, $$);}
168 | exp '~' {calc_not($1, $$);}
169 | exp ']' {calc_u16($1, $$);}
170 | exp '[' {calc_u32($1, $$);}
171 | exp '}' {calc_tenpowx($1, $$);}
172 | exp '{' {mpexp($1, $$);}
174 | func {cp($1, $$);}
177 func:
178 tLOG10 parenthesis {mplog10($2, $$);}
179 | term tLOG10 {mplog10($1, $$);}
180 | tSQRT parenthesis {mpsqrt($2, $$);}
181 | term tSQRT {mpsqrt($1, $$);}
182 | tLN parenthesis {mpln($2, $$);}
183 | term tLN {mpln($1, $$);}
184 | tABS parenthesis {mpabs($2, $$);}
185 | term tABS {mpabs($1, $$);}
186 | tFRAC parenthesis {mpcmf($2, $$);}
187 | term tFRAC {mpcmf($1, $$);}
188 | tINT parenthesis {mpcmim($2, $$);}
189 | term tINT {mpcmim($1, $$);}
190 | tSIN parenthesis {calc_trigfunc(sin_t, $2, $$);}
191 | term tSIN {calc_trigfunc(sin_t, $1, $$);}
192 | tCOS parenthesis {calc_trigfunc(cos_t, $2, $$);}
193 | term tCOS {calc_trigfunc(cos_t, $1, $$);}
194 | tTAN parenthesis {calc_trigfunc(tan_t, $2, $$);}
195 | term tTAN {calc_trigfunc(tan_t, $1, $$);}
198 parenthesis:
199 '(' exp ')' {cp($2, $$);}
202 term:
203 number {cp($1, $$);}
204 | rcl {cp($1, $$);}
205 | parenthesis {cp($1, $$);}
206 | '-' term %prec POS {mpneg($2, $$);}
207 | '+' term %prec POS {cp($2, $$);}
210 rcl:
211 tRCL '(' tINUMBER ')' {
212 int val;
213 mpcmi($3, &val);
214 do_rcl_reg(val, $$);
218 number:
219 tINUMBER {cp($1, $$);}
220 | tDNUMBER {cp($1, $$);}
225 int lrerror(char *s) {return 0;}
228 #if 0
230 #endif