1 /* A Bison parser, made by GNU Bison 3.0.4.  */
2 
3 /* Bison implementation for Yacc-like parsers in C
4 
5    Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6 
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 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29 
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32 
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35 
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42 
43 /* Identify Bison output.  */
44 #define YYBISON 1
45 
46 /* Bison version.  */
47 #define YYBISON_VERSION "3.0.4"
48 
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51 
52 /* Pure parsers.  */
53 #define YYPURE 0
54 
55 /* Push parsers.  */
56 #define YYPUSH 0
57 
58 /* Pull parsers.  */
59 #define YYPULL 1
60 
61 
62 
63 
64 /* Copy the first part of user declarations.  */
65 #line 1 "parser.y" /* yacc.c:339  */
66 
67 /*
68  * Gnumeric Parser
69  *
70  * (C) 1998-2002 GNOME Foundation
71  * Copyright (C) 2002-2009 Morten Welinder
72  *
73  * Authors:
74  *    Miguel de Icaza (miguel@gnu.org)
75  *    Jody Goldberg (jody@gnome.org)
76  *    Morten Welinder (terra@diku.dk)
77  *    Almer S. Tigelaar (almer@gnome.org)
78  */
79 #include <gnumeric-config.h>
80 #include <glib/gi18n-lib.h>
81 #include <gnumeric.h>
82 #include <number-match.h>
83 #include <expr.h>
84 #include <expr-impl.h>
85 #include <expr-name.h>
86 #include <func.h>
87 #include <workbook.h>
88 #include <sheet.h>
89 #include <gnm-format.h>
90 #include <application.h>
91 #include <parse-util.h>
92 #include <gutils.h>
93 #include <style.h>
94 #include <value.h>
95 #include <goffice/goffice.h>
96 
97 #include <string.h>
98 #include <errno.h>
99 #include <stdlib.h>
100 
101 #define YYDEBUG 1
102 
103 /* ------------------------------------------------------------------------- */
104 /* Allocation with disposal-on-error */
105 
106 /*
107  * If some dork enters "=1+2+2*(1+" we have already allocated space for
108  * "1+2", "2", and "1" before the parser sees the syntax error and warps
109  * us to the error production in the "line" non-terminal.
110  *
111  * To make sure we can clean up, we register every allocation.  On success,
112  * nothing should be left (except the final expression which is unregistered),
113  * but on failure we must free everything allocated.
114  *
115  * Note: there is some room left for optimisation here.  Talk to terra@diku.dk
116  * before you set out to do it.
117  */
118 
119 static void
free_expr_list_list(GSList * list)120 free_expr_list_list (GSList *list)
121 {
122 	GSList *l;
123 	for (l = list; l; l = l->next)
124 		gnm_expr_list_unref (l->data);
125 	g_slist_free (list);
126 }
127 
128 typedef void (*ParseDeallocator) (void *);
129 static GPtrArray *deallocate_stack;
130 
131 static void
deallocate_init(void)132 deallocate_init (void)
133 {
134 	deallocate_stack = g_ptr_array_new ();
135 }
136 
137 static void
deallocate_uninit(void)138 deallocate_uninit (void)
139 {
140 	g_ptr_array_free (deallocate_stack, TRUE);
141 	deallocate_stack = NULL;
142 }
143 
144 static void
deallocate_all(void)145 deallocate_all (void)
146 {
147 	int i;
148 
149 	for (i = 0; i < (int)deallocate_stack->len; i += 2) {
150 		ParseDeallocator freer = g_ptr_array_index (deallocate_stack, i + 1);
151 		freer (g_ptr_array_index (deallocate_stack, i));
152 	}
153 
154 	g_ptr_array_set_size (deallocate_stack, 0);
155 }
156 
157 static void
deallocate_assert_empty(void)158 deallocate_assert_empty (void)
159 {
160 	if (deallocate_stack->len == 0)
161 		return;
162 
163 	g_warning ("deallocate_stack not empty as expected.");
164 	deallocate_all ();
165 }
166 
167 static void *
register_allocation(gpointer data,ParseDeallocator freer)168 register_allocation (gpointer data, ParseDeallocator freer)
169 {
170 	/* It's handy to be able to register and unregister NULLs.  */
171 	if (data) {
172 		int len;
173 		/*
174 		 * There are really only a few different freers, so we
175 		 * could encode the freer in the lower bits of the data
176 		 * pointer.  Unfortunately, no-one can predict how high
177 		 * Miguel would jump when he found out.
178 		 */
179 		len = deallocate_stack->len;
180 		g_ptr_array_set_size (deallocate_stack, len + 2);
181 		g_ptr_array_index (deallocate_stack, len) = data;
182 		g_ptr_array_index (deallocate_stack, len + 1) = freer;
183 	}
184 
185 	/* Returning the pointer here improved readability of the caller.  */
186 	return data;
187 }
188 
189 #define register_expr_allocation(expr) \
190   register_allocation ((gpointer)(expr), (ParseDeallocator)&gnm_expr_free)
191 
192 #define register_expr_list_allocation(list) \
193   register_allocation ((list), (ParseDeallocator)&gnm_expr_list_unref)
194 
195 #define register_expr_list_list_allocation(list) \
196   register_allocation ((list), (ParseDeallocator)&free_expr_list_list)
197 
198 static void
unregister_allocation(void const * data)199 unregister_allocation (void const *data)
200 {
201 	int i, pos;
202 
203 	/* It's handy to be able to register and unregister NULLs.  */
204 	if (!data)
205 		return;
206 
207 	pos = deallocate_stack->len - 2;
208 	if (pos >= 0 && data == g_ptr_array_index (deallocate_stack, pos)) {
209 		g_ptr_array_set_size (deallocate_stack, pos);
210 		return;
211 	}
212 
213 	/*
214 	 * Bummer.  In certain error cases, it is possible that the parser
215 	 * will reduce after it has discovered a token that will lead to an
216 	 * error.  "2/16/1800 00:00" (without the quotes) is an example.
217 	 * The first "00" is registered before the second division is
218 	 * reduced.
219 	 *
220 	 * Another example is 564077 where we deallocate out of order.
221 	 *
222 	 * This isn't a big deal -- we will just look at the entries below
223 	 * the top.
224 	 */
225 	for (i = pos - 2; i >= 0; i -= 2) {
226 		if (data == g_ptr_array_index (deallocate_stack, i)) {
227 			g_ptr_array_remove_index (deallocate_stack, i);
228 			g_ptr_array_remove_index (deallocate_stack, i);
229 			return;
230 		}
231 	}
232 
233 	g_warning ("Unbalanced allocation registration");
234 }
235 
236 /* ------------------------------------------------------------------------- */
237 
238 /* Bison/Yacc internals */
239 static int yylex (void);
240 static int yyerror (char const *s);
241 
242 typedef struct {
243 	char const *ptr;	/* current position of the lexer */
244 	char const *start;	/* start of the expression */
245 
246 	/* Location where the parsing is taking place */
247 	GnmParsePos const *pos;
248 
249 	/* loaded from convs with locale specific mappings */
250 	gunichar decimal_point;
251 	gunichar arg_sep;
252 	gunichar union_char;
253 	gunichar array_col_sep;
254 	gunichar array_row_sep;
255 	/* if arg_sep conflicts with array_col_sep or array_row_sep */
256 	int in_array_sep_is;	/* token id */
257 
258 	GnmExprParseFlags     flags;
259 	GnmConventions const *convs;
260 
261 	/* dynamic state */
262 	int in_array; /* toggled in the lexer for '{' and '}' */
263 	GnmExprList *result;
264 
265 	GnmParseError *error;
266 } ParserState;
267 
268 /* The error returned from the */
269 static ParserState *state;
270 
271 static void
report_err(ParserState * state,GError * err,char const * last,int guesstimate_of_length)272 report_err (ParserState *state, GError *err,
273 	    char const *last, int guesstimate_of_length)
274 {
275 	if (state->error != NULL) {
276 		state->error->err    	 = err;
277 		state->error->end_char   = last - state->start;
278 		state->error->begin_char = state->error->end_char - guesstimate_of_length;
279 		if (state->error->begin_char < 0)
280 			state->error->begin_char = 0;
281 	} else
282 		g_error_free (err);
283 }
284 
285 static gboolean
is_signed(const GnmExpr * expr)286 is_signed (const GnmExpr *expr)
287 {
288 	if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_UNARY_NEG)
289 		return TRUE;
290 
291 	if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_UNARY_PLUS)
292 		return TRUE;
293 
294 	if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_CONSTANT) {
295 		GnmValue const *v = expr->constant.value;
296 		return VALUE_IS_FLOAT (v) && value_get_as_float (v) < 0;
297 	}
298 
299 	return FALSE;
300 }
301 
302 /* Handle -cst for use in arrays.  Don't handle other types here.  */
303 static GnmExpr *
fold_negative_constant(GnmExpr * expr)304 fold_negative_constant (GnmExpr *expr)
305 {
306 	if (expr && GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_CONSTANT) {
307 		GnmValue *v = (GnmValue *)expr->constant.value;
308 
309 		if (VALUE_IS_FLOAT (v)) {
310 			gnm_float f = value_get_as_float (v);
311 			expr->constant.value = value_new_float (0 - f);
312 			value_release (v);
313 			return expr;
314 		}
315 	}
316 
317 	return NULL;
318 }
319 
320 /* Handle +cst for use in arrays.  Don't handle other types here.  */
321 static GnmExpr *
fold_positive_constant(GnmExpr * expr)322 fold_positive_constant (GnmExpr *expr)
323 {
324 	if (expr && GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_CONSTANT) {
325 		const GnmValue *v = expr->constant.value;
326 		if (VALUE_IS_FLOAT (v))
327 			return expr;
328 	}
329 
330 	return NULL;
331 }
332 
333 static GnmExpr *
build_unary_op(GnmExprOp op,GnmExpr * expr)334 build_unary_op (GnmExprOp op, GnmExpr *expr)
335 {
336 	if (!expr) return NULL;
337 
338 	unregister_allocation (expr);
339 	return register_expr_allocation (gnm_expr_new_unary (op, expr));
340 }
341 
342 static GnmExpr *
build_binop(GnmExpr * l,GnmExprOp op,GnmExpr * r)343 build_binop (GnmExpr *l, GnmExprOp op, GnmExpr *r)
344 {
345 	if (!l || !r) return NULL;
346 
347 	unregister_allocation (r);
348 	unregister_allocation (l);
349 	return register_expr_allocation (gnm_expr_new_binary (l, op, r));
350 }
351 
352 static GnmExpr *
build_logical(GnmExpr * l,gboolean is_and,GnmExpr * r)353 build_logical (GnmExpr *l, gboolean is_and, GnmExpr *r)
354 {
355 	static GnmFunc *and_func = NULL, *or_func = NULL;
356 
357 	if (!l || !r) return NULL;
358 
359 	if (and_func == NULL)
360 		and_func = gnm_func_lookup ("AND", NULL);
361 	if (or_func == NULL)
362 		or_func = gnm_func_lookup ("OR", NULL);
363 
364 	unregister_allocation (r);
365 	unregister_allocation (l);
366 	return register_expr_allocation
367 		(gnm_expr_new_funcall2 (is_and ? and_func : or_func, l, r));
368 }
369 
370 static GnmExpr *
build_not(GnmExpr * expr)371 build_not (GnmExpr *expr)
372 {
373 	static GnmFunc *not_func = NULL;
374 
375 	if (!expr) return NULL;
376 
377 	if (not_func == NULL)
378 		not_func = gnm_func_lookup ("NOT", NULL);
379 	unregister_allocation (expr);
380 	return register_expr_allocation
381 		(gnm_expr_new_funcall1 (not_func, expr));
382 }
383 
384 static GnmExpr *
build_exp(GnmExpr * l,GnmExpr * r)385 build_exp (GnmExpr *l, GnmExpr *r)
386 {
387 	if (is_signed (l)) {
388 		/* See bug 115941 */
389 		l = build_unary_op (GNM_EXPR_OP_PAREN, l);
390 	}
391 
392 	if (GNM_EXPR_GET_OPER (l) == GNM_EXPR_OP_EXP) {
393 		/* Add ()s to x^y^z */
394 		l = build_unary_op (GNM_EXPR_OP_PAREN, l);
395 	}
396 
397 	if (GNM_EXPR_GET_OPER (r) == GNM_EXPR_OP_EXP) {
398 		/* Add ()s to x^y^z */
399 		r = build_unary_op (GNM_EXPR_OP_PAREN, r);
400 	}
401 
402 	return build_binop (l, GNM_EXPR_OP_EXP, r);
403 }
404 
405 /*
406  * Build an array expression.
407  *
408  * Returns %NULL on failure.  Caller must YYERROR in that case.
409  */
410 static GnmExpr *
build_array(GSList * cols)411 build_array (GSList *cols)
412 {
413 	GnmValue *array;
414 	int mx, y;
415 
416 	if (!cols) {
417 		report_err (state, g_error_new (1, PERR_INVALID_EMPTY,
418 			_("An array must have at least 1 element")),
419 			state->ptr, 0);
420 		return NULL;
421 	}
422 
423 	mx = g_list_length (cols->data);
424 	array = value_new_array_empty (mx, g_slist_length (cols));
425 
426 	y = 0;
427 	while (cols) {
428 		GSList *row = cols->data;
429 		int x = 0;
430 		while (row && x < mx) {
431 			GnmExpr const *expr = row->data;
432 			GnmValue const *v = expr->constant.value;
433 
434 			g_assert (expr && GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_CONSTANT);
435 
436 			value_array_set (array, x, y, value_dup (v));
437 
438 			x++;
439 			row = row->next;
440 		}
441 		if (x < mx || row) {
442 			/* parser_error = PARSE_ERR_SYNTAX; */
443 			report_err (state, g_error_new (1, PERR_ASYMETRIC_ARRAY,
444 				_("Arrays must be rectangular")),
445 				state->ptr, 0);
446 			value_release (array);
447 			return NULL;
448 		}
449 		y++;
450 		cols = cols->next;
451 	}
452 
453 	return register_expr_allocation (gnm_expr_new_constant (array));
454 }
455 
456 /*
457  * Build a range constructor.
458  *
459  * Returns %NULL on failure.  Caller must YYERROR in that case.
460  */
461 static GnmExpr *
build_range_ctor(GnmExpr * l,GnmExpr * r,GnmExpr * validate)462 build_range_ctor (GnmExpr *l, GnmExpr *r, GnmExpr *validate)
463 {
464 	if (!l || !r) return NULL;
465 
466 	if (validate != NULL) {
467 		if (GNM_EXPR_GET_OPER (validate) != GNM_EXPR_OP_CELLREF ||
468 		    validate->cellref.ref.sheet != NULL) {
469 			report_err (state, g_error_new (1, PERR_UNEXPECTED_TOKEN,
470 				_("Constructed ranges use simple references")),
471 				state->ptr, 0);
472 			return NULL;
473 		    }
474 	}
475 
476 	unregister_allocation (r);
477 	unregister_allocation (l);
478 	return register_expr_allocation (gnm_expr_new_range_ctor (l, r));
479 }
480 
481 /*
482  * Build an intersection expression.
483  *
484  * Returns %NULL on failure.  Caller must YYERROR in that case.
485  */
486 static GnmExpr *
build_intersect(GnmExpr * l,GnmExpr * r)487 build_intersect (GnmExpr *l, GnmExpr *r)
488 {
489 	if (!l || !r) return NULL;
490 
491 	if (gnm_expr_is_rangeref (l) && gnm_expr_is_rangeref (r))
492 		return build_binop (l, GNM_EXPR_OP_INTERSECT, r);
493 	report_err (state, g_error_new (1, PERR_SET_CONTENT_MUST_BE_RANGE,
494 		_("All entries in the set must be references")),
495 		state->ptr, 0);
496 	return NULL;
497 }
498 
499 /*
500  * Build a set expression.
501  *
502  * Returns %NULL on failure.  Caller must YYERROR in that case.
503  */
504 static GnmExpr *
build_set(GnmExprList * list)505 build_set (GnmExprList *list)
506 {
507 	/* verify that every thing is a ref */
508 	GnmExprList *ptr;
509 	for (ptr = list; ptr != NULL ; ptr = ptr->next) {
510 		GnmExpr const *expr = ptr->data;
511 		if (!expr || !gnm_expr_is_rangeref (expr)) {
512 			report_err (state, g_error_new (1, PERR_SET_CONTENT_MUST_BE_RANGE,
513 				_("All entries in the set must be references")),
514 				state->ptr, 0);
515 			return NULL;
516 		}
517 	}
518 
519 	unregister_allocation (list);
520 	return register_expr_allocation (gnm_expr_new_set (list));
521 }
522 
523 /**
524  * parse_string_as_value:
525  *
526  * Try to parse the entered text as a basic value (empty, bool, int,
527  * gnm_float, err) if this succeeds, we store this as a GnmValue otherwise, we
528  * return a string.
529  */
530 static GnmExpr *
parse_string_as_value(GnmExpr * str)531 parse_string_as_value (GnmExpr *str)
532 {
533 	GnmValue *v = format_match_simple (value_peek_string (str->constant.value));
534 
535 	if (v != NULL) {
536 		unregister_allocation (str);
537 		gnm_expr_free (str);
538 		return register_expr_allocation (gnm_expr_new_constant (v));
539 	}
540 	return str;
541 }
542 
543 static const GnmExpr *
parser_simple_name(const char * str,Sheet * sheet)544 parser_simple_name (const char *str, Sheet *sheet)
545 {
546 	GnmExpr const *res;
547 	GnmNamedExpr *nexpr;
548 
549 	if (sheet) {
550 		GnmParsePos pp;
551 		parse_pos_init_sheet (&pp, sheet);
552 		nexpr = expr_name_lookup (&pp, str);
553 	} else
554 		nexpr = expr_name_lookup (state->pos, str);
555 
556 	if (nexpr == NULL) {
557 		if (state->flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_INVALID) {
558 			GError *e;
559 			e = sheet
560 				? g_error_new (1, PERR_UNKNOWN_NAME,
561 					       _("Name '%s' does not exist in sheet '%s'"),
562 					       str, sheet->name_quoted)
563 				: g_error_new (1, PERR_UNKNOWN_NAME,
564 					       _("Name '%s' does not exist"),
565 					       str);
566 			report_err (state, e, state->ptr, 0);
567 			res = NULL;
568 		} else if (!sheet && state->flags & GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS) {
569 			res = gnm_expr_new_constant (value_new_string (str));
570 		} else if (state->convs->input.name_validate (str)) {
571 			GnmParsePos pp = *state->pos;
572 			pp.sheet = sheet;
573 			/* Create a place holder */
574 			nexpr = expr_name_add (&pp, str, NULL, NULL, TRUE, NULL);
575 			res = gnm_expr_new_name (nexpr, sheet, NULL);
576 		} else {
577 			report_err (state, g_error_new (1, PERR_UNKNOWN_NAME,
578 							_("'%s' cannot be used as a name"),
579 							str),
580 				    state->ptr, 0);
581 			res = NULL;
582 		}
583 	} else
584 		res = gnm_expr_new_name (nexpr, sheet, NULL);
585 
586 	return res;
587 }
588 
589 /**
590  * parser_simple_val_or_name:
591  * @str : An expression with oper constant, whose value is a string.
592  *
593  * Check to see if a string is a simple value or failing that a named
594  * expression, if it is not create a placeholder name for it.
595  */
596 static GnmExpr *
parser_simple_val_or_name(GnmExpr * str_expr)597 parser_simple_val_or_name (GnmExpr *str_expr)
598 {
599 	GnmExpr const *res;
600 	char const *str = value_peek_string (str_expr->constant.value);
601 	GnmValue *v = format_match_simple (str);
602 
603 	/* if it is not a simple value see if it is a name */
604 	if (v == NULL) {
605 		res = parser_simple_name (str, NULL);
606 	} else
607 		res = gnm_expr_new_constant (v);
608 
609 	unregister_allocation (str_expr);
610 	gnm_expr_free (str_expr);
611 	return register_expr_allocation (res);
612 }
613 
614 static Sheet *
parser_sheet_by_name(Workbook * wb,GnmExpr * name_expr)615 parser_sheet_by_name (Workbook *wb, GnmExpr *name_expr)
616 {
617 	char const *name = value_peek_string (name_expr->constant.value);
618 	Sheet *sheet = NULL;
619 
620 	if (wb == NULL)
621 		return NULL;
622 
623 	sheet = workbook_sheet_by_name (wb, name);
624 
625 	/* Applix has absolute and relative sheet references */
626 	if (sheet == NULL && *name == '$' &&
627 	    state->convs->allow_absolute_sheet_references)
628 		sheet = workbook_sheet_by_name (wb, name + 1);
629 
630 	if (sheet == NULL)
631 		/* TODO : length is broken in the context of quoted names or
632 		 * names with escaped character */
633 		/* -1 is a kludge.  We know that this routine is only called
634 		 * when the last token was SHEET_SEP */
635 		report_err (state, g_error_new (1, PERR_UNKNOWN_SHEET,
636 			_("Unknown sheet '%s'"), name),
637 			state->ptr-1, strlen (name));
638 
639 	return sheet;
640 }
641 
642 /* Make byacc happier */
643 static int yyparse (void);
644 
645 
646 #line 647 "parser.c" /* yacc.c:339  */
647 
648 # ifndef YY_NULLPTR
649 #  if defined __cplusplus && 201103L <= __cplusplus
650 #   define YY_NULLPTR nullptr
651 #  else
652 #   define YY_NULLPTR 0
653 #  endif
654 # endif
655 
656 /* Enabling verbose error messages.  */
657 #ifdef YYERROR_VERBOSE
658 # undef YYERROR_VERBOSE
659 # define YYERROR_VERBOSE 1
660 #else
661 # define YYERROR_VERBOSE 0
662 #endif
663 
664 
665 /* Debug traces.  */
666 #ifndef YYDEBUG
667 # define YYDEBUG 0
668 #endif
669 #if YYDEBUG
670 extern int yydebug;
671 #endif
672 
673 /* Token type.  */
674 #ifndef YYTOKENTYPE
675 # define YYTOKENTYPE
676   enum yytokentype
677   {
678     STRING = 258,
679     QUOTED_STRING = 259,
680     CONSTANT = 260,
681     RANGEREF = 261,
682     tok_GTE = 262,
683     tok_LTE = 263,
684     tok_NE = 264,
685     tok_AND = 265,
686     tok_OR = 266,
687     tok_NOT = 267,
688     INTERSECT = 268,
689     ARG_SEP = 269,
690     ARRAY_COL_SEP = 270,
691     ARRAY_ROW_SEP = 271,
692     SHEET_SEP = 272,
693     INVALID_TOKEN = 273,
694     tok_WORKBOOKREF = 274,
695     tok_RIGHT_EXP = 275,
696     tok_LEFT_EXP = 276,
697     tok_NEG = 277,
698     tok_PLUS = 278,
699     RANGE_INTERSECT = 279,
700     RANGE_SEP = 280
701   };
702 #endif
703 /* Tokens.  */
704 #define STRING 258
705 #define QUOTED_STRING 259
706 #define CONSTANT 260
707 #define RANGEREF 261
708 #define tok_GTE 262
709 #define tok_LTE 263
710 #define tok_NE 264
711 #define tok_AND 265
712 #define tok_OR 266
713 #define tok_NOT 267
714 #define INTERSECT 268
715 #define ARG_SEP 269
716 #define ARRAY_COL_SEP 270
717 #define ARRAY_ROW_SEP 271
718 #define SHEET_SEP 272
719 #define INVALID_TOKEN 273
720 #define tok_WORKBOOKREF 274
721 #define tok_RIGHT_EXP 275
722 #define tok_LEFT_EXP 276
723 #define tok_NEG 277
724 #define tok_PLUS 278
725 #define RANGE_INTERSECT 279
726 #define RANGE_SEP 280
727 
728 /* Value type.  */
729 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
730 
731 union YYSTYPE
732 {
733 #line 582 "parser.y" /* yacc.c:355  */
734 
735 	GnmExpr		*expr;
736 	GnmValue	*value;
737 	GnmCellRef	*cell;
738 	GnmExprList	*list;
739 	Sheet		*sheet;
740 	Workbook	*wb;
741 
742 #line 743 "parser.c" /* yacc.c:355  */
743 };
744 
745 typedef union YYSTYPE YYSTYPE;
746 # define YYSTYPE_IS_TRIVIAL 1
747 # define YYSTYPE_IS_DECLARED 1
748 #endif
749 
750 
751 extern YYSTYPE yylval;
752 
753 int yyparse (void);
754 
755 
756 
757 /* Copy the second part of user declarations.  */
758 
759 #line 760 "parser.c" /* yacc.c:358  */
760 
761 #ifdef short
762 # undef short
763 #endif
764 
765 #ifdef YYTYPE_UINT8
766 typedef YYTYPE_UINT8 yytype_uint8;
767 #else
768 typedef unsigned char yytype_uint8;
769 #endif
770 
771 #ifdef YYTYPE_INT8
772 typedef YYTYPE_INT8 yytype_int8;
773 #else
774 typedef signed char yytype_int8;
775 #endif
776 
777 #ifdef YYTYPE_UINT16
778 typedef YYTYPE_UINT16 yytype_uint16;
779 #else
780 typedef unsigned short int yytype_uint16;
781 #endif
782 
783 #ifdef YYTYPE_INT16
784 typedef YYTYPE_INT16 yytype_int16;
785 #else
786 typedef short int yytype_int16;
787 #endif
788 
789 #ifndef YYSIZE_T
790 # ifdef __SIZE_TYPE__
791 #  define YYSIZE_T __SIZE_TYPE__
792 # elif defined size_t
793 #  define YYSIZE_T size_t
794 # elif ! defined YYSIZE_T
795 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
796 #  define YYSIZE_T size_t
797 # else
798 #  define YYSIZE_T unsigned int
799 # endif
800 #endif
801 
802 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
803 
804 #ifndef YY_
805 # if defined YYENABLE_NLS && YYENABLE_NLS
806 #  if ENABLE_NLS
807 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
808 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
809 #  endif
810 # endif
811 # ifndef YY_
812 #  define YY_(Msgid) Msgid
813 # endif
814 #endif
815 
816 #ifndef YY_ATTRIBUTE
817 # if (defined __GNUC__                                               \
818       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
819      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
820 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
821 # else
822 #  define YY_ATTRIBUTE(Spec) /* empty */
823 # endif
824 #endif
825 
826 #ifndef YY_ATTRIBUTE_PURE
827 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
828 #endif
829 
830 #ifndef YY_ATTRIBUTE_UNUSED
831 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
832 #endif
833 
834 #if !defined _Noreturn \
835      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
836 # if defined _MSC_VER && 1200 <= _MSC_VER
837 #  define _Noreturn __declspec (noreturn)
838 # else
839 #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
840 # endif
841 #endif
842 
843 /* Suppress unused-variable warnings by "using" E.  */
844 #if ! defined lint || defined __GNUC__
845 # define YYUSE(E) ((void) (E))
846 #else
847 # define YYUSE(E) /* empty */
848 #endif
849 
850 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
851 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
852 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
853     _Pragma ("GCC diagnostic push") \
854     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
855     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
856 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
857     _Pragma ("GCC diagnostic pop")
858 #else
859 # define YY_INITIAL_VALUE(Value) Value
860 #endif
861 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
862 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
863 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
864 #endif
865 #ifndef YY_INITIAL_VALUE
866 # define YY_INITIAL_VALUE(Value) /* Nothing. */
867 #endif
868 
869 
870 #if ! defined yyoverflow || YYERROR_VERBOSE
871 
872 /* The parser invokes alloca or malloc; define the necessary symbols.  */
873 
874 # ifdef YYSTACK_USE_ALLOCA
875 #  if YYSTACK_USE_ALLOCA
876 #   ifdef __GNUC__
877 #    define YYSTACK_ALLOC __builtin_alloca
878 #   elif defined __BUILTIN_VA_ARG_INCR
879 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
880 #   elif defined _AIX
881 #    define YYSTACK_ALLOC __alloca
882 #   elif defined _MSC_VER
883 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
884 #    define alloca _alloca
885 #   else
886 #    define YYSTACK_ALLOC alloca
887 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
888 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
889       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
890 #     ifndef EXIT_SUCCESS
891 #      define EXIT_SUCCESS 0
892 #     endif
893 #    endif
894 #   endif
895 #  endif
896 # endif
897 
898 # ifdef YYSTACK_ALLOC
899    /* Pacify GCC's 'empty if-body' warning.  */
900 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
901 #  ifndef YYSTACK_ALLOC_MAXIMUM
902     /* The OS might guarantee only one guard page at the bottom of the stack,
903        and a page size can be as small as 4096 bytes.  So we cannot safely
904        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
905        to allow for a few compiler-allocated temporary stack slots.  */
906 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
907 #  endif
908 # else
909 #  define YYSTACK_ALLOC YYMALLOC
910 #  define YYSTACK_FREE YYFREE
911 #  ifndef YYSTACK_ALLOC_MAXIMUM
912 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
913 #  endif
914 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
915        && ! ((defined YYMALLOC || defined malloc) \
916              && (defined YYFREE || defined free)))
917 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
918 #   ifndef EXIT_SUCCESS
919 #    define EXIT_SUCCESS 0
920 #   endif
921 #  endif
922 #  ifndef YYMALLOC
923 #   define YYMALLOC malloc
924 #   if ! defined malloc && ! defined EXIT_SUCCESS
925 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
926 #   endif
927 #  endif
928 #  ifndef YYFREE
929 #   define YYFREE free
930 #   if ! defined free && ! defined EXIT_SUCCESS
931 void free (void *); /* INFRINGES ON USER NAME SPACE */
932 #   endif
933 #  endif
934 # endif
935 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
936 
937 
938 #if (! defined yyoverflow \
939      && (! defined __cplusplus \
940          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
941 
942 /* A type that is properly aligned for any stack member.  */
943 union yyalloc
944 {
945   yytype_int16 yyss_alloc;
946   YYSTYPE yyvs_alloc;
947 };
948 
949 /* The size of the maximum gap between one aligned stack and the next.  */
950 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
951 
952 /* The size of an array large to enough to hold all stacks, each with
953    N elements.  */
954 # define YYSTACK_BYTES(N) \
955      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
956       + YYSTACK_GAP_MAXIMUM)
957 
958 # define YYCOPY_NEEDED 1
959 
960 /* Relocate STACK from its old location to the new one.  The
961    local variables YYSIZE and YYSTACKSIZE give the old and new number of
962    elements in the stack, and YYPTR gives the new location of the
963    stack.  Advance YYPTR to a properly aligned location for the next
964    stack.  */
965 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
966     do                                                                  \
967       {                                                                 \
968         YYSIZE_T yynewbytes;                                            \
969         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
970         Stack = &yyptr->Stack_alloc;                                    \
971         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
972         yyptr += yynewbytes / sizeof (*yyptr);                          \
973       }                                                                 \
974     while (0)
975 
976 #endif
977 
978 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
979 /* Copy COUNT objects from SRC to DST.  The source and destination do
980    not overlap.  */
981 # ifndef YYCOPY
982 #  if defined __GNUC__ && 1 < __GNUC__
983 #   define YYCOPY(Dst, Src, Count) \
984       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
985 #  else
986 #   define YYCOPY(Dst, Src, Count)              \
987       do                                        \
988         {                                       \
989           YYSIZE_T yyi;                         \
990           for (yyi = 0; yyi < (Count); yyi++)   \
991             (Dst)[yyi] = (Src)[yyi];            \
992         }                                       \
993       while (0)
994 #  endif
995 # endif
996 #endif /* !YYCOPY_NEEDED */
997 
998 /* YYFINAL -- State number of the termination state.  */
999 #define YYFINAL  4
1000 /* YYLAST -- Last index in YYTABLE.  */
1001 #define YYLAST   221
1002 
1003 /* YYNTOKENS -- Number of terminals.  */
1004 #define YYNTOKENS  42
1005 /* YYNNTS -- Number of nonterminals.  */
1006 #define YYNNTS  14
1007 /* YYNRULES -- Number of rules.  */
1008 #define YYNRULES  62
1009 /* YYNSTATES -- Number of states.  */
1010 #define YYNSTATES  102
1011 
1012 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
1013    by yylex, with out-of-bounds checking.  */
1014 #define YYUNDEFTOK  2
1015 #define YYMAXUTOK   280
1016 
1017 #define YYTRANSLATE(YYX)                                                \
1018   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
1019 
1020 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
1021    as returned by yylex, without out-of-bounds checking.  */
1022 static const yytype_uint8 yytranslate[] =
1023 {
1024        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1025        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1026        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1027        2,     2,     2,     2,     2,     2,     2,    30,    23,     2,
1028       36,    37,    26,    25,    33,    24,     2,    27,     2,     2,
1029        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1030       20,    22,    21,     2,     2,     2,     2,     2,     2,     2,
1031        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1032        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1033        2,    40,     2,    41,     2,     2,     2,     2,     2,     2,
1034        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1035        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1036        2,     2,     2,    38,     2,    39,     2,     2,     2,     2,
1037        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1038        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1039        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1040        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1041        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1042        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1043        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1044        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1045        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1046        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1047        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1048        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
1049        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
1050        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
1051       15,    16,    17,    18,    19,    28,    29,    31,    32,    34,
1052       35
1053 };
1054 
1055 #if YYDEBUG
1056   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
1057 static const yytype_uint16 yyrline[] =
1058 {
1059        0,   612,   612,   618,   626,   632,   635,   636,   637,   641,
1060      642,   643,   644,   645,   646,   647,   648,   649,   650,   651,
1061      652,   653,   654,   655,   656,   657,   662,   666,   670,   671,
1062      673,   691,   698,   699,   710,   731,   748,   749,   752,   753,
1063      756,   757,   785,   807,   816,   828,   829,   833,   837,   841,
1064      847,   852,   863,   873,   876,   877,   882,   887,   891,   892,
1065      897,   905,   910
1066 };
1067 #endif
1068 
1069 #if YYDEBUG || YYERROR_VERBOSE || 0
1070 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1071    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
1072 static const char *const yytname[] =
1073 {
1074   "$end", "error", "$undefined", "STRING", "QUOTED_STRING", "CONSTANT",
1075   "RANGEREF", "tok_GTE", "tok_LTE", "tok_NE", "tok_AND", "tok_OR",
1076   "tok_NOT", "INTERSECT", "ARG_SEP", "ARRAY_COL_SEP", "ARRAY_ROW_SEP",
1077   "SHEET_SEP", "INVALID_TOKEN", "tok_WORKBOOKREF", "'<'", "'>'", "'='",
1078   "'&'", "'-'", "'+'", "'*'", "'/'", "tok_RIGHT_EXP", "tok_LEFT_EXP",
1079   "'%'", "tok_NEG", "tok_PLUS", "','", "RANGE_INTERSECT", "RANGE_SEP",
1080   "'('", "')'", "'{'", "'}'", "'['", "']'", "$accept", "line", "opt_exp",
1081   "exp", "function", "string_opt_quote", "opt_sheet_sep", "workbookref",
1082   "sheetref", "cellref", "arg_list", "array_exp", "array_row",
1083   "array_rows", YY_NULLPTR
1084 };
1085 #endif
1086 
1087 # ifdef YYPRINT
1088 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
1089    (internal) symbol number NUM (which must be that of a token).  */
1090 static const yytype_uint16 yytoknum[] =
1091 {
1092        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
1093      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
1094       60,    62,    61,    38,    45,    43,    42,    47,   275,   276,
1095       37,   277,   278,    44,   279,   280,    40,    41,   123,   125,
1096       91,    93
1097 };
1098 # endif
1099 
1100 #define YYPACT_NINF -19
1101 
1102 #define yypact_value_is_default(Yystate) \
1103   (!!((Yystate) == (-19)))
1104 
1105 #define YYTABLE_NINF -38
1106 
1107 #define yytable_value_is_error(Yytable_value) \
1108   0
1109 
1110   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1111      STATE-NUM.  */
1112 static const yytype_int16 yypact[] =
1113 {
1114       62,   -19,     7,   108,   -19,   -11,    20,   -19,   -18,   108,
1115       30,   108,   108,    85,    15,     0,   129,    25,    53,    19,
1116       32,   -19,    85,    18,     2,   -19,   -19,     2,     2,    85,
1117      157,    34,   -19,   -19,   -19,    68,    70,   -19,    61,    63,
1118       38,   -19,    37,   108,   108,   108,   108,   108,   -19,   108,
1119      108,   108,   108,   108,   108,   108,   108,   108,   108,   -19,
1120      108,    66,   -19,    65,    75,   -19,    43,    49,   -19,   -19,
1121      -19,    85,   -19,   -19,   -19,    15,    15,   -19,   -19,     4,
1122        4,     4,    59,    59,     4,     4,     4,   178,   187,   187,
1123      165,   165,   165,    73,   -19,   -19,   -19,   -19,   -19,   -19,
1124      -19,   -19
1125 };
1126 
1127   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
1128      Performed when YYTABLE does not specify something else to do.  Zero
1129      means the default is an error.  */
1130 static const yytype_uint8 yydefact[] =
1131 {
1132        0,     3,     0,     0,     1,     8,     7,     6,    45,     0,
1133       39,     0,     0,    53,    58,     0,     2,    32,     0,     0,
1134        0,     9,    53,     0,    28,    38,    40,    26,    27,    53,
1135       50,     0,    36,    37,    54,     0,     0,    57,    59,    61,
1136        0,    42,     0,     0,     0,     0,     0,     0,     4,     0,
1137        0,     0,     0,     0,     0,     0,     0,     0,     0,    29,
1138        0,     0,    43,    34,     0,    33,     0,     0,    49,    47,
1139       52,    53,    30,    55,    56,    58,    58,    31,    41,    20,
1140       22,    21,    23,    24,    18,    19,    17,    16,    11,    10,
1141       12,    13,    14,    15,    25,    48,    46,    44,    35,    51,
1142       60,    62
1143 };
1144 
1145   /* YYPGOTO[NTERM-NUM].  */
1146 static const yytype_int8 yypgoto[] =
1147 {
1148      -19,   -19,   -19,    -1,     3,   -14,   -19,   -19,   -19,   -19,
1149      -13,   -19,    21,    29
1150 };
1151 
1152   /* YYDEFGOTO[NTERM-NUM].  */
1153 static const yytype_int8 yydefgoto[] =
1154 {
1155       -1,     2,     3,    30,    17,    18,    26,    19,    20,    21,
1156       31,    38,    39,    40
1157 };
1158 
1159   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
1160      positive, shift that token.  If negative, reduce the rule whose
1161      number is the opposite.  If YYTABLE_NINF, syntax error.  */
1162 static const yytype_int8 yytable[] =
1163 {
1164       37,    42,    16,    32,    33,    64,   -36,     4,    24,    66,
1165       27,    28,    46,    47,    46,    47,    70,    23,    32,    33,
1166       34,    67,    63,    33,    68,    22,    69,    52,    53,    54,
1167       55,    56,    57,    58,    59,    65,    60,   -37,    60,    35,
1168       36,    41,    79,    80,    81,    82,    83,    25,    84,    85,
1169       86,    87,    88,    89,    90,    91,    92,    93,    99,    94,
1170       61,    37,    37,     1,    96,    -5,    -5,    -5,    -5,    67,
1171       62,    72,    95,    73,    -5,    74,    75,    77,    78,    76,
1172       98,    -5,   -36,    46,    47,    22,    -5,    -5,     5,     6,
1173        7,     8,    97,    60,     0,     0,   100,     9,    -5,    29,
1174       -5,     0,    -5,    59,    10,   101,     0,    60,     0,    11,
1175       12,     5,     6,     7,     8,     0,     0,     0,     0,     0,
1176        9,    13,     0,    14,     0,    15,     0,    10,     0,     0,
1177        0,     0,    11,    12,     0,     0,    43,    44,    45,    46,
1178       47,     0,     0,    48,    13,     0,    14,     0,    15,    49,
1179       50,    51,    52,    53,    54,    55,    56,    57,    58,    59,
1180        0,     0,     0,    60,    43,    44,    45,    46,    47,     0,
1181        0,    71,     0,     0,     0,    46,    47,    49,    50,    51,
1182       52,    53,    54,    55,    56,    57,    58,    59,    46,    47,
1183        0,    60,     0,    57,    58,    59,     0,    46,    47,    60,
1184        0,     0,    53,    54,    55,    56,    57,    58,    59,     0,
1185        0,     0,    60,    55,    56,    57,    58,    59,     0,     0,
1186        0,    60
1187 };
1188 
1189 static const yytype_int8 yycheck[] =
1190 {
1191       14,    15,     3,     3,     4,    19,    17,     0,     9,    22,
1192       11,    12,    10,    11,    10,    11,    29,    35,     3,     4,
1193        5,     3,     3,     4,     6,    36,    23,    23,    24,    25,
1194       26,    27,    28,    29,    30,     3,    34,    17,    34,    24,
1195       25,    41,    43,    44,    45,    46,    47,    17,    49,    50,
1196       51,    52,    53,    54,    55,    56,    57,    58,    71,    60,
1197       35,    75,    76,     1,    61,     3,     4,     5,     6,     3,
1198       17,    37,     6,     5,    12,     5,    15,    39,    41,    16,
1199       37,    19,    17,    10,    11,    36,    24,    25,     3,     4,
1200        5,     6,    17,    34,    -1,    -1,    75,    12,    36,    14,
1201       38,    -1,    40,    30,    19,    76,    -1,    34,    -1,    24,
1202       25,     3,     4,     5,     6,    -1,    -1,    -1,    -1,    -1,
1203       12,    36,    -1,    38,    -1,    40,    -1,    19,    -1,    -1,
1204       -1,    -1,    24,    25,    -1,    -1,     7,     8,     9,    10,
1205       11,    -1,    -1,    14,    36,    -1,    38,    -1,    40,    20,
1206       21,    22,    23,    24,    25,    26,    27,    28,    29,    30,
1207       -1,    -1,    -1,    34,     7,     8,     9,    10,    11,    -1,
1208       -1,    14,    -1,    -1,    -1,    10,    11,    20,    21,    22,
1209       23,    24,    25,    26,    27,    28,    29,    30,    10,    11,
1210       -1,    34,    -1,    28,    29,    30,    -1,    10,    11,    34,
1211       -1,    -1,    24,    25,    26,    27,    28,    29,    30,    -1,
1212       -1,    -1,    34,    26,    27,    28,    29,    30,    -1,    -1,
1213       -1,    34
1214 };
1215 
1216   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1217      symbol of state STATE-NUM.  */
1218 static const yytype_uint8 yystos[] =
1219 {
1220        0,     1,    43,    44,     0,     3,     4,     5,     6,    12,
1221       19,    24,    25,    36,    38,    40,    45,    46,    47,    49,
1222       50,    51,    36,    35,    45,    17,    48,    45,    45,    14,
1223       45,    52,     3,     4,     5,    24,    25,    47,    53,    54,
1224       55,    41,    47,     7,     8,     9,    10,    11,    14,    20,
1225       21,    22,    23,    24,    25,    26,    27,    28,    29,    30,
1226       34,    35,    17,     3,    47,     3,    52,     3,     6,    46,
1227       52,    14,    37,     5,     5,    15,    16,    39,    41,    45,
1228       45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
1229       45,    45,    45,    45,    45,     6,    46,    17,    37,    52,
1230       54,    55
1231 };
1232 
1233   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
1234 static const yytype_uint8 yyr1[] =
1235 {
1236        0,    42,    43,    43,    44,    44,    45,    45,    45,    45,
1237       45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
1238       45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
1239       45,    45,    45,    45,    45,    46,    47,    47,    48,    48,
1240       49,    49,    49,    50,    50,    51,    51,    51,    51,    51,
1241       52,    52,    52,    52,    53,    53,    53,    53,    54,    54,
1242       54,    55,    55
1243 };
1244 
1245   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
1246 static const yytype_uint8 yyr2[] =
1247 {
1248        0,     2,     2,     1,     3,     0,     1,     1,     1,     1,
1249        3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
1250        3,     3,     3,     3,     3,     3,     2,     2,     2,     2,
1251        3,     3,     1,     2,     2,     4,     1,     1,     1,     0,
1252        2,     3,     2,     2,     3,     1,     3,     3,     3,     3,
1253        1,     3,     2,     0,     1,     2,     2,     1,     0,     1,
1254        3,     1,     3
1255 };
1256 
1257 
1258 #define yyerrok         (yyerrstatus = 0)
1259 #define yyclearin       (yychar = YYEMPTY)
1260 #define YYEMPTY         (-2)
1261 #define YYEOF           0
1262 
1263 #define YYACCEPT        goto yyacceptlab
1264 #define YYABORT         goto yyabortlab
1265 #define YYERROR         goto yyerrorlab
1266 
1267 
1268 #define YYRECOVERING()  (!!yyerrstatus)
1269 
1270 #define YYBACKUP(Token, Value)                                  \
1271 do                                                              \
1272   if (yychar == YYEMPTY)                                        \
1273     {                                                           \
1274       yychar = (Token);                                         \
1275       yylval = (Value);                                         \
1276       YYPOPSTACK (yylen);                                       \
1277       yystate = *yyssp;                                         \
1278       goto yybackup;                                            \
1279     }                                                           \
1280   else                                                          \
1281     {                                                           \
1282       yyerror (YY_("syntax error: cannot back up")); \
1283       YYERROR;                                                  \
1284     }                                                           \
1285 while (0)
1286 
1287 /* Error token number */
1288 #define YYTERROR        1
1289 #define YYERRCODE       256
1290 
1291 
1292 
1293 /* Enable debugging if requested.  */
1294 #if YYDEBUG
1295 
1296 # ifndef YYFPRINTF
1297 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1298 #  define YYFPRINTF fprintf
1299 # endif
1300 
1301 # define YYDPRINTF(Args)                        \
1302 do {                                            \
1303   if (yydebug)                                  \
1304     YYFPRINTF Args;                             \
1305 } while (0)
1306 
1307 /* This macro is provided for backward compatibility. */
1308 #ifndef YY_LOCATION_PRINT
1309 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1310 #endif
1311 
1312 
1313 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
1314 do {                                                                      \
1315   if (yydebug)                                                            \
1316     {                                                                     \
1317       YYFPRINTF (stderr, "%s ", Title);                                   \
1318       yy_symbol_print (stderr,                                            \
1319                   Type, Value); \
1320       YYFPRINTF (stderr, "\n");                                           \
1321     }                                                                     \
1322 } while (0)
1323 
1324 
1325 /*----------------------------------------.
1326 | Print this symbol's value on YYOUTPUT.  |
1327 `----------------------------------------*/
1328 
1329 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep)1330 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1331 {
1332   FILE *yyo = yyoutput;
1333   YYUSE (yyo);
1334   if (!yyvaluep)
1335     return;
1336 # ifdef YYPRINT
1337   if (yytype < YYNTOKENS)
1338     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1339 # endif
1340   YYUSE (yytype);
1341 }
1342 
1343 
1344 /*--------------------------------.
1345 | Print this symbol on YYOUTPUT.  |
1346 `--------------------------------*/
1347 
1348 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep)1349 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
1350 {
1351   YYFPRINTF (yyoutput, "%s %s (",
1352              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1353 
1354   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
1355   YYFPRINTF (yyoutput, ")");
1356 }
1357 
1358 /*------------------------------------------------------------------.
1359 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1360 | TOP (included).                                                   |
1361 `------------------------------------------------------------------*/
1362 
1363 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)1364 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1365 {
1366   YYFPRINTF (stderr, "Stack now");
1367   for (; yybottom <= yytop; yybottom++)
1368     {
1369       int yybot = *yybottom;
1370       YYFPRINTF (stderr, " %d", yybot);
1371     }
1372   YYFPRINTF (stderr, "\n");
1373 }
1374 
1375 # define YY_STACK_PRINT(Bottom, Top)                            \
1376 do {                                                            \
1377   if (yydebug)                                                  \
1378     yy_stack_print ((Bottom), (Top));                           \
1379 } while (0)
1380 
1381 
1382 /*------------------------------------------------.
1383 | Report that the YYRULE is going to be reduced.  |
1384 `------------------------------------------------*/
1385 
1386 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,int yyrule)1387 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
1388 {
1389   unsigned long int yylno = yyrline[yyrule];
1390   int yynrhs = yyr2[yyrule];
1391   int yyi;
1392   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1393              yyrule - 1, yylno);
1394   /* The symbols being reduced.  */
1395   for (yyi = 0; yyi < yynrhs; yyi++)
1396     {
1397       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1398       yy_symbol_print (stderr,
1399                        yystos[yyssp[yyi + 1 - yynrhs]],
1400                        &(yyvsp[(yyi + 1) - (yynrhs)])
1401                                               );
1402       YYFPRINTF (stderr, "\n");
1403     }
1404 }
1405 
1406 # define YY_REDUCE_PRINT(Rule)          \
1407 do {                                    \
1408   if (yydebug)                          \
1409     yy_reduce_print (yyssp, yyvsp, Rule); \
1410 } while (0)
1411 
1412 /* Nonzero means print parse trace.  It is left uninitialized so that
1413    multiple parsers can coexist.  */
1414 int yydebug;
1415 #else /* !YYDEBUG */
1416 # define YYDPRINTF(Args)
1417 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1418 # define YY_STACK_PRINT(Bottom, Top)
1419 # define YY_REDUCE_PRINT(Rule)
1420 #endif /* !YYDEBUG */
1421 
1422 
1423 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1424 #ifndef YYINITDEPTH
1425 # define YYINITDEPTH 200
1426 #endif
1427 
1428 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1429    if the built-in stack extension method is used).
1430 
1431    Do not make this value too large; the results are undefined if
1432    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1433    evaluated with infinite-precision integer arithmetic.  */
1434 
1435 #ifndef YYMAXDEPTH
1436 # define YYMAXDEPTH 10000
1437 #endif
1438 
1439 
1440 #if YYERROR_VERBOSE
1441 
1442 # ifndef yystrlen
1443 #  if defined __GLIBC__ && defined _STRING_H
1444 #   define yystrlen strlen
1445 #  else
1446 /* Return the length of YYSTR.  */
1447 static YYSIZE_T
yystrlen(const char * yystr)1448 yystrlen (const char *yystr)
1449 {
1450   YYSIZE_T yylen;
1451   for (yylen = 0; yystr[yylen]; yylen++)
1452     continue;
1453   return yylen;
1454 }
1455 #  endif
1456 # endif
1457 
1458 # ifndef yystpcpy
1459 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1460 #   define yystpcpy stpcpy
1461 #  else
1462 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1463    YYDEST.  */
1464 static char *
yystpcpy(char * yydest,const char * yysrc)1465 yystpcpy (char *yydest, const char *yysrc)
1466 {
1467   char *yyd = yydest;
1468   const char *yys = yysrc;
1469 
1470   while ((*yyd++ = *yys++) != '\0')
1471     continue;
1472 
1473   return yyd - 1;
1474 }
1475 #  endif
1476 # endif
1477 
1478 # ifndef yytnamerr
1479 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1480    quotes and backslashes, so that it's suitable for yyerror.  The
1481    heuristic is that double-quoting is unnecessary unless the string
1482    contains an apostrophe, a comma, or backslash (other than
1483    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1484    null, do not copy; instead, return the length of what the result
1485    would have been.  */
1486 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)1487 yytnamerr (char *yyres, const char *yystr)
1488 {
1489   if (*yystr == '"')
1490     {
1491       YYSIZE_T yyn = 0;
1492       char const *yyp = yystr;
1493 
1494       for (;;)
1495         switch (*++yyp)
1496           {
1497           case '\'':
1498           case ',':
1499             goto do_not_strip_quotes;
1500 
1501           case '\\':
1502             if (*++yyp != '\\')
1503               goto do_not_strip_quotes;
1504             /* Fall through.  */
1505           default:
1506             if (yyres)
1507               yyres[yyn] = *yyp;
1508             yyn++;
1509             break;
1510 
1511           case '"':
1512             if (yyres)
1513               yyres[yyn] = '\0';
1514             return yyn;
1515           }
1516     do_not_strip_quotes: ;
1517     }
1518 
1519   if (! yyres)
1520     return yystrlen (yystr);
1521 
1522   return yystpcpy (yyres, yystr) - yyres;
1523 }
1524 # endif
1525 
1526 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1527    about the unexpected token YYTOKEN for the state stack whose top is
1528    YYSSP.
1529 
1530    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1531    not large enough to hold the message.  In that case, also set
1532    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1533    required number of bytes is too large to store.  */
1534 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)1535 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1536                 yytype_int16 *yyssp, int yytoken)
1537 {
1538   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1539   YYSIZE_T yysize = yysize0;
1540   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1541   /* Internationalized format string. */
1542   const char *yyformat = YY_NULLPTR;
1543   /* Arguments of yyformat. */
1544   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1545   /* Number of reported tokens (one for the "unexpected", one per
1546      "expected"). */
1547   int yycount = 0;
1548 
1549   /* There are many possibilities here to consider:
1550      - If this state is a consistent state with a default action, then
1551        the only way this function was invoked is if the default action
1552        is an error action.  In that case, don't check for expected
1553        tokens because there are none.
1554      - The only way there can be no lookahead present (in yychar) is if
1555        this state is a consistent state with a default action.  Thus,
1556        detecting the absence of a lookahead is sufficient to determine
1557        that there is no unexpected or expected token to report.  In that
1558        case, just report a simple "syntax error".
1559      - Don't assume there isn't a lookahead just because this state is a
1560        consistent state with a default action.  There might have been a
1561        previous inconsistent state, consistent state with a non-default
1562        action, or user semantic action that manipulated yychar.
1563      - Of course, the expected token list depends on states to have
1564        correct lookahead information, and it depends on the parser not
1565        to perform extra reductions after fetching a lookahead from the
1566        scanner and before detecting a syntax error.  Thus, state merging
1567        (from LALR or IELR) and default reductions corrupt the expected
1568        token list.  However, the list is correct for canonical LR with
1569        one exception: it will still contain any token that will not be
1570        accepted due to an error action in a later state.
1571   */
1572   if (yytoken != YYEMPTY)
1573     {
1574       int yyn = yypact[*yyssp];
1575       yyarg[yycount++] = yytname[yytoken];
1576       if (!yypact_value_is_default (yyn))
1577         {
1578           /* Start YYX at -YYN if negative to avoid negative indexes in
1579              YYCHECK.  In other words, skip the first -YYN actions for
1580              this state because they are default actions.  */
1581           int yyxbegin = yyn < 0 ? -yyn : 0;
1582           /* Stay within bounds of both yycheck and yytname.  */
1583           int yychecklim = YYLAST - yyn + 1;
1584           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1585           int yyx;
1586 
1587           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1588             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1589                 && !yytable_value_is_error (yytable[yyx + yyn]))
1590               {
1591                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1592                   {
1593                     yycount = 1;
1594                     yysize = yysize0;
1595                     break;
1596                   }
1597                 yyarg[yycount++] = yytname[yyx];
1598                 {
1599                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1600                   if (! (yysize <= yysize1
1601                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1602                     return 2;
1603                   yysize = yysize1;
1604                 }
1605               }
1606         }
1607     }
1608 
1609   switch (yycount)
1610     {
1611 # define YYCASE_(N, S)                      \
1612       case N:                               \
1613         yyformat = S;                       \
1614       break
1615       YYCASE_(0, YY_("syntax error"));
1616       YYCASE_(1, YY_("syntax error, unexpected %s"));
1617       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1618       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1619       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1620       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1621 # undef YYCASE_
1622     }
1623 
1624   {
1625     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1626     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1627       return 2;
1628     yysize = yysize1;
1629   }
1630 
1631   if (*yymsg_alloc < yysize)
1632     {
1633       *yymsg_alloc = 2 * yysize;
1634       if (! (yysize <= *yymsg_alloc
1635              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1636         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1637       return 1;
1638     }
1639 
1640   /* Avoid sprintf, as that infringes on the user's name space.
1641      Don't have undefined behavior even if the translation
1642      produced a string with the wrong number of "%s"s.  */
1643   {
1644     char *yyp = *yymsg;
1645     int yyi = 0;
1646     while ((*yyp = *yyformat) != '\0')
1647       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1648         {
1649           yyp += yytnamerr (yyp, yyarg[yyi++]);
1650           yyformat += 2;
1651         }
1652       else
1653         {
1654           yyp++;
1655           yyformat++;
1656         }
1657   }
1658   return 0;
1659 }
1660 #endif /* YYERROR_VERBOSE */
1661 
1662 /*-----------------------------------------------.
1663 | Release the memory associated to this symbol.  |
1664 `-----------------------------------------------*/
1665 
1666 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep)1667 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1668 {
1669   YYUSE (yyvaluep);
1670   if (!yymsg)
1671     yymsg = "Deleting";
1672   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1673 
1674   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1675   YYUSE (yytype);
1676   YY_IGNORE_MAYBE_UNINITIALIZED_END
1677 }
1678 
1679 
1680 
1681 
1682 /* The lookahead symbol.  */
1683 int yychar;
1684 
1685 /* The semantic value of the lookahead symbol.  */
1686 YYSTYPE yylval;
1687 /* Number of syntax errors so far.  */
1688 int yynerrs;
1689 
1690 
1691 /*----------.
1692 | yyparse.  |
1693 `----------*/
1694 
1695 int
yyparse(void)1696 yyparse (void)
1697 {
1698     int yystate;
1699     /* Number of tokens to shift before error messages enabled.  */
1700     int yyerrstatus;
1701 
1702     /* The stacks and their tools:
1703        'yyss': related to states.
1704        'yyvs': related to semantic values.
1705 
1706        Refer to the stacks through separate pointers, to allow yyoverflow
1707        to reallocate them elsewhere.  */
1708 
1709     /* The state stack.  */
1710     yytype_int16 yyssa[YYINITDEPTH];
1711     yytype_int16 *yyss;
1712     yytype_int16 *yyssp;
1713 
1714     /* The semantic value stack.  */
1715     YYSTYPE yyvsa[YYINITDEPTH];
1716     YYSTYPE *yyvs;
1717     YYSTYPE *yyvsp;
1718 
1719     YYSIZE_T yystacksize;
1720 
1721   int yyn;
1722   int yyresult;
1723   /* Lookahead token as an internal (translated) token number.  */
1724   int yytoken = 0;
1725   /* The variables used to return semantic value and location from the
1726      action routines.  */
1727   YYSTYPE yyval;
1728 
1729 #if YYERROR_VERBOSE
1730   /* Buffer for error messages, and its allocated size.  */
1731   char yymsgbuf[128];
1732   char *yymsg = yymsgbuf;
1733   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1734 #endif
1735 
1736 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1737 
1738   /* The number of symbols on the RHS of the reduced rule.
1739      Keep to zero when no symbol should be popped.  */
1740   int yylen = 0;
1741 
1742   yyssp = yyss = yyssa;
1743   yyvsp = yyvs = yyvsa;
1744   yystacksize = YYINITDEPTH;
1745 
1746   YYDPRINTF ((stderr, "Starting parse\n"));
1747 
1748   yystate = 0;
1749   yyerrstatus = 0;
1750   yynerrs = 0;
1751   yychar = YYEMPTY; /* Cause a token to be read.  */
1752   goto yysetstate;
1753 
1754 /*------------------------------------------------------------.
1755 | yynewstate -- Push a new state, which is found in yystate.  |
1756 `------------------------------------------------------------*/
1757  yynewstate:
1758   /* In all cases, when you get here, the value and location stacks
1759      have just been pushed.  So pushing a state here evens the stacks.  */
1760   yyssp++;
1761 
1762  yysetstate:
1763   *yyssp = yystate;
1764 
1765   if (yyss + yystacksize - 1 <= yyssp)
1766     {
1767       /* Get the current used size of the three stacks, in elements.  */
1768       YYSIZE_T yysize = yyssp - yyss + 1;
1769 
1770 #ifdef yyoverflow
1771       {
1772         /* Give user a chance to reallocate the stack.  Use copies of
1773            these so that the &'s don't force the real ones into
1774            memory.  */
1775         YYSTYPE *yyvs1 = yyvs;
1776         yytype_int16 *yyss1 = yyss;
1777 
1778         /* Each stack pointer address is followed by the size of the
1779            data in use in that stack, in bytes.  This used to be a
1780            conditional around just the two extra args, but that might
1781            be undefined if yyoverflow is a macro.  */
1782         yyoverflow (YY_("memory exhausted"),
1783                     &yyss1, yysize * sizeof (*yyssp),
1784                     &yyvs1, yysize * sizeof (*yyvsp),
1785                     &yystacksize);
1786 
1787         yyss = yyss1;
1788         yyvs = yyvs1;
1789       }
1790 #else /* no yyoverflow */
1791 # ifndef YYSTACK_RELOCATE
1792       goto yyexhaustedlab;
1793 # else
1794       /* Extend the stack our own way.  */
1795       if (YYMAXDEPTH <= yystacksize)
1796         goto yyexhaustedlab;
1797       yystacksize *= 2;
1798       if (YYMAXDEPTH < yystacksize)
1799         yystacksize = YYMAXDEPTH;
1800 
1801       {
1802         yytype_int16 *yyss1 = yyss;
1803         union yyalloc *yyptr =
1804           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1805         if (! yyptr)
1806           goto yyexhaustedlab;
1807         YYSTACK_RELOCATE (yyss_alloc, yyss);
1808         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1809 #  undef YYSTACK_RELOCATE
1810         if (yyss1 != yyssa)
1811           YYSTACK_FREE (yyss1);
1812       }
1813 # endif
1814 #endif /* no yyoverflow */
1815 
1816       yyssp = yyss + yysize - 1;
1817       yyvsp = yyvs + yysize - 1;
1818 
1819       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1820                   (unsigned long int) yystacksize));
1821 
1822       if (yyss + yystacksize - 1 <= yyssp)
1823         YYABORT;
1824     }
1825 
1826   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1827 
1828   if (yystate == YYFINAL)
1829     YYACCEPT;
1830 
1831   goto yybackup;
1832 
1833 /*-----------.
1834 | yybackup.  |
1835 `-----------*/
1836 yybackup:
1837 
1838   /* Do appropriate processing given the current state.  Read a
1839      lookahead token if we need one and don't already have one.  */
1840 
1841   /* First try to decide what to do without reference to lookahead token.  */
1842   yyn = yypact[yystate];
1843   if (yypact_value_is_default (yyn))
1844     goto yydefault;
1845 
1846   /* Not known => get a lookahead token if don't already have one.  */
1847 
1848   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1849   if (yychar == YYEMPTY)
1850     {
1851       YYDPRINTF ((stderr, "Reading a token: "));
1852       yychar = yylex ();
1853     }
1854 
1855   if (yychar <= YYEOF)
1856     {
1857       yychar = yytoken = YYEOF;
1858       YYDPRINTF ((stderr, "Now at end of input.\n"));
1859     }
1860   else
1861     {
1862       yytoken = YYTRANSLATE (yychar);
1863       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1864     }
1865 
1866   /* If the proper action on seeing token YYTOKEN is to reduce or to
1867      detect an error, take that action.  */
1868   yyn += yytoken;
1869   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1870     goto yydefault;
1871   yyn = yytable[yyn];
1872   if (yyn <= 0)
1873     {
1874       if (yytable_value_is_error (yyn))
1875         goto yyerrlab;
1876       yyn = -yyn;
1877       goto yyreduce;
1878     }
1879 
1880   /* Count tokens shifted since error; after three, turn off error
1881      status.  */
1882   if (yyerrstatus)
1883     yyerrstatus--;
1884 
1885   /* Shift the lookahead token.  */
1886   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1887 
1888   /* Discard the shifted token.  */
1889   yychar = YYEMPTY;
1890 
1891   yystate = yyn;
1892   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1893   *++yyvsp = yylval;
1894   YY_IGNORE_MAYBE_UNINITIALIZED_END
1895 
1896   goto yynewstate;
1897 
1898 
1899 /*-----------------------------------------------------------.
1900 | yydefault -- do the default action for the current state.  |
1901 `-----------------------------------------------------------*/
1902 yydefault:
1903   yyn = yydefact[yystate];
1904   if (yyn == 0)
1905     goto yyerrlab;
1906   goto yyreduce;
1907 
1908 
1909 /*-----------------------------.
1910 | yyreduce -- Do a reduction.  |
1911 `-----------------------------*/
1912 yyreduce:
1913   /* yyn is the number of a rule to reduce with.  */
1914   yylen = yyr2[yyn];
1915 
1916   /* If YYLEN is nonzero, implement the default value of the action:
1917      '$$ = $1'.
1918 
1919      Otherwise, the following line sets YYVAL to garbage.
1920      This behavior is undocumented and Bison
1921      users should not rely upon it.  Assigning to YYVAL
1922      unconditionally makes the parser a bit smaller, and it avoids a
1923      GCC warning that YYVAL may be used uninitialized.  */
1924   yyval = yyvsp[1-yylen];
1925 
1926 
1927   YY_REDUCE_PRINT (yyn);
1928   switch (yyn)
1929     {
1930         case 2:
1931 #line 612 "parser.y" /* yacc.c:1646  */
1932     {
1933 		unregister_allocation ((yyvsp[0].expr));
1934 		unregister_allocation ((yyvsp[-1].list));
1935 		state->result = gnm_expr_list_prepend ((yyvsp[-1].list), (yyvsp[0].expr));
1936 	}
1937 #line 1938 "parser.c" /* yacc.c:1646  */
1938     break;
1939 
1940   case 3:
1941 #line 618 "parser.y" /* yacc.c:1646  */
1942     {
1943 		if (state->result != NULL) {
1944 			gnm_expr_list_unref (state->result);
1945 			state->result = NULL;
1946 		}
1947 	}
1948 #line 1949 "parser.c" /* yacc.c:1646  */
1949     break;
1950 
1951   case 4:
1952 #line 626 "parser.y" /* yacc.c:1646  */
1953     {
1954 	       unregister_allocation ((yyvsp[-1].expr));
1955 	       unregister_allocation ((yyvsp[-2].list));
1956 	       (yyval.list) = gnm_expr_list_prepend ((yyvsp[-2].list), (yyvsp[-1].expr));
1957 	       register_expr_list_allocation ((yyval.list));
1958 	}
1959 #line 1960 "parser.c" /* yacc.c:1646  */
1960     break;
1961 
1962   case 5:
1963 #line 632 "parser.y" /* yacc.c:1646  */
1964     { (yyval.list) = NULL; register_expr_list_allocation ((yyval.list)); }
1965 #line 1966 "parser.c" /* yacc.c:1646  */
1966     break;
1967 
1968   case 6:
1969 #line 635 "parser.y" /* yacc.c:1646  */
1970     { (yyval.expr) = (yyvsp[0].expr); }
1971 #line 1972 "parser.c" /* yacc.c:1646  */
1972     break;
1973 
1974   case 7:
1975 #line 636 "parser.y" /* yacc.c:1646  */
1976     { (yyval.expr) = (yyvsp[0].expr); }
1977 #line 1978 "parser.c" /* yacc.c:1646  */
1978     break;
1979 
1980   case 8:
1981 #line 637 "parser.y" /* yacc.c:1646  */
1982     {
1983 		(yyval.expr) = parser_simple_val_or_name ((yyvsp[0].expr));
1984 		if ((yyval.expr) == NULL) { YYERROR; }
1985 	}
1986 #line 1987 "parser.c" /* yacc.c:1646  */
1987     break;
1988 
1989   case 9:
1990 #line 641 "parser.y" /* yacc.c:1646  */
1991     { (yyval.expr) = (yyvsp[0].expr); }
1992 #line 1993 "parser.c" /* yacc.c:1646  */
1993     break;
1994 
1995   case 10:
1996 #line 642 "parser.y" /* yacc.c:1646  */
1997     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_ADD,	(yyvsp[0].expr)); }
1998 #line 1999 "parser.c" /* yacc.c:1646  */
1999     break;
2000 
2001   case 11:
2002 #line 643 "parser.y" /* yacc.c:1646  */
2003     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_SUB,	(yyvsp[0].expr)); }
2004 #line 2005 "parser.c" /* yacc.c:1646  */
2005     break;
2006 
2007   case 12:
2008 #line 644 "parser.y" /* yacc.c:1646  */
2009     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_MULT,	(yyvsp[0].expr)); }
2010 #line 2011 "parser.c" /* yacc.c:1646  */
2011     break;
2012 
2013   case 13:
2014 #line 645 "parser.y" /* yacc.c:1646  */
2015     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_DIV,	(yyvsp[0].expr)); }
2016 #line 2017 "parser.c" /* yacc.c:1646  */
2017     break;
2018 
2019   case 14:
2020 #line 646 "parser.y" /* yacc.c:1646  */
2021     { (yyval.expr) = build_exp ((yyvsp[-2].expr), (yyvsp[0].expr)); }
2022 #line 2023 "parser.c" /* yacc.c:1646  */
2023     break;
2024 
2025   case 15:
2026 #line 647 "parser.y" /* yacc.c:1646  */
2027     { (yyval.expr) = build_exp ((yyvsp[-2].expr), (yyvsp[0].expr)); }
2028 #line 2029 "parser.c" /* yacc.c:1646  */
2029     break;
2030 
2031   case 16:
2032 #line 648 "parser.y" /* yacc.c:1646  */
2033     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_CAT,	(yyvsp[0].expr)); }
2034 #line 2035 "parser.c" /* yacc.c:1646  */
2035     break;
2036 
2037   case 17:
2038 #line 649 "parser.y" /* yacc.c:1646  */
2039     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_EQUAL,	(yyvsp[0].expr)); }
2040 #line 2041 "parser.c" /* yacc.c:1646  */
2041     break;
2042 
2043   case 18:
2044 #line 650 "parser.y" /* yacc.c:1646  */
2045     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_LT,		(yyvsp[0].expr)); }
2046 #line 2047 "parser.c" /* yacc.c:1646  */
2047     break;
2048 
2049   case 19:
2050 #line 651 "parser.y" /* yacc.c:1646  */
2051     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_GT,		(yyvsp[0].expr)); }
2052 #line 2053 "parser.c" /* yacc.c:1646  */
2053     break;
2054 
2055   case 20:
2056 #line 652 "parser.y" /* yacc.c:1646  */
2057     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_GTE,	(yyvsp[0].expr)); }
2058 #line 2059 "parser.c" /* yacc.c:1646  */
2059     break;
2060 
2061   case 21:
2062 #line 653 "parser.y" /* yacc.c:1646  */
2063     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_NOT_EQUAL,	(yyvsp[0].expr)); }
2064 #line 2065 "parser.c" /* yacc.c:1646  */
2065     break;
2066 
2067   case 22:
2068 #line 654 "parser.y" /* yacc.c:1646  */
2069     { (yyval.expr) = build_binop ((yyvsp[-2].expr), GNM_EXPR_OP_LTE,	(yyvsp[0].expr)); }
2070 #line 2071 "parser.c" /* yacc.c:1646  */
2071     break;
2072 
2073   case 23:
2074 #line 655 "parser.y" /* yacc.c:1646  */
2075     { (yyval.expr) = build_logical ((yyvsp[-2].expr), TRUE,	(yyvsp[0].expr)); }
2076 #line 2077 "parser.c" /* yacc.c:1646  */
2077     break;
2078 
2079   case 24:
2080 #line 656 "parser.y" /* yacc.c:1646  */
2081     { (yyval.expr) = build_logical ((yyvsp[-2].expr), FALSE, (yyvsp[0].expr)); }
2082 #line 2083 "parser.c" /* yacc.c:1646  */
2083     break;
2084 
2085   case 25:
2086 #line 657 "parser.y" /* yacc.c:1646  */
2087     {
2088 		(yyval.expr) = build_intersect ((yyvsp[-2].expr), (yyvsp[0].expr));
2089 		if ((yyval.expr) == NULL) { YYERROR; }
2090 	}
2091 #line 2092 "parser.c" /* yacc.c:1646  */
2092     break;
2093 
2094   case 26:
2095 #line 662 "parser.y" /* yacc.c:1646  */
2096     {
2097 		GnmExpr *tmp = fold_negative_constant ((yyvsp[0].expr));
2098 		(yyval.expr) = tmp ? tmp : build_unary_op (GNM_EXPR_OP_UNARY_NEG, (yyvsp[0].expr));
2099 	}
2100 #line 2101 "parser.c" /* yacc.c:1646  */
2101     break;
2102 
2103   case 27:
2104 #line 666 "parser.y" /* yacc.c:1646  */
2105     {
2106 		/* Don't fold here.  */
2107 		(yyval.expr) = build_unary_op (GNM_EXPR_OP_UNARY_PLUS, (yyvsp[0].expr));
2108 	}
2109 #line 2110 "parser.c" /* yacc.c:1646  */
2110     break;
2111 
2112   case 28:
2113 #line 670 "parser.y" /* yacc.c:1646  */
2114     { (yyval.expr) = build_not ((yyvsp[0].expr)); }
2115 #line 2116 "parser.c" /* yacc.c:1646  */
2116     break;
2117 
2118   case 29:
2119 #line 671 "parser.y" /* yacc.c:1646  */
2120     { (yyval.expr) = build_unary_op (GNM_EXPR_OP_PERCENTAGE, (yyvsp[-1].expr)); }
2121 #line 2122 "parser.c" /* yacc.c:1646  */
2122     break;
2123 
2124   case 30:
2125 #line 673 "parser.y" /* yacc.c:1646  */
2126     {
2127 		if ((yyvsp[-1].list) == NULL) {
2128 			report_err (state, g_error_new (1, PERR_INVALID_EMPTY,
2129 				_("() is an invalid expression")),
2130 				state->ptr-2, 2);
2131 			YYERROR;
2132 		} else {
2133 			if ((yyvsp[-1].list)->next == NULL) {
2134 				unregister_allocation ((yyvsp[-1].list));
2135 				(yyval.expr) = register_expr_allocation (gnm_expr_new_unary (GNM_EXPR_OP_PAREN, (yyvsp[-1].list)->data));
2136 				/* NOTE : free list not content */
2137 				gnm_expr_list_free ((yyvsp[-1].list));
2138 			} else {
2139 				(yyval.expr) = build_set ((yyvsp[-1].list));
2140 				if ((yyval.expr) == NULL) { YYERROR; }
2141 			}
2142 		}
2143 	}
2144 #line 2145 "parser.c" /* yacc.c:1646  */
2145     break;
2146 
2147   case 31:
2148 #line 691 "parser.y" /* yacc.c:1646  */
2149     {
2150 		unregister_allocation ((yyvsp[-1].list));
2151 		(yyval.expr) = build_array ((yyvsp[-1].list));
2152 		free_expr_list_list ((yyvsp[-1].list));
2153 		if ((yyval.expr) == NULL) { YYERROR; }
2154 	}
2155 #line 2156 "parser.c" /* yacc.c:1646  */
2156     break;
2157 
2158   case 33:
2159 #line 699 "parser.y" /* yacc.c:1646  */
2160     {
2161 		char const *name = value_peek_string ((yyvsp[0].expr)->constant.value);
2162 		GnmExpr const *ename = parser_simple_name (name, (yyvsp[-1].sheet));
2163 
2164 		if (ename) {
2165 			unregister_allocation ((yyvsp[0].expr)); gnm_expr_free ((yyvsp[0].expr));
2166 			(yyval.expr) = register_expr_allocation (ename);
2167 		} else {
2168 			YYERROR;
2169 		}
2170 	}
2171 #line 2172 "parser.c" /* yacc.c:1646  */
2172     break;
2173 
2174   case 34:
2175 #line 710 "parser.y" /* yacc.c:1646  */
2176     {
2177 		GnmNamedExpr *nexpr = NULL;
2178 		char const *name = value_peek_string ((yyvsp[0].expr)->constant.value);
2179 		GnmParsePos pos = *state->pos;
2180 
2181 		pos.sheet = NULL;
2182 		pos.wb = (yyvsp[-1].wb);
2183 		nexpr = expr_name_lookup (&pos, name);
2184 		if (nexpr != NULL) {
2185 			unregister_allocation ((yyvsp[0].expr)); gnm_expr_free ((yyvsp[0].expr));
2186 			(yyval.expr) = register_expr_allocation (gnm_expr_new_name (nexpr, NULL, (yyvsp[-1].wb)));
2187 		} else {
2188 			report_err (state, g_error_new (1, PERR_UNKNOWN_NAME,
2189 				_("Name '%s' does not exist in workbook"),
2190 							name),
2191 				state->ptr, strlen (name));
2192 			YYERROR;
2193 		}
2194 	}
2195 #line 2196 "parser.c" /* yacc.c:1646  */
2196     break;
2197 
2198   case 35:
2199 #line 731 "parser.y" /* yacc.c:1646  */
2200     {
2201 		char const *name = value_peek_string ((yyvsp[-3].expr)->constant.value);
2202 		GnmExpr const *f_call = (*state->convs->input.func) (
2203 			state->convs, state->pos->wb, name, (yyvsp[-1].list));
2204 
2205 		(yyval.expr) = NULL;
2206 		if (f_call) {
2207 			/* We're done with the function name.  */
2208 			unregister_allocation ((yyvsp[-3].expr)); gnm_expr_free ((yyvsp[-3].expr));
2209 			unregister_allocation ((yyvsp[-1].list));
2210 			(yyval.expr) = register_expr_allocation (f_call);
2211 		} else {
2212 			YYERROR;
2213 		}
2214 	}
2215 #line 2216 "parser.c" /* yacc.c:1646  */
2216     break;
2217 
2218   case 41:
2219 #line 757 "parser.y" /* yacc.c:1646  */
2220     {
2221 		char const *wb_name = value_peek_string ((yyvsp[-1].expr)->constant.value);
2222 		Workbook *ref_wb = state->pos
2223 			? (state->pos->wb
2224 			   ? state->pos->wb
2225 			   : (state->pos->sheet
2226 			      ? state->pos->sheet->workbook
2227 			      : NULL))
2228 			: NULL;
2229 		Workbook *wb =
2230 			state->convs->input.external_wb (state->convs,
2231 							 ref_wb,
2232 							 wb_name);
2233 
2234 		if (wb != NULL) {
2235 			unregister_allocation ((yyvsp[-1].expr)); gnm_expr_free ((yyvsp[-1].expr));
2236 			(yyval.wb) = wb;
2237 		} else {
2238 			/* kludge to produce better error messages
2239 			 * we know that the last token read will be the ']'
2240 			 * so subtract 1.
2241 			 */
2242 			report_err (state, g_error_new (1, PERR_UNKNOWN_WORKBOOK,
2243 				_("Unknown workbook '%s'"), wb_name),
2244 				state->ptr - 1, strlen (wb_name));
2245 			YYERROR;
2246 		}
2247 	}
2248 #line 2249 "parser.c" /* yacc.c:1646  */
2249     break;
2250 
2251   case 42:
2252 #line 785 "parser.y" /* yacc.c:1646  */
2253     {
2254 		/* Special syntax for global names shadowed by sheet names.  */
2255 		Workbook *wb = state->pos
2256 			? (state->pos->wb
2257 			   ? state->pos->wb
2258 			   : (state->pos->sheet
2259 			      ? state->pos->sheet->workbook
2260 			      : NULL))
2261 			: NULL;
2262 		(yyval.wb) = wb;
2263 		if (wb == NULL) {
2264 			report_err (state, g_error_new (1, PERR_UNKNOWN_WORKBOOK,
2265 				_("Unknown workbook")),
2266 				state->ptr - 1, 1);
2267 			YYERROR;
2268 		}
2269 	}
2270 #line 2271 "parser.c" /* yacc.c:1646  */
2271     break;
2272 
2273   case 43:
2274 #line 807 "parser.y" /* yacc.c:1646  */
2275     {
2276 		Sheet *sheet = parser_sheet_by_name (state->pos->wb, (yyvsp[-1].expr));
2277 		if (sheet != NULL) {
2278 			unregister_allocation ((yyvsp[-1].expr)); gnm_expr_free ((yyvsp[-1].expr));
2279 			(yyval.sheet) = sheet;
2280 		} else {
2281 			YYERROR;
2282 		}
2283 	}
2284 #line 2285 "parser.c" /* yacc.c:1646  */
2285     break;
2286 
2287   case 44:
2288 #line 816 "parser.y" /* yacc.c:1646  */
2289     {
2290 		Workbook *wb = (yyvsp[-2].wb);
2291 		Sheet *sheet = parser_sheet_by_name (wb, (yyvsp[-1].expr));
2292 		if (sheet != NULL) {
2293 			unregister_allocation ((yyvsp[-1].expr)); gnm_expr_free ((yyvsp[-1].expr));
2294 			(yyval.sheet) = sheet;
2295 		} else {
2296 			YYERROR;
2297 		}
2298         }
2299 #line 2300 "parser.c" /* yacc.c:1646  */
2300     break;
2301 
2302   case 45:
2303 #line 828 "parser.y" /* yacc.c:1646  */
2304     { (yyval.expr) = (yyvsp[0].expr); }
2305 #line 2306 "parser.c" /* yacc.c:1646  */
2306     break;
2307 
2308   case 46:
2309 #line 829 "parser.y" /* yacc.c:1646  */
2310     {
2311 		(yyval.expr) = build_range_ctor ((yyvsp[-2].expr), (yyvsp[0].expr), NULL);
2312 		if ((yyval.expr) == NULL) { YYERROR; }
2313 	}
2314 #line 2315 "parser.c" /* yacc.c:1646  */
2315     break;
2316 
2317   case 47:
2318 #line 833 "parser.y" /* yacc.c:1646  */
2319     {
2320 		(yyval.expr) = build_range_ctor ((yyvsp[-2].expr), (yyvsp[0].expr), (yyvsp[-2].expr));
2321 		if ((yyval.expr) == NULL) { YYERROR; }
2322 	}
2323 #line 2324 "parser.c" /* yacc.c:1646  */
2324     break;
2325 
2326   case 48:
2327 #line 837 "parser.y" /* yacc.c:1646  */
2328     {
2329 		(yyval.expr) = build_range_ctor ((yyvsp[-2].expr), (yyvsp[0].expr), (yyvsp[0].expr));
2330 		if ((yyval.expr) == NULL) { YYERROR; }
2331 	}
2332 #line 2333 "parser.c" /* yacc.c:1646  */
2333     break;
2334 
2335   case 49:
2336 #line 841 "parser.y" /* yacc.c:1646  */
2337     {
2338 		(yyval.expr) = build_range_ctor ((yyvsp[-2].expr), (yyvsp[0].expr), NULL);
2339 		if ((yyval.expr) == NULL) { YYERROR; }
2340 	}
2341 #line 2342 "parser.c" /* yacc.c:1646  */
2342     break;
2343 
2344   case 50:
2345 #line 847 "parser.y" /* yacc.c:1646  */
2346     {
2347 		unregister_allocation ((yyvsp[0].expr));
2348 		(yyval.list) = gnm_expr_list_prepend (NULL, (yyvsp[0].expr));
2349 		register_expr_list_allocation ((yyval.list));
2350         }
2351 #line 2352 "parser.c" /* yacc.c:1646  */
2352     break;
2353 
2354   case 51:
2355 #line 852 "parser.y" /* yacc.c:1646  */
2356     {
2357 		GSList *tmp = (yyvsp[0].list);
2358 		unregister_allocation ((yyvsp[0].list));
2359 		unregister_allocation ((yyvsp[-2].expr));
2360 
2361 		if (tmp == NULL)
2362 			tmp = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_empty ()));
2363 
2364 		(yyval.list) = gnm_expr_list_prepend (tmp, (yyvsp[-2].expr));
2365 		register_expr_list_allocation ((yyval.list));
2366 	}
2367 #line 2368 "parser.c" /* yacc.c:1646  */
2368     break;
2369 
2370   case 52:
2371 #line 863 "parser.y" /* yacc.c:1646  */
2372     {
2373 		GSList *tmp = (yyvsp[0].list);
2374 		unregister_allocation ((yyvsp[0].list));
2375 
2376 		if (tmp == NULL)
2377 			tmp = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_empty ()));
2378 
2379 		(yyval.list) = gnm_expr_list_prepend (tmp, gnm_expr_new_constant (value_new_empty ()));
2380 		register_expr_list_allocation ((yyval.list));
2381 	}
2382 #line 2383 "parser.c" /* yacc.c:1646  */
2383     break;
2384 
2385   case 53:
2386 #line 873 "parser.y" /* yacc.c:1646  */
2387     { (yyval.list) = NULL; }
2388 #line 2389 "parser.c" /* yacc.c:1646  */
2389     break;
2390 
2391   case 54:
2392 #line 876 "parser.y" /* yacc.c:1646  */
2393     { (yyval.expr) = (yyvsp[0].expr); }
2394 #line 2395 "parser.c" /* yacc.c:1646  */
2395     break;
2396 
2397   case 55:
2398 #line 877 "parser.y" /* yacc.c:1646  */
2399     {
2400 		GnmExpr *tmp = fold_negative_constant ((yyvsp[0].expr));
2401 		if (!tmp) { YYERROR; }
2402 		(yyval.expr) = tmp;
2403 	 }
2404 #line 2405 "parser.c" /* yacc.c:1646  */
2405     break;
2406 
2407   case 56:
2408 #line 882 "parser.y" /* yacc.c:1646  */
2409     {
2410 		GnmExpr *tmp = fold_positive_constant ((yyvsp[0].expr));
2411 		if (!tmp) { YYERROR; }
2412 		(yyval.expr) = tmp;
2413 	 }
2414 #line 2415 "parser.c" /* yacc.c:1646  */
2415     break;
2416 
2417   case 57:
2418 #line 887 "parser.y" /* yacc.c:1646  */
2419     { (yyval.expr) = parse_string_as_value ((yyvsp[0].expr)); }
2420 #line 2421 "parser.c" /* yacc.c:1646  */
2421     break;
2422 
2423   case 58:
2424 #line 891 "parser.y" /* yacc.c:1646  */
2425     { (yyval.list) = NULL; }
2426 #line 2427 "parser.c" /* yacc.c:1646  */
2427     break;
2428 
2429   case 59:
2430 #line 892 "parser.y" /* yacc.c:1646  */
2431     {
2432 		unregister_allocation ((yyvsp[0].expr));
2433 		(yyval.list) = g_slist_prepend (NULL, (yyvsp[0].expr));
2434 		register_expr_list_allocation ((yyval.list));
2435         }
2436 #line 2437 "parser.c" /* yacc.c:1646  */
2437     break;
2438 
2439   case 60:
2440 #line 897 "parser.y" /* yacc.c:1646  */
2441     {
2442 		unregister_allocation ((yyvsp[0].list));
2443 		unregister_allocation ((yyvsp[-2].expr));
2444 		(yyval.list) = g_slist_prepend ((yyvsp[0].list), (yyvsp[-2].expr));
2445 		register_expr_list_allocation ((yyval.list));
2446 	}
2447 #line 2448 "parser.c" /* yacc.c:1646  */
2448     break;
2449 
2450   case 61:
2451 #line 905 "parser.y" /* yacc.c:1646  */
2452     {
2453 		unregister_allocation ((yyvsp[0].list));
2454 		(yyval.list) = g_slist_prepend (NULL, (yyvsp[0].list));
2455 		register_expr_list_list_allocation ((yyval.list));
2456         }
2457 #line 2458 "parser.c" /* yacc.c:1646  */
2458     break;
2459 
2460   case 62:
2461 #line 910 "parser.y" /* yacc.c:1646  */
2462     {
2463 		unregister_allocation ((yyvsp[0].list));
2464 		unregister_allocation ((yyvsp[-2].list));
2465 		(yyval.list) = g_slist_prepend ((yyvsp[0].list), (yyvsp[-2].list));
2466 		register_expr_list_list_allocation ((yyval.list));
2467 	}
2468 #line 2469 "parser.c" /* yacc.c:1646  */
2469     break;
2470 
2471 
2472 #line 2473 "parser.c" /* yacc.c:1646  */
2473       default: break;
2474     }
2475   /* User semantic actions sometimes alter yychar, and that requires
2476      that yytoken be updated with the new translation.  We take the
2477      approach of translating immediately before every use of yytoken.
2478      One alternative is translating here after every semantic action,
2479      but that translation would be missed if the semantic action invokes
2480      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2481      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
2482      incorrect destructor might then be invoked immediately.  In the
2483      case of YYERROR or YYBACKUP, subsequent parser actions might lead
2484      to an incorrect destructor call or verbose syntax error message
2485      before the lookahead is translated.  */
2486   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2487 
2488   YYPOPSTACK (yylen);
2489   yylen = 0;
2490   YY_STACK_PRINT (yyss, yyssp);
2491 
2492   *++yyvsp = yyval;
2493 
2494   /* Now 'shift' the result of the reduction.  Determine what state
2495      that goes to, based on the state we popped back to and the rule
2496      number reduced by.  */
2497 
2498   yyn = yyr1[yyn];
2499 
2500   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2501   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2502     yystate = yytable[yystate];
2503   else
2504     yystate = yydefgoto[yyn - YYNTOKENS];
2505 
2506   goto yynewstate;
2507 
2508 
2509 /*--------------------------------------.
2510 | yyerrlab -- here on detecting error.  |
2511 `--------------------------------------*/
2512 yyerrlab:
2513   /* Make sure we have latest lookahead translation.  See comments at
2514      user semantic actions for why this is necessary.  */
2515   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2516 
2517   /* If not already recovering from an error, report this error.  */
2518   if (!yyerrstatus)
2519     {
2520       ++yynerrs;
2521 #if ! YYERROR_VERBOSE
2522       yyerror (YY_("syntax error"));
2523 #else
2524 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2525                                         yyssp, yytoken)
2526       {
2527         char const *yymsgp = YY_("syntax error");
2528         int yysyntax_error_status;
2529         yysyntax_error_status = YYSYNTAX_ERROR;
2530         if (yysyntax_error_status == 0)
2531           yymsgp = yymsg;
2532         else if (yysyntax_error_status == 1)
2533           {
2534             if (yymsg != yymsgbuf)
2535               YYSTACK_FREE (yymsg);
2536             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2537             if (!yymsg)
2538               {
2539                 yymsg = yymsgbuf;
2540                 yymsg_alloc = sizeof yymsgbuf;
2541                 yysyntax_error_status = 2;
2542               }
2543             else
2544               {
2545                 yysyntax_error_status = YYSYNTAX_ERROR;
2546                 yymsgp = yymsg;
2547               }
2548           }
2549         yyerror (yymsgp);
2550         if (yysyntax_error_status == 2)
2551           goto yyexhaustedlab;
2552       }
2553 # undef YYSYNTAX_ERROR
2554 #endif
2555     }
2556 
2557 
2558 
2559   if (yyerrstatus == 3)
2560     {
2561       /* If just tried and failed to reuse lookahead token after an
2562          error, discard it.  */
2563 
2564       if (yychar <= YYEOF)
2565         {
2566           /* Return failure if at end of input.  */
2567           if (yychar == YYEOF)
2568             YYABORT;
2569         }
2570       else
2571         {
2572           yydestruct ("Error: discarding",
2573                       yytoken, &yylval);
2574           yychar = YYEMPTY;
2575         }
2576     }
2577 
2578   /* Else will try to reuse lookahead token after shifting the error
2579      token.  */
2580   goto yyerrlab1;
2581 
2582 
2583 /*---------------------------------------------------.
2584 | yyerrorlab -- error raised explicitly by YYERROR.  |
2585 `---------------------------------------------------*/
2586 yyerrorlab:
2587 
2588   /* Pacify compilers like GCC when the user code never invokes
2589      YYERROR and the label yyerrorlab therefore never appears in user
2590      code.  */
2591   if (/*CONSTCOND*/ 0)
2592      goto yyerrorlab;
2593 
2594   /* Do not reclaim the symbols of the rule whose action triggered
2595      this YYERROR.  */
2596   YYPOPSTACK (yylen);
2597   yylen = 0;
2598   YY_STACK_PRINT (yyss, yyssp);
2599   yystate = *yyssp;
2600   goto yyerrlab1;
2601 
2602 
2603 /*-------------------------------------------------------------.
2604 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2605 `-------------------------------------------------------------*/
2606 yyerrlab1:
2607   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2608 
2609   for (;;)
2610     {
2611       yyn = yypact[yystate];
2612       if (!yypact_value_is_default (yyn))
2613         {
2614           yyn += YYTERROR;
2615           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2616             {
2617               yyn = yytable[yyn];
2618               if (0 < yyn)
2619                 break;
2620             }
2621         }
2622 
2623       /* Pop the current state because it cannot handle the error token.  */
2624       if (yyssp == yyss)
2625         YYABORT;
2626 
2627 
2628       yydestruct ("Error: popping",
2629                   yystos[yystate], yyvsp);
2630       YYPOPSTACK (1);
2631       yystate = *yyssp;
2632       YY_STACK_PRINT (yyss, yyssp);
2633     }
2634 
2635   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2636   *++yyvsp = yylval;
2637   YY_IGNORE_MAYBE_UNINITIALIZED_END
2638 
2639 
2640   /* Shift the error token.  */
2641   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2642 
2643   yystate = yyn;
2644   goto yynewstate;
2645 
2646 
2647 /*-------------------------------------.
2648 | yyacceptlab -- YYACCEPT comes here.  |
2649 `-------------------------------------*/
2650 yyacceptlab:
2651   yyresult = 0;
2652   goto yyreturn;
2653 
2654 /*-----------------------------------.
2655 | yyabortlab -- YYABORT comes here.  |
2656 `-----------------------------------*/
2657 yyabortlab:
2658   yyresult = 1;
2659   goto yyreturn;
2660 
2661 #if !defined yyoverflow || YYERROR_VERBOSE
2662 /*-------------------------------------------------.
2663 | yyexhaustedlab -- memory exhaustion comes here.  |
2664 `-------------------------------------------------*/
2665 yyexhaustedlab:
2666   yyerror (YY_("memory exhausted"));
2667   yyresult = 2;
2668   /* Fall through.  */
2669 #endif
2670 
2671 yyreturn:
2672   if (yychar != YYEMPTY)
2673     {
2674       /* Make sure we have latest lookahead translation.  See comments at
2675          user semantic actions for why this is necessary.  */
2676       yytoken = YYTRANSLATE (yychar);
2677       yydestruct ("Cleanup: discarding lookahead",
2678                   yytoken, &yylval);
2679     }
2680   /* Do not reclaim the symbols of the rule whose action triggered
2681      this YYABORT or YYACCEPT.  */
2682   YYPOPSTACK (yylen);
2683   YY_STACK_PRINT (yyss, yyssp);
2684   while (yyssp != yyss)
2685     {
2686       yydestruct ("Cleanup: popping",
2687                   yystos[*yyssp], yyvsp);
2688       YYPOPSTACK (1);
2689     }
2690 #ifndef yyoverflow
2691   if (yyss != yyssa)
2692     YYSTACK_FREE (yyss);
2693 #endif
2694 #if YYERROR_VERBOSE
2695   if (yymsg != yymsgbuf)
2696     YYSTACK_FREE (yymsg);
2697 #endif
2698   return yyresult;
2699 }
2700 #line 918 "parser.y" /* yacc.c:1906  */
2701 
2702 
2703 static char const *
find_matching_close(char const * str,char const ** res)2704 find_matching_close (char const *str, char const **res)
2705 {
2706 	while (*str) {
2707 		if (*str == '(') {
2708 			char const *tmp = str;
2709 			str = find_matching_close (str + 1, res);
2710 			if (*str != ')' && *res == NULL) {
2711 				*res = tmp;
2712 				return str;
2713 			}
2714 			if (*str == 0)
2715 				return str;
2716 		} else if (*str == ')')
2717 			return str;
2718 		else if (*str == '\'' || *str == '\"') {
2719 			GString *dummy = g_string_new (NULL);
2720 			char const *end = go_strunescape (dummy, str);
2721 			g_string_free (dummy, TRUE);
2722 			if (end == NULL)
2723 				return str + strlen (str);
2724 			str = end;
2725 			continue; /* skip incrementing str */
2726 		}
2727 		str = g_utf8_next_char (str);
2728 	}
2729 
2730 	return str;
2731 }
2732 
2733 static inline int
eat_space(ParserState * state,int res)2734 eat_space (ParserState *state, int res)
2735 {
2736 	/* help the user by ignoring pointless spaces after an
2737 	 * arg_sep.  We know they are going to be errors and
2738 	 * the spaces cannot be operators in this context */
2739 	while (*state->ptr == ' ')
2740 		state->ptr++;
2741 	return res;
2742 }
2743 
2744 /*
2745  * Do we want to ignore space before a given character?
2746  */
2747 static gboolean
ignore_space_before(gunichar c)2748 ignore_space_before (gunichar c)
2749 {
2750 	switch (c) {
2751 	case '*': case '/': case '+': case '-': case '%': case '^': case '&':
2752 	case '>': case '<': case '=':
2753 	case ')':
2754 	case '#':
2755 	case '"': case '\'':  /* Refers to opening quote only.  */
2756 	case UNICODE_LOGICAL_NOT_C:
2757 	case UNICODE_LOGICAL_AND_C:
2758 	case UNICODE_LOGICAL_OR_C:
2759 	case UNICODE_MINUS_SIGN_C:
2760 	case UNICODE_DIVISION_SLASH_C:
2761 	case UNICODE_NOT_EQUAL_TO_C:
2762 	case UNICODE_LESS_THAN_OR_EQUAL_TO_C:
2763 	case UNICODE_GREATER_THAN_OR_EQUAL_TO_C:
2764 	case 0:
2765 		return TRUE;
2766 	default:
2767 		return FALSE;
2768 	}
2769 }
2770 
2771 /*
2772  * Do we want to ignore space after a given character?
2773  */
2774 static gboolean
ignore_space_after(gunichar c)2775 ignore_space_after (gunichar c)
2776 {
2777 	switch (c) {
2778 	case '*': case '/': case '+': case '-': case '%': case '^': case '&':
2779 	case '>': case '<': case '=':
2780 	case '(':
2781 	case '"': case '\'':  /* Refers to closing quote only [not actually hit].  */
2782 	case UNICODE_LOGICAL_NOT_C:
2783 	case UNICODE_LOGICAL_AND_C:
2784 	case UNICODE_LOGICAL_OR_C:
2785 	case UNICODE_MINUS_SIGN_C:
2786 	case UNICODE_DIVISION_SLASH_C:
2787 	case UNICODE_NOT_EQUAL_TO_C:
2788 	case UNICODE_LESS_THAN_OR_EQUAL_TO_C:
2789 	case UNICODE_GREATER_THAN_OR_EQUAL_TO_C:
2790 	case 0:
2791 		return TRUE;
2792 	default:
2793 		return FALSE;
2794 	}
2795 }
2796 
2797 static gboolean
open_paren(const char * p)2798 open_paren (const char *p)
2799 {
2800 	while (g_unichar_isspace (g_utf8_get_char (p)))
2801 		p = g_utf8_next_char (p);
2802 	return *p == '(';
2803 }
2804 
2805 static int
yylex(void)2806 yylex (void)
2807 {
2808 	gunichar c, tmp;
2809 	char const *start, *end;
2810 	GnmRangeRef ref;
2811 	gboolean is_number = FALSE;
2812 	gboolean is_space = FALSE;
2813 	gboolean error_token = FALSE;
2814 
2815 	/*
2816 	 * Some special logic to handle space as intersection char.
2817 	 * Any number of white space characters are treated as one
2818 	 * intersecton.
2819 	 *
2820 	 * Also, if we are not using space for that, drop spaces.
2821 	 */
2822         while (g_unichar_isspace (g_utf8_get_char (state->ptr))) {
2823                 state->ptr = g_utf8_next_char (state->ptr);
2824 		is_space = TRUE;
2825 	}
2826 	if (is_space && state->convs->intersection_char == ' ' &&
2827 	    !ignore_space_before (g_utf8_get_char (state->ptr)))
2828 		return RANGE_INTERSECT;
2829 
2830 	start = state->ptr;
2831 	c = g_utf8_get_char (start);
2832 	if (c == 0)
2833 		return 0;
2834 	state->ptr = g_utf8_next_char (state->ptr);
2835 
2836 	if (c == state->convs->intersection_char)
2837 		return RANGE_INTERSECT;
2838 
2839 	if (c == '&' && state->convs->decode_ampersands) {
2840 		if (!strncmp (state->ptr, "amp;", 4)) {
2841 			state->ptr += 4;
2842 			return '&';
2843 		}
2844 
2845 		if (!strncmp (state->ptr, "lt;", 3)) {
2846 			state->ptr += 3;
2847 			if (*state->ptr == '='){
2848 				state->ptr++;
2849 				return tok_LTE;
2850 			}
2851 			if (!strncmp (state->ptr, "&gt;", 4)) {
2852 				state->ptr += 4;
2853 				return tok_NE;
2854 			}
2855 			return '<';
2856 		}
2857 		if (!strncmp (state->ptr, "gt;", 3)) {
2858 			state->ptr += 3;
2859 			if (*state->ptr == '='){
2860 				state->ptr++;
2861 				return tok_GTE;
2862 			}
2863 			return '>';
2864 		}
2865 		if (!strncmp (state->ptr, "apos;", 5) ||
2866 		    !strncmp (state->ptr, "quot;", 5)) {
2867 			char const *quotes_end;
2868 			char const *p;
2869 			char *string, *s;
2870 			GnmValue *v;
2871 
2872 			if (*state->ptr == 'q') {
2873 				quotes_end = "&quot;";
2874 				c = '\"';
2875 			} else {
2876 				quotes_end = "&apos;";
2877 				c = '\'';
2878 			}
2879 
2880 			state->ptr += 5;
2881 			p = state->ptr;
2882 			double_quote_loop:
2883 				state->ptr = strstr (state->ptr, quotes_end);
2884 			if (!*state->ptr) {
2885 				report_err (state, g_error_new (1, PERR_MISSING_CLOSING_QUOTE,
2886 								_("Could not find matching closing quote")),
2887 					    p, 1);
2888 				return INVALID_TOKEN;
2889 			}
2890 			if (!strncmp (state->ptr + 6, quotes_end, 6)) {
2891 				state->ptr += 2 * 6;
2892 				goto double_quote_loop;
2893 			}
2894 
2895 			s = string = g_malloc (1 + state->ptr - p);
2896 			while (p != state->ptr) {
2897 				if (*p == '&') {
2898 					if (!strncmp (p, "&amp;", 5)) {
2899 						p += 5;
2900 						*s++ = '&';
2901 						continue;
2902 					} else if (!strncmp (p, "&lt;", 4)) {
2903 						p += 4;
2904 						*s++ = '<';
2905 						continue;
2906 					} else if (!strncmp (p, "&gt;", 4)) {
2907 						p += 4;
2908 						*s++ = '>';
2909 						continue;
2910 					} else if (!strncmp (p, quotes_end, 6)) {
2911 						p += 12; /* two in a row is the escape mechanism */
2912 						*s++ = c;
2913 						continue;
2914 					} else if (!strncmp (p, "&quot;", 6)) {
2915 						p += 6;
2916 						*s++ = '\"';
2917 						continue;
2918 					} else if (!strncmp (p, "&apos;", 6)) {
2919 						p += 6;
2920 						*s++ = '\'';
2921 						continue;
2922 					}
2923 				}
2924 				*s++ = *p++;
2925 			}
2926 
2927 			*s = 0;
2928 			state->ptr += 6;
2929 
2930 			v = value_new_string_nocopy (string);
2931 			yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
2932 			return QUOTED_STRING;
2933 		}
2934 	}
2935 
2936 	if (c == ':' && state->convs->range_sep_colon)
2937 		return eat_space (state, RANGE_SEP);
2938 
2939 	if (c == state->convs->sheet_name_sep)
2940 		return eat_space (state, SHEET_SEP);
2941 
2942 	if (c == '.' && *state->ptr == '.' && state->convs->range_sep_dotdot) {
2943 		state->ptr++;
2944 		return RANGE_SEP;
2945 	}
2946 
2947 	if (c == '#' && state->convs->accept_hash_logicals) {
2948 		if (!strncmp (state->ptr, "NOT#", 4)) {
2949 			state->ptr += 4;
2950 			return eat_space (state, tok_NOT);
2951 		}
2952 		if (!strncmp (state->ptr, "AND#", 4)) {
2953 			state->ptr += 4;
2954 			return eat_space (state, tok_AND);
2955 		}
2956 		if (!strncmp (state->ptr, "OR#", 3)) {
2957 			state->ptr += 3;
2958 			return eat_space (state, tok_OR);
2959 		}
2960 	}
2961 
2962 	if (c == state->arg_sep)
2963 		return eat_space (state, state->in_array ? state->in_array_sep_is : ARG_SEP);
2964 	if ((c == state->union_char) && (state->union_char != 0))
2965 		return eat_space (state, ARG_SEP);
2966 	if (c == state->array_col_sep)
2967 		return eat_space (state, ARRAY_COL_SEP);
2968 	if (c == state->array_row_sep)
2969 		return eat_space (state, ARRAY_ROW_SEP);
2970 
2971 	end = state->convs->input.range_ref (&ref, start,
2972 					     state->pos, state->convs);
2973 	/*
2974 	 * In order to parse "LOG10(1024)" in sheets with more than ~8500
2975 	 * columns we do not consider anything a rangeref if it is followed
2976 	 * by an opening parenthesis.
2977 	 */
2978 	if (start != end && !open_paren (end)) {
2979 		state->ptr = end;
2980 		if (invalid_sheet == ref.a.sheet) {
2981 		        yylval.expr = register_expr_allocation
2982 		                (gnm_expr_new_constant
2983 				 (value_new_error_REF (NULL)));
2984 			return CONSTANT;
2985 		}
2986 		if (state->flags & GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES) {
2987 			if (ref.a.col_relative) {
2988 				ref.a.col += state->pos->eval.col;
2989 				ref.a.col_relative = FALSE;
2990 			}
2991 			if (ref.b.col_relative) {
2992 				ref.b.col += state->pos->eval.col;
2993 				ref.b.col_relative = FALSE;
2994 			}
2995 			if (ref.a.row_relative) {
2996 				ref.a.row += state->pos->eval.row;
2997 				ref.a.row_relative = FALSE;
2998 			}
2999 			if (ref.b.row_relative) {
3000 				ref.b.row += state->pos->eval.row;
3001 				ref.b.row_relative = FALSE;
3002 			}
3003 		} else if (state->flags & GNM_EXPR_PARSE_FORCE_RELATIVE_REFERENCES) {
3004 			if (!ref.a.col_relative) {
3005 				ref.a.col -= state->pos->eval.col;
3006 				ref.a.col_relative = TRUE;
3007 			}
3008 			if (!ref.b.col_relative) {
3009 				ref.b.col -= state->pos->eval.col;
3010 				ref.b.col_relative = TRUE;
3011 			}
3012 			if (!ref.a.row_relative) {
3013 				ref.a.row -= state->pos->eval.row;
3014 				ref.a.row_relative = TRUE;
3015 			}
3016 			if (!ref.b.row_relative) {
3017 				ref.b.row -= state->pos->eval.row;
3018 				ref.b.row_relative = TRUE;
3019 			}
3020 		}
3021 
3022 		if (ref.a.sheet == NULL && (state->flags & GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES)) {
3023 			ref.a.sheet = state->pos->sheet;
3024 			if (ref.a.sheet == NULL) {
3025 				report_err (state, g_error_new (1, PERR_SHEET_IS_REQUIRED,
3026 					_("Sheet name is required")),
3027 					state->ptr, 0);
3028 				return INVALID_TOKEN;
3029 			}
3030 		}
3031 
3032 		if ((ref.b.sheet == NULL || ref.b.sheet == ref.a.sheet) &&
3033 		    ref.a.col		== ref.b.col &&
3034 		    ref.a.col_relative	== ref.b.col_relative &&
3035 		    ref.a.row		== ref.b.row &&
3036 		    ref.a.row_relative	== ref.b.row_relative) {
3037 			yylval.expr = register_expr_allocation (gnm_expr_new_cellref (&ref.a));
3038 			return RANGEREF;
3039 		}
3040 		yylval.expr = register_expr_allocation (gnm_expr_new_constant (
3041 			 value_new_cellrange_unsafe (&ref.a, &ref.b)));
3042 		return RANGEREF;
3043 	}
3044 
3045 	/* Do NOT handle negative numbers here.  That has to be done in the
3046 	 * parser otherwise we mishandle A1-1 when it looks like
3047 	 * rangeref CONSTANT  */
3048 	if (c == state->decimal_point) {
3049 		/* Could be a number or a stand alone  */
3050 		if (!g_unichar_isdigit (g_utf8_get_char (state->ptr)))
3051 			return c;
3052 		is_number = TRUE;
3053 	}  else if (g_unichar_isdigit (c)) {
3054 		/* find the end of the first portion of the number */
3055 		do {
3056 			c = g_utf8_get_char (state->ptr);
3057 			state->ptr = g_utf8_next_char (state->ptr);
3058 		} while (g_unichar_isdigit (c));
3059 		is_number = TRUE;
3060 		if (c == 0)
3061 			state->ptr--;
3062 	}
3063 
3064 	if (is_number) {
3065 		GnmValue *v = NULL;
3066 
3067 		if (c == state->decimal_point || c == 'e' || c == 'E') {
3068 			/* This is a floating point number */
3069 			char *end;
3070 			gnm_float d;
3071 
3072 			errno = 0;
3073 			d = gnm_utf8_strto (start, &end);
3074 			if (start == end) {
3075 				g_warning ("%s is not a double, but was expected to be one", start);
3076 			}  else if (errno != ERANGE) {
3077 				v = value_new_float (d);
3078 				state->ptr = end;
3079 			} else if (c != 'e' && c != 'E') {
3080 				report_err (state, g_error_new (1, PERR_OUT_OF_RANGE,
3081 					_("The number is out of range")),
3082 					state->ptr, end - start);
3083 				return INVALID_TOKEN;
3084 			} else {
3085 				/* For an exponent it's hard to highlight the
3086 				 * right region w/o it turning into an ugly
3087 				 * hack, for now the cursor is put at the end.
3088 				 */
3089 				report_err (state, g_error_new (1, PERR_OUT_OF_RANGE,
3090 					_("The number is out of range")),
3091 					state->ptr, 0);
3092 				return INVALID_TOKEN;
3093 			}
3094 		} else {
3095 			char *end;
3096 			long l;
3097 
3098 			l = gnm_utf8_strtol (start, &end);
3099 			if (start == end) {
3100 				g_warning ("%s is not an integer, but was expected to be one", start);
3101 			} else if (errno != ERANGE && l >= INT_MIN && l <= INT_MAX) {
3102 				v = value_new_int (l);
3103 				state->ptr = end;
3104 			} else {
3105 				gnm_float d;
3106 
3107 				errno = 0;
3108 				d = gnm_utf8_strto (start, &end);
3109 				if (errno != ERANGE) {
3110 					v = value_new_float (d);
3111 					state->ptr = end;
3112 				} else {
3113 					report_err (state, g_error_new (1, PERR_OUT_OF_RANGE,
3114 						_("The number is out of range")),
3115 						state->ptr, end - start);
3116 					return INVALID_TOKEN;
3117 				}
3118 			}
3119 		}
3120 
3121 		/* Very odd string,  Could be a bound problem.  Trigger an error */
3122 		if (v == NULL)
3123 			return c;
3124 
3125 		yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
3126 		return CONSTANT;
3127 	}
3128 
3129 	switch (c) {
3130 	case '#':
3131 		if (state->ptr[0] != '"') {
3132 			while ((tmp = g_utf8_get_char (state->ptr)) != 0 &&
3133 			       !g_unichar_isspace (tmp)) {
3134 				state->ptr = g_utf8_next_char (state->ptr);
3135 				if (tmp == '!' || tmp == '?' ||
3136 				((state->ptr - start) == 4 && 0 == strncmp (start, "#N/A", 4))) {
3137 					GOString *name = go_string_new_nocopy (g_strndup (start, state->ptr - start));
3138 					yylval.expr = register_expr_allocation
3139 						(gnm_expr_new_constant (
3140 							value_new_error_str (NULL, name)));
3141 					go_string_unref (name);
3142 					return CONSTANT;
3143 				}
3144 			}
3145 
3146 			report_err (state, g_error_new
3147 				    (1, PERR_UNEXPECTED_TOKEN,
3148 				     _("Improperly formatted error token")),
3149 				    state->ptr, state->ptr - start);
3150 
3151 			return INVALID_TOKEN;
3152 		}
3153 		error_token = TRUE;
3154 		start++;
3155 		/* Fall through */
3156 	case '\'':
3157 	case '"': {
3158 		GString *s = g_string_new (NULL);
3159 		char const *end = state->convs->input.string (start, s, state->convs);
3160 
3161 		if (end == NULL) {
3162 			size_t len = strlen (start);
3163 			g_string_free (s, TRUE);
3164   			report_err (state,
3165 				    g_error_new (1, PERR_MISSING_CLOSING_QUOTE,
3166 						 _("Could not find matching closing quote")),
3167 				    start + len, len);
3168 			return INVALID_TOKEN;
3169 		}
3170 
3171 		state->ptr = (char *)end;
3172 
3173 		if (error_token) {
3174 			GnmValue *v = value_new_error (NULL, s->str);
3175 			yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
3176 			g_string_free (s, TRUE);
3177 			return eat_space (state, CONSTANT);
3178 		} else {
3179 			GnmValue *v = value_new_string_nocopy (g_string_free (s, FALSE));
3180 			yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
3181 			return eat_space (state, QUOTED_STRING);
3182 		}
3183 	}
3184 
3185 	case '[': {
3186 		const char *p = state->ptr;
3187 		GString *s = g_string_new (NULL);
3188 		Workbook *ref_wb = state->pos
3189 			? (state->pos->wb
3190 			   ? state->pos->wb
3191 			   : (state->pos->sheet
3192 			      ? state->pos->sheet->workbook
3193 			      : NULL))
3194 			: NULL;
3195 
3196 		while (g_unichar_isspace (g_utf8_get_char (p)))
3197 			p = g_utf8_next_char (p);
3198 
3199 		if (p[0] == '"' || p[0] == '\'') {
3200 			p = go_strunescape (s, p);
3201 		} else {
3202 			gunichar uc;
3203 			while (1) {
3204 				uc = g_utf8_get_char (p);
3205 				if (!uc || uc == ']' || g_unichar_isspace (uc))
3206 					break;
3207 				p = g_utf8_next_char (p);
3208 				g_string_append_unichar (s, uc);
3209 			}
3210 		}
3211 
3212 		while (p && g_unichar_isspace (g_utf8_get_char (p)))
3213 			p = g_utf8_next_char (p);
3214 
3215 		if (s->len == 0 || !p || p[0] != ']') {
3216 			g_string_free (s, TRUE);
3217 			break;
3218 		}
3219 
3220 		yylval.wb = state->convs->input.external_wb (state->convs,
3221 							     ref_wb,
3222 							     s->str);
3223 		g_string_free (s, TRUE);
3224 		if (!yylval.wb)
3225 			break;
3226 
3227 		state->ptr = p + 1;
3228 		return tok_WORKBOOKREF;
3229 	}
3230 	}
3231 
3232 	if ((end = state->convs->input.name (start, state->convs))) {
3233 		state->ptr = end;
3234 		yylval.expr = register_expr_allocation (gnm_expr_new_constant (
3235 			value_new_string_nocopy (g_strndup (start, state->ptr - start))));
3236 		return STRING;
3237 	}
3238 
3239 	switch (c) {
3240 	case '<':
3241 		if (*state->ptr == '='){
3242 			state->ptr++;
3243 			return eat_space (state, tok_LTE);
3244 		}
3245 		if (*state->ptr == '>'){
3246 			state->ptr++;
3247 			return eat_space (state, tok_NE);
3248 		}
3249 		return eat_space (state, c);
3250 
3251 	case '>':
3252 		if (*state->ptr == '='){
3253 			state->ptr++;
3254 			return eat_space (state, tok_GTE);
3255 		}
3256 		return eat_space (state, c);
3257 
3258 	case '\n': return 0;
3259 
3260 	case '{':
3261 		state->in_array++;
3262 		return c;
3263 	case '}':
3264 		state->in_array--;
3265 		return c;
3266 
3267 	case '^':
3268 		return state->convs->exp_is_left_associative
3269 			? tok_LEFT_EXP
3270 			: tok_RIGHT_EXP;
3271 
3272 	case UNICODE_LOGICAL_NOT_C: return tok_NOT;
3273 	case UNICODE_MINUS_SIGN_C: return '-';
3274 	case UNICODE_DIVISION_SLASH_C: return '/';
3275 	case UNICODE_LOGICAL_AND_C: return tok_AND;
3276 	case UNICODE_LOGICAL_OR_C: return tok_OR;
3277 	case UNICODE_NOT_EQUAL_TO_C: return eat_space (state, tok_NE);
3278 	case UNICODE_LESS_THAN_OR_EQUAL_TO_C: return eat_space (state, tok_LTE);
3279 	case UNICODE_GREATER_THAN_OR_EQUAL_TO_C: return eat_space (state, tok_GTE);
3280 	}
3281 
3282 	if (ignore_space_after (c))
3283 		return eat_space (state, c);
3284 	else
3285 		return c;
3286 }
3287 
3288 int
yyerror(char const * s)3289 yyerror (char const *s)
3290 {
3291 #if 0
3292 	g_printerr ("Error: %s\n", s);
3293 #endif
3294 	return 0;
3295 }
3296 
3297 static void
setup_state(ParserState * pstate,const char * str,GnmParsePos const * pp,GnmExprParseFlags flags,GnmConventions const * convs,GnmParseError * error)3298 setup_state (ParserState *pstate, const char *str,
3299 	     GnmParsePos const *pp,
3300 	     GnmExprParseFlags flags,
3301 	     GnmConventions const *convs,
3302 	     GnmParseError *error)
3303 {
3304 	pstate->start = pstate->ptr = str;
3305 	pstate->pos   = pp;
3306 
3307 	pstate->flags		= flags;
3308 	pstate->convs                                    =
3309 		(NULL != convs) ? convs : ((NULL != pp->sheet) ? pp->sheet->convs : gnm_conventions_default);
3310 
3311 
3312 	pstate->decimal_point = pstate->convs->decimal_sep_dot
3313 		? '.'
3314 		: g_utf8_get_char (go_locale_get_decimal ()->str); /* FIXME: one char handled.  */
3315 
3316 	if (pstate->convs->arg_sep != 0)
3317 		pstate->arg_sep = pstate->convs->arg_sep;
3318 	else
3319 		pstate->arg_sep = go_locale_get_arg_sep ();
3320 	pstate->union_char = pstate->convs->union_char;
3321 	if (pstate->convs->array_col_sep != 0)
3322 		pstate->array_col_sep = pstate->convs->array_col_sep;
3323 	else
3324 		pstate->array_col_sep = go_locale_get_col_sep ();
3325 	if (pstate->convs->array_row_sep != 0)
3326 		pstate->array_row_sep = pstate->convs->array_row_sep;
3327 	else
3328 		pstate->array_row_sep = go_locale_get_row_sep ();
3329 
3330 	/* Some locales/conventions have ARG_SEP == ARRAY_ROW_SEP
3331 	 * 	eg {1\2\3;4\5\6} for XL style with ',' as a decimal
3332 	 * some have ARG_SEP == ARRAY_COL_SEPARATOR
3333 	 * 	eg {1,2,3;4,5,6} for XL style with '.' as a decimal
3334 	 * 	or {1;2;3|4;5;6} for OOo/
3335 	 * keep track of whether we are in an array to allow the lexer to
3336 	 * dis-ambiguate. */
3337 	if (pstate->arg_sep == pstate->array_col_sep)
3338 		pstate->in_array_sep_is = ARRAY_COL_SEP;
3339 	else if (pstate->arg_sep == pstate->array_row_sep)
3340 		pstate->in_array_sep_is = ARRAY_ROW_SEP;
3341 	else
3342 		pstate->in_array_sep_is = ARG_SEP;
3343 	pstate->in_array = 0;
3344 
3345 	pstate->result = NULL;
3346 	pstate->error = error;
3347 
3348 	state = pstate;
3349 }
3350 
3351 /**
3352  * gnm_expr_parse_str:
3353  *
3354  * @str   : The string to parse.
3355  * @pp	  : #GnmParsePos
3356  * @flags : See parse-utils for descriptions
3357  * @convs: (nullable): #GnmConventions
3358  * @error: (out) (nullable) (optional): ptr to store details of error.
3359  *
3360  * Parse a string. if @error is non-null it will be assumed that the
3361  * caller has passed a pointer to a GnmParseError struct AND that it will
3362  * take responsibility for freeing that struct and its contents.
3363  * with parse_error_free.
3364  * If @convs is %NULL, use the conventions from @pp.
3365  **/
3366 GnmExprTop const *
gnm_expr_parse_str(char const * str,GnmParsePos const * pp,GnmExprParseFlags flags,GnmConventions const * convs,GnmParseError * error)3367 gnm_expr_parse_str (char const *str, GnmParsePos const *pp,
3368 		    GnmExprParseFlags flags,
3369 		    GnmConventions const *convs,
3370 		    GnmParseError *error)
3371 {
3372 	GnmExpr const *expr;
3373 	ParserState pstate;
3374 
3375 	g_return_val_if_fail (str != NULL, NULL);
3376 	g_return_val_if_fail (pp != NULL, NULL);
3377 	g_return_val_if_fail (state == NULL, NULL);
3378 
3379 	if (deallocate_stack == NULL)
3380 		deallocate_init ();
3381 
3382 	setup_state (&pstate, str, pp, flags, convs, error);
3383 	yyparse ();
3384 	state = NULL;
3385 
3386 	if (pstate.result != NULL) {
3387 		deallocate_assert_empty ();
3388 
3389 #if 0
3390 		/* If this happens, something is very wrong */
3391 		if (pstate.error != NULL && pstate.error->message != NULL) {
3392 			g_warning ("An error occurred and the GnmExpr is non-null! This should not happen");
3393 			g_warning ("Error message is %s (%d, %d)", pstate.error->message, pstate.error->begin_char,
3394 					pstate.error->end_char);
3395 		}
3396 #endif
3397 
3398 		/* Do we have multiple expressions */
3399 		if (pstate.result->next != NULL) {
3400 			if (flags & GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS)
3401 				expr = gnm_expr_new_set (g_slist_reverse (pstate.result));
3402 			else {
3403 				gnm_expr_list_unref (pstate.result);
3404 				report_err (&pstate, g_error_new (1, PERR_MULTIPLE_EXPRESSIONS,
3405 					_("Multiple expressions are not supported in this context")),
3406 					pstate.start,
3407 					(pstate.ptr - pstate.start));
3408 				expr = NULL;
3409 			}
3410 		} else {
3411 			/* Free the list, do not unref the content */
3412 			expr = pstate.result->data;
3413 			gnm_expr_list_free (pstate.result);
3414 		}
3415 	} else {
3416 		/* If there is no error message, attempt to be more detailed */
3417 		if (pstate.error != NULL &&
3418 		    (pstate.error->err == NULL || pstate.error->err->message == NULL)) {
3419 			char const *last_token = pstate.ptr;
3420 
3421 			if (*last_token == '\0') {
3422 				char const *str = pstate.start;
3423 				char const *res = NULL;
3424 				char const *last = find_matching_close (str, &res);
3425 
3426 				if (*last)
3427 					report_err (&pstate, g_error_new (1, PERR_MISSING_PAREN_OPEN,
3428 						_("Could not find matching opening parenthesis")),
3429 						last, 1);
3430 				else if (res != NULL)
3431 					report_err (&pstate, g_error_new (1, PERR_MISSING_PAREN_CLOSE,
3432 						_("Could not find matching closing parenthesis")),
3433 						res, 1);
3434 				else
3435 					report_err (&pstate, g_error_new (1, PERR_INVALID_EXPRESSION,
3436 						_("Invalid expression")),
3437 						pstate.ptr, pstate.ptr - pstate.start);
3438 			} else
3439 				report_err (&pstate, g_error_new (1, PERR_UNEXPECTED_TOKEN,
3440 					_("Unexpected token %c"), *last_token),
3441 					last_token, 1);
3442 		}
3443 
3444 		deallocate_all ();
3445 
3446 		expr = NULL;
3447 	}
3448 
3449 	deallocate_uninit ();
3450 
3451 	return gnm_expr_top_new (expr);
3452 }
3453 
3454 GnmLexerItem *
gnm_expr_lex_all(char const * str,GnmParsePos const * pp,GnmExprParseFlags flags,GnmConventions const * convs)3455 gnm_expr_lex_all (char const *str, GnmParsePos const *pp,
3456 		  GnmExprParseFlags flags,
3457 		  GnmConventions const *convs)
3458 {
3459 	GnmLexerItem *res = NULL;
3460 	int n = 0, alloc = 0;
3461 	ParserState pstate;
3462 	GnmParseError *error = NULL;
3463 
3464 	g_return_val_if_fail (str != NULL, NULL);
3465 	g_return_val_if_fail (pp != NULL, NULL);
3466 
3467 	if (deallocate_stack == NULL)
3468 		deallocate_init ();
3469 
3470 	setup_state (&pstate, str, pp, flags, convs, error);
3471 
3472 	while (1) {
3473 		int len;
3474 
3475 		if (alloc <= n) {
3476 			alloc = alloc * 2 + 20;
3477 			res = g_renew (GnmLexerItem, res, alloc);
3478 		}
3479 
3480 		res[n].start = pstate.ptr - pstate.start;
3481 		res[n].token = yylex ();
3482 		res[n].end = pstate.ptr - pstate.start;
3483 
3484 		if (res[n].token == 0)
3485 			break;
3486 
3487 		len = res[n].end - res[n].start;
3488 		/* Kill spaces that got eaten, but not a space operator */
3489 		while (len > 1 && str[res[n].start] == ' ') {
3490 			res[n].start++;
3491 			len--;
3492 		}
3493 		while (len > 1 && str[res[n].end - 1] == ' ') {
3494 			res[n].end--;
3495 			len--;
3496 		}
3497 
3498 		n++;
3499 	}
3500 
3501 	deallocate_all ();
3502 
3503 	state = NULL;
3504 
3505 	return res;
3506 }
3507