2
* Copyright (C) 1997-2004 Jiri (George) Lebl
4
* Author: Jiri (George) Lebl
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
35
#include "parseutil.h"
37
extern GSList *gel_parsestack;
41
gp_push_func (gboolean vararg)
48
val = stack_pop(&gel_parsestack);
54
tree = stack_pop(&gel_parsestack);
55
if(tree && tree->type==EXPRLIST_START_NODE) {
59
/*we have gone all the way to the top and haven't found a
60
marker or tree is not an ident node*/
61
if(!tree || tree->type != IDENTIFIER_NODE) {
62
if(tree) gel_freetree(tree);
63
g_slist_foreach(list,(GFunc)gel_freetree,NULL);
67
list = g_slist_prepend(list,tree->id.id);
74
tree->type = FUNCTION_NODE;
75
tree->func.func = d_makeufunc(NULL,val,list,i, NULL);
76
tree->func.func->context = -1;
77
tree->func.func->vararg = vararg;
79
stack_push(&gel_parsestack,tree);
85
gp_prepare_push_param (gboolean setfunc)
91
/* FIXME: setfunc not yet implemented */
92
g_assert ( ! setfunc);
94
val = stack_pop (&gel_parsestack);
98
ident = stack_pop (&gel_parsestack);
102
func = gel_makenum_null ();
104
stack_push (&gel_parsestack, func);
105
stack_push (&gel_parsestack, ident);
106
stack_push (&gel_parsestack, val);
111
/* returns true if this is a 'by' sep */
113
gp_prepare_push_region_sep (void)
117
e2 = stack_pop (&gel_parsestack);
118
e1 = stack_pop (&gel_parsestack);
120
if (e2->type == OPERATOR_NODE &&
121
e2->op.oper == E_REGION_SEP) {
122
GelETree *a1 = e2->op.args;
123
GelETree *a2 = e2->op.args->any.next;
128
stack_push (&gel_parsestack, e1);
129
stack_push (&gel_parsestack, a1);
130
stack_push (&gel_parsestack, a2);
134
stack_push (&gel_parsestack, e1);
135
stack_push (&gel_parsestack, e2);
141
/*pops the last expression, pushes a marker
142
entry and puts the last expression back*/
144
gp_push_marker(GelETreeType markertype)
146
GelETree * last_expr = stack_pop(&gel_parsestack);
153
tree->type = markertype;
154
stack_push(&gel_parsestack,tree);
155
stack_push(&gel_parsestack,last_expr);
161
gp_push_marker_simple(GelETreeType markertype)
165
tree->type = markertype;
166
stack_push(&gel_parsestack,tree);
169
/*puts a spacer into the tree, spacers are just useless nodes to be removed
170
before evaluation, they just signify where there were parenthesis*/
174
GelETree * last_expr = stack_pop(&gel_parsestack);
178
else if(last_expr->type == SPACER_NODE)
179
stack_push(&gel_parsestack,last_expr);
183
tree->type = SPACER_NODE;
184
tree->sp.arg = last_expr;
185
stack_push(&gel_parsestack,tree);
190
/*gather all expressions up until a row start marker and push the
191
result as a MATRIX_ROW_NODE*/
193
gp_push_matrix_row(void)
196
GelETree *row = NULL;
199
tree = stack_pop(&gel_parsestack);
200
/*we have gone all the way to the top and haven't found a
204
GelETree *li = row->any.next;
210
if(tree->type==EXPRLIST_START_NODE) {
214
tree->any.next = row;
219
tree->type = MATRIX_ROW_NODE;
220
tree->row.args = row;
223
stack_push(&gel_parsestack,tree);
228
/*gather all expressions up until a row start marker and push the
231
gp_push_matrix(gboolean quoted)
245
tree = stack_pop(&gel_parsestack);
246
/*we have gone all the way to the top and haven't found a
250
for(li=rowl;li;li=g_slist_next(li)) {
251
GelETree *row = li->data;
253
GelETree *a = row->any.next;
259
/**/g_warning("BAD MATRIX, NO START MARKER");
261
} else if(tree->type==MATRIX_START_NODE) {
264
} else if(tree->type==MATRIX_ROW_NODE) {
265
if(tree->row.nargs>cols)
266
cols = tree->row.nargs;
267
rowl = g_slist_prepend(rowl,tree->row.args);
268
tree->row.args = NULL;
276
for(li=rowl;li;li=g_slist_next(li)) {
277
GelETree *row = li->data;
279
GelETree *a = row->any.next;
285
/**/g_warning("BAD MATRIX, A NON ROW ELEMENT FOUND");
290
matrix = gel_matrix_new();
291
gel_matrix_set_size(matrix, cols, rows, TRUE /* padding */);
293
for(j=0,liy=rowl;liy;j++,liy=g_slist_next(liy)) {
294
for(i=0,lix=liy->data;lix;i++,lix=lix->any.next) {
295
gel_matrix_index(matrix,i,j) = lix;
297
/* On non-quoted matrices fill the matrix with nulls
298
* since those may be converted to zeros */
301
gel_matrix_index (matrix, i, j) =
309
tree->type = MATRIX_NODE;
310
tree->mat.matrix = gel_matrixw_new_with_matrix(matrix);
311
tree->mat.quoted = quoted ? 1 : 0;
313
stack_push(&gel_parsestack,tree);
317
/*pushes a NULL onto the stack, null cannot be evaluated, it will be
324
tree->type = NULL_NODE;
326
stack_push(&gel_parsestack,tree);
330
gp_convert_identifier_to_bool (void)
334
val = stack_peek (&gel_parsestack);
336
val->type != IDENTIFIER_NODE) {
337
/**/g_warning ("NO IDENTIFIER TO CONVERT TO TRY TO CONVERT BOOL");
340
if (val->id.id == NULL ||
341
val->id.id->token == NULL)
344
if (strcmp (val->id.id->token, "true") == 0 ||
345
strcmp (val->id.id->token, "True") == 0 ||
346
strcmp (val->id.id->token, "TRUE") == 0) {
348
gel_makenum_bool_from (val, TRUE);
349
} else if (strcmp (val->id.id->token, "false") == 0 ||
350
strcmp (val->id.id->token, "False") == 0 ||
351
strcmp (val->id.id->token, "FALSE") == 0) {
353
gel_makenum_bool_from (val, FALSE);