Bump GDB's version number to 15.0.91.DATE-git.
[binutils-gdb.git] / gdb / m2-exp.y
blob28005e1a70008bc6331405f3af4ac7082a099f22
1 /* YACC grammar for Modula-2 expressions, for GDB.
2 Copyright (C) 1986-2024 Free Software Foundation, Inc.
3 Generated from expread.y (now c-exp.y) and contributed by the Department
4 of Computer Science at the State University of New York at Buffalo, 1991.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Parse a Modula-2 expression from text in a string,
22 and return the result as a struct expression pointer.
23 That structure contains arithmetic operations in reverse polish,
24 with constants represented by operations that are followed by special data.
25 See expression.h for the details of the format.
26 What is important here is that it can be built up sequentially
27 during the process of parsing; the lower levels of the tree always
28 come first in the result.
30 Note that malloc's and realloc's in this file are transformed to
31 xmalloc and xrealloc respectively by the same sed command in the
32 makefile that remaps any other malloc/realloc inserted by the parser
33 generator. Doing this with #defines and trying to control the interaction
34 with include files (<malloc.h> and <stdlib.h> for example) just became
35 too messy, particularly when such includes can be inserted at random
36 times by the parser generator. */
40 #include "expression.h"
41 #include "language.h"
42 #include "value.h"
43 #include "parser-defs.h"
44 #include "m2-lang.h"
45 #include "block.h"
46 #include "m2-exp.h"
48 #define parse_type(ps) builtin_type (ps->gdbarch ())
49 #define parse_m2_type(ps) builtin_m2_type (ps->gdbarch ())
51 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
52 etc). */
53 #define GDB_YY_REMAP_PREFIX m2_
54 #include "yy-remap.h"
56 /* The state of the parser, used internally when we are parsing the
57 expression. */
59 static struct parser_state *pstate = NULL;
61 int yyparse (void);
63 static int yylex (void);
65 static void yyerror (const char *);
67 static int parse_number (int);
69 /* The sign of the number being parsed. */
70 static int number_sign = 1;
72 using namespace expr;
75 /* Although the yacc "value" of an expression is not used,
76 since the result is stored in the structure being created,
77 other node types do have values. */
79 %union
81 LONGEST lval;
82 ULONGEST ulval;
83 gdb_byte val[16];
84 struct symbol *sym;
85 struct type *tval;
86 struct stoken sval;
87 int voidval;
88 const struct block *bval;
89 enum exp_opcode opcode;
90 struct internalvar *ivar;
92 struct type **tvec;
93 int *ivec;
96 %type <voidval> exp type_exp start set
97 %type <voidval> variable
98 %type <tval> type
99 %type <bval> block
100 %type <sym> fblock
102 %token <lval> INT HEX ERROR
103 %token <ulval> UINT M2_TRUE M2_FALSE CHAR
104 %token <val> FLOAT
106 /* Both NAME and TYPENAME tokens represent symbols in the input,
107 and both convey their data as strings.
108 But a TYPENAME is a string that happens to be defined as a typedef
109 or builtin type name (such as int or char)
110 and a NAME is any other symbol.
112 Contexts where this distinction is not important can use the
113 nonterminal "name", which matches either NAME or TYPENAME. */
115 %token <sval> STRING
116 %token <sval> NAME BLOCKNAME IDENT VARNAME
117 %token <sval> TYPENAME
119 %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
120 %token TSIZE
121 %token INC DEC INCL EXCL
123 /* The GDB scope operator */
124 %token COLONCOLON
126 %token <sval> DOLLAR_VARIABLE
128 /* M2 tokens */
129 %left ','
130 %left ABOVE_COMMA
131 %nonassoc ASSIGN
132 %left '<' '>' LEQ GEQ '=' NOTEQUAL '#' IN
133 %left OROR
134 %left LOGICAL_AND '&'
135 %left '@'
136 %left '+' '-'
137 %left '*' '/' DIV MOD
138 %right UNARY
139 %right '^' DOT '[' '('
140 %right NOT '~'
141 %left COLONCOLON QID
142 /* This is not an actual token ; it is used for precedence.
143 %right QID
149 start : exp
150 | type_exp
153 type_exp: type
154 { pstate->push_new<type_operation> ($1); }
157 /* Expressions */
159 exp : exp '^' %prec UNARY
160 { pstate->wrap<unop_ind_operation> (); }
163 exp : '-'
164 { number_sign = -1; }
165 exp %prec UNARY
166 { number_sign = 1;
167 pstate->wrap<unary_neg_operation> (); }
170 exp : '+' exp %prec UNARY
171 { pstate->wrap<unary_plus_operation> (); }
174 exp : not_exp exp %prec UNARY
175 { pstate->wrap<unary_logical_not_operation> (); }
178 not_exp : NOT
179 | '~'
182 exp : CAP '(' exp ')'
183 { error (_("CAP function is not implemented")); }
186 exp : ORD '(' exp ')'
187 { error (_("ORD function is not implemented")); }
190 exp : ABS '(' exp ')'
191 { error (_("ABS function is not implemented")); }
194 exp : HIGH '(' exp ')'
195 { pstate->wrap<m2_unop_high_operation> (); }
198 exp : MIN_FUNC '(' type ')'
199 { error (_("MIN function is not implemented")); }
202 exp : MAX_FUNC '(' type ')'
203 { error (_("MAX function is not implemented")); }
206 exp : FLOAT_FUNC '(' exp ')'
207 { error (_("FLOAT function is not implemented")); }
210 exp : VAL '(' type ',' exp ')'
211 { error (_("VAL function is not implemented")); }
214 exp : CHR '(' exp ')'
215 { error (_("CHR function is not implemented")); }
218 exp : ODD '(' exp ')'
219 { error (_("ODD function is not implemented")); }
222 exp : TRUNC '(' exp ')'
223 { error (_("TRUNC function is not implemented")); }
226 exp : TSIZE '(' exp ')'
227 { pstate->wrap<unop_sizeof_operation> (); }
230 exp : SIZE exp %prec UNARY
231 { pstate->wrap<unop_sizeof_operation> (); }
235 exp : INC '(' exp ')'
236 { pstate->wrap<preinc_operation> (); }
239 exp : INC '(' exp ',' exp ')'
241 operation_up rhs = pstate->pop ();
242 operation_up lhs = pstate->pop ();
243 pstate->push_new<assign_modify_operation>
244 (BINOP_ADD, std::move (lhs), std::move (rhs));
248 exp : DEC '(' exp ')'
249 { pstate->wrap<predec_operation> (); }
252 exp : DEC '(' exp ',' exp ')'
254 operation_up rhs = pstate->pop ();
255 operation_up lhs = pstate->pop ();
256 pstate->push_new<assign_modify_operation>
257 (BINOP_SUB, std::move (lhs), std::move (rhs));
261 exp : exp DOT NAME
263 pstate->push_new<structop_operation>
264 (pstate->pop (), copy_name ($3));
268 exp : set
271 exp : exp IN set
272 { error (_("Sets are not implemented."));}
275 exp : INCL '(' exp ',' exp ')'
276 { error (_("Sets are not implemented."));}
279 exp : EXCL '(' exp ',' exp ')'
280 { error (_("Sets are not implemented."));}
283 set : '{' arglist '}'
284 { error (_("Sets are not implemented."));}
285 | type '{' arglist '}'
286 { error (_("Sets are not implemented."));}
290 /* Modula-2 array subscript notation [a,b,c...]. */
291 exp : exp '['
292 /* This function just saves the number of arguments
293 that follow in the list. It is *not* specific to
294 function types */
295 { pstate->start_arglist(); }
296 non_empty_arglist ']' %prec DOT
298 gdb_assert (pstate->arglist_len > 0);
299 std::vector<operation_up> args
300 = pstate->pop_vector (pstate->end_arglist ());
301 pstate->push_new<multi_subscript_operation>
302 (pstate->pop (), std::move (args));
306 exp : exp '('
307 /* This is to save the value of arglist_len
308 being accumulated by an outer function call. */
309 { pstate->start_arglist (); }
310 arglist ')' %prec DOT
312 std::vector<operation_up> args
313 = pstate->pop_vector (pstate->end_arglist ());
314 pstate->push_new<funcall_operation>
315 (pstate->pop (), std::move (args));
319 arglist :
322 arglist : exp
323 { pstate->arglist_len = 1; }
326 arglist : arglist ',' exp %prec ABOVE_COMMA
327 { pstate->arglist_len++; }
330 non_empty_arglist
331 : exp
332 { pstate->arglist_len = 1; }
335 non_empty_arglist
336 : non_empty_arglist ',' exp %prec ABOVE_COMMA
337 { pstate->arglist_len++; }
340 /* GDB construct */
341 exp : '{' type '}' exp %prec UNARY
343 pstate->push_new<unop_memval_operation>
344 (pstate->pop (), $2);
348 exp : type '(' exp ')' %prec UNARY
350 pstate->push_new<unop_cast_operation>
351 (pstate->pop (), $1);
355 exp : '(' exp ')'
359 /* Binary operators in order of decreasing precedence. Note that some
360 of these operators are overloaded! (ie. sets) */
362 /* GDB construct */
363 exp : exp '@' exp
364 { pstate->wrap2<repeat_operation> (); }
367 exp : exp '*' exp
368 { pstate->wrap2<mul_operation> (); }
371 exp : exp '/' exp
372 { pstate->wrap2<div_operation> (); }
375 exp : exp DIV exp
376 { pstate->wrap2<intdiv_operation> (); }
379 exp : exp MOD exp
380 { pstate->wrap2<rem_operation> (); }
383 exp : exp '+' exp
384 { pstate->wrap2<add_operation> (); }
387 exp : exp '-' exp
388 { pstate->wrap2<sub_operation> (); }
391 exp : exp '=' exp
392 { pstate->wrap2<equal_operation> (); }
395 exp : exp NOTEQUAL exp
396 { pstate->wrap2<notequal_operation> (); }
397 | exp '#' exp
398 { pstate->wrap2<notequal_operation> (); }
401 exp : exp LEQ exp
402 { pstate->wrap2<leq_operation> (); }
405 exp : exp GEQ exp
406 { pstate->wrap2<geq_operation> (); }
409 exp : exp '<' exp
410 { pstate->wrap2<less_operation> (); }
413 exp : exp '>' exp
414 { pstate->wrap2<gtr_operation> (); }
417 exp : exp LOGICAL_AND exp
418 { pstate->wrap2<logical_and_operation> (); }
421 exp : exp OROR exp
422 { pstate->wrap2<logical_or_operation> (); }
425 exp : exp ASSIGN exp
426 { pstate->wrap2<assign_operation> (); }
430 /* Constants */
432 exp : M2_TRUE
433 { pstate->push_new<bool_operation> ($1); }
436 exp : M2_FALSE
437 { pstate->push_new<bool_operation> ($1); }
440 exp : INT
442 pstate->push_new<long_const_operation>
443 (parse_m2_type (pstate)->builtin_int, $1);
447 exp : UINT
449 pstate->push_new<long_const_operation>
450 (parse_m2_type (pstate)->builtin_card, $1);
454 exp : CHAR
456 pstate->push_new<long_const_operation>
457 (parse_m2_type (pstate)->builtin_char, $1);
462 exp : FLOAT
464 float_data data;
465 std::copy (std::begin ($1), std::end ($1),
466 std::begin (data));
467 pstate->push_new<float_const_operation>
468 (parse_m2_type (pstate)->builtin_real, data);
472 exp : variable
475 exp : SIZE '(' type ')' %prec UNARY
477 pstate->push_new<long_const_operation>
478 (parse_m2_type (pstate)->builtin_int,
479 $3->length ());
483 exp : STRING
484 { error (_("strings are not implemented")); }
487 /* This will be used for extensions later. Like adding modules. */
488 block : fblock
489 { $$ = $1->value_block (); }
492 fblock : BLOCKNAME
493 { struct symbol *sym
494 = lookup_symbol (copy_name ($1).c_str (),
495 pstate->expression_context_block,
496 SEARCH_VFT, 0).symbol;
497 $$ = sym;}
501 /* GDB scope operator */
502 fblock : block COLONCOLON BLOCKNAME
503 { struct symbol *tem
504 = lookup_symbol (copy_name ($3).c_str (), $1,
505 SEARCH_VFT, 0).symbol;
506 if (!tem || tem->aclass () != LOC_BLOCK)
507 error (_("No function \"%s\" in specified context."),
508 copy_name ($3).c_str ());
509 $$ = tem;
513 /* Useful for assigning to PROCEDURE variables */
514 variable: fblock
516 block_symbol sym { $1, nullptr };
517 pstate->push_new<var_value_operation> (sym);
521 /* GDB internal ($foo) variable */
522 variable: DOLLAR_VARIABLE
523 { pstate->push_dollar ($1); }
526 /* GDB scope operator */
527 variable: block COLONCOLON NAME
528 { struct block_symbol sym
529 = lookup_symbol (copy_name ($3).c_str (), $1,
530 SEARCH_VFT, 0);
532 if (sym.symbol == 0)
533 error (_("No symbol \"%s\" in specified context."),
534 copy_name ($3).c_str ());
535 if (symbol_read_needs_frame (sym.symbol))
536 pstate->block_tracker->update (sym);
538 pstate->push_new<var_value_operation> (sym);
542 /* Base case for variables. */
543 variable: NAME
544 { struct block_symbol sym;
545 struct field_of_this_result is_a_field_of_this;
547 std::string name = copy_name ($1);
549 = lookup_symbol (name.c_str (),
550 pstate->expression_context_block,
551 SEARCH_VFT,
552 &is_a_field_of_this);
554 pstate->push_symbol (name.c_str (), sym);
558 type
559 : TYPENAME
560 { $$
561 = lookup_typename (pstate->language (),
562 copy_name ($1).c_str (),
563 pstate->expression_context_block,
571 /* Take care of parsing a number (anything that starts with a digit).
572 Set yylval and return the token type; update lexptr.
573 LEN is the number of characters in it. */
575 /*** Needs some error checking for the float case ***/
577 static int
578 parse_number (int olen)
580 const char *p = pstate->lexptr;
581 ULONGEST n = 0;
582 ULONGEST prevn = 0;
583 int c,i,ischar=0;
584 int base = input_radix;
585 int len = olen;
587 if(p[len-1] == 'H')
589 base = 16;
590 len--;
592 else if(p[len-1] == 'C' || p[len-1] == 'B')
594 base = 8;
595 ischar = p[len-1] == 'C';
596 len--;
599 /* Scan the number */
600 for (c = 0; c < len; c++)
602 if (p[c] == '.' && base == 10)
604 /* It's a float since it contains a point. */
605 if (!parse_float (p, len,
606 parse_m2_type (pstate)->builtin_real,
607 yylval.val))
608 return ERROR;
610 pstate->lexptr += len;
611 return FLOAT;
613 if (p[c] == '.' && base != 10)
614 error (_("Floating point numbers must be base 10."));
615 if (base == 10 && (p[c] < '0' || p[c] > '9'))
616 error (_("Invalid digit \'%c\' in number."),p[c]);
619 while (len-- > 0)
621 c = *p++;
622 n *= base;
623 if( base == 8 && (c == '8' || c == '9'))
624 error (_("Invalid digit \'%c\' in octal number."),c);
625 if (c >= '0' && c <= '9')
626 i = c - '0';
627 else
629 if (base == 16 && c >= 'A' && c <= 'F')
630 i = c - 'A' + 10;
631 else
632 return ERROR;
634 n+=i;
635 if(i >= base)
636 return ERROR;
637 if (n == 0 && prevn == 0)
639 else if (RANGE_CHECK && prevn >= n)
640 range_error (_("Overflow on numeric constant."));
642 prevn=n;
645 pstate->lexptr = p;
646 if(*p == 'B' || *p == 'C' || *p == 'H')
647 pstate->lexptr++; /* Advance past B,C or H */
649 if (ischar)
651 yylval.ulval = n;
652 return CHAR;
655 int int_bits = gdbarch_int_bit (pstate->gdbarch ());
656 bool have_signed = number_sign == -1;
657 bool have_unsigned = number_sign == 1;
658 if (have_signed && fits_in_type (number_sign, n, int_bits, true))
660 yylval.lval = n;
661 return INT;
663 else if (have_unsigned && fits_in_type (number_sign, n, int_bits, false))
665 yylval.ulval = n;
666 return UINT;
668 else
669 error (_("Overflow on numeric constant."));
673 /* Some tokens */
675 static struct
677 char name[2];
678 int token;
679 } tokentab2[] =
681 { {'<', '>'}, NOTEQUAL },
682 { {':', '='}, ASSIGN },
683 { {'<', '='}, LEQ },
684 { {'>', '='}, GEQ },
685 { {':', ':'}, COLONCOLON },
689 /* Some specific keywords */
691 struct keyword {
692 char keyw[10];
693 int token;
696 static struct keyword keytab[] =
698 {"OR" , OROR },
699 {"IN", IN },/* Note space after IN */
700 {"AND", LOGICAL_AND},
701 {"ABS", ABS },
702 {"CHR", CHR },
703 {"DEC", DEC },
704 {"NOT", NOT },
705 {"DIV", DIV },
706 {"INC", INC },
707 {"MAX", MAX_FUNC },
708 {"MIN", MIN_FUNC },
709 {"MOD", MOD },
710 {"ODD", ODD },
711 {"CAP", CAP },
712 {"ORD", ORD },
713 {"VAL", VAL },
714 {"EXCL", EXCL },
715 {"HIGH", HIGH },
716 {"INCL", INCL },
717 {"SIZE", SIZE },
718 {"FLOAT", FLOAT_FUNC },
719 {"TRUNC", TRUNC },
720 {"TSIZE", SIZE },
724 /* Depth of parentheses. */
725 static int paren_depth;
727 /* Read one token, getting characters through lexptr. */
729 /* This is where we will check to make sure that the language and the
730 operators used are compatible */
732 static int
733 yylex (void)
735 int c;
736 int namelen;
737 int i;
738 const char *tokstart;
739 char quote;
741 retry:
743 pstate->prev_lexptr = pstate->lexptr;
745 tokstart = pstate->lexptr;
748 /* See if it is a special token of length 2 */
749 for( i = 0 ; i < (int) (sizeof tokentab2 / sizeof tokentab2[0]) ; i++)
750 if (strncmp (tokentab2[i].name, tokstart, 2) == 0)
752 pstate->lexptr += 2;
753 return tokentab2[i].token;
756 switch (c = *tokstart)
758 case 0:
759 return 0;
761 case ' ':
762 case '\t':
763 case '\n':
764 pstate->lexptr++;
765 goto retry;
767 case '(':
768 paren_depth++;
769 pstate->lexptr++;
770 return c;
772 case ')':
773 if (paren_depth == 0)
774 return 0;
775 paren_depth--;
776 pstate->lexptr++;
777 return c;
779 case ',':
780 if (pstate->comma_terminates && paren_depth == 0)
781 return 0;
782 pstate->lexptr++;
783 return c;
785 case '.':
786 /* Might be a floating point number. */
787 if (pstate->lexptr[1] >= '0' && pstate->lexptr[1] <= '9')
788 break; /* Falls into number code. */
789 else
791 pstate->lexptr++;
792 return DOT;
795 /* These are character tokens that appear as-is in the YACC grammar */
796 case '+':
797 case '-':
798 case '*':
799 case '/':
800 case '^':
801 case '<':
802 case '>':
803 case '[':
804 case ']':
805 case '=':
806 case '{':
807 case '}':
808 case '#':
809 case '@':
810 case '~':
811 case '&':
812 pstate->lexptr++;
813 return c;
815 case '\'' :
816 case '"':
817 quote = c;
818 for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
819 if (c == '\\')
821 c = tokstart[++namelen];
822 if (c >= '0' && c <= '9')
824 c = tokstart[++namelen];
825 if (c >= '0' && c <= '9')
826 c = tokstart[++namelen];
829 if(c != quote)
830 error (_("Unterminated string or character constant."));
831 yylval.sval.ptr = tokstart + 1;
832 yylval.sval.length = namelen - 1;
833 pstate->lexptr += namelen + 1;
835 if(namelen == 2) /* Single character */
837 yylval.ulval = tokstart[1];
838 return CHAR;
840 else
841 return STRING;
844 /* Is it a number? */
845 /* Note: We have already dealt with the case of the token '.'.
846 See case '.' above. */
847 if ((c >= '0' && c <= '9'))
849 /* It's a number. */
850 int got_dot = 0, got_e = 0;
851 const char *p = tokstart;
852 int toktype;
854 for (++p ;; ++p)
856 if (!got_e && (*p == 'e' || *p == 'E'))
857 got_dot = got_e = 1;
858 else if (!got_dot && *p == '.')
859 got_dot = 1;
860 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
861 && (*p == '-' || *p == '+'))
862 /* This is the sign of the exponent, not the end of the
863 number. */
864 continue;
865 else if ((*p < '0' || *p > '9') &&
866 (*p < 'A' || *p > 'F') &&
867 (*p != 'H')) /* Modula-2 hexadecimal number */
868 break;
870 toktype = parse_number (p - tokstart);
871 if (toktype == ERROR)
872 error (_("Invalid number \"%.*s\"."), (int) (p - tokstart),
873 tokstart);
874 pstate->lexptr = p;
875 return toktype;
878 if (!(c == '_' || c == '$'
879 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
880 /* We must have come across a bad character (e.g. ';'). */
881 error (_("Invalid character '%c' in expression."), c);
883 /* It's a name. See how long it is. */
884 namelen = 0;
885 for (c = tokstart[namelen];
886 (c == '_' || c == '$' || (c >= '0' && c <= '9')
887 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
888 c = tokstart[++namelen])
891 /* The token "if" terminates the expression and is NOT
892 removed from the input stream. */
893 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
895 return 0;
898 pstate->lexptr += namelen;
900 /* Lookup special keywords */
901 for(i = 0 ; i < (int) (sizeof(keytab) / sizeof(keytab[0])) ; i++)
902 if (namelen == strlen (keytab[i].keyw)
903 && strncmp (tokstart, keytab[i].keyw, namelen) == 0)
904 return keytab[i].token;
906 yylval.sval.ptr = tokstart;
907 yylval.sval.length = namelen;
909 if (*tokstart == '$')
910 return DOLLAR_VARIABLE;
912 /* Use token-type BLOCKNAME for symbols that happen to be defined as
913 functions. If this is not so, then ...
914 Use token-type TYPENAME for symbols that happen to be defined
915 currently as names of types; NAME for other symbols.
916 The caller is not constrained to care about the distinction. */
918 std::string tmp = copy_name (yylval.sval);
919 struct symbol *sym;
921 if (lookup_symtab (tmp.c_str ()))
922 return BLOCKNAME;
923 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
924 SEARCH_VFT, 0).symbol;
925 if (sym && sym->aclass () == LOC_BLOCK)
926 return BLOCKNAME;
927 if (lookup_typename (pstate->language (),
928 tmp.c_str (), pstate->expression_context_block, 1))
929 return TYPENAME;
931 if(sym)
933 switch(sym->aclass ())
935 case LOC_STATIC:
936 case LOC_REGISTER:
937 case LOC_ARG:
938 case LOC_REF_ARG:
939 case LOC_REGPARM_ADDR:
940 case LOC_LOCAL:
941 case LOC_CONST:
942 case LOC_CONST_BYTES:
943 case LOC_OPTIMIZED_OUT:
944 case LOC_COMPUTED:
945 return NAME;
947 case LOC_TYPEDEF:
948 return TYPENAME;
950 case LOC_BLOCK:
951 return BLOCKNAME;
953 case LOC_UNDEF:
954 error (_("internal: Undefined class in m2lex()"));
956 case LOC_LABEL:
957 case LOC_UNRESOLVED:
958 error (_("internal: Unforseen case in m2lex()"));
960 default:
961 error (_("unhandled token in m2lex()"));
962 break;
965 else
967 /* Built-in BOOLEAN type. This is sort of a hack. */
968 if (startswith (tokstart, "TRUE"))
970 yylval.ulval = 1;
971 return M2_TRUE;
973 else if (startswith (tokstart, "FALSE"))
975 yylval.ulval = 0;
976 return M2_FALSE;
980 /* Must be another type of name... */
981 return NAME;
986 m2_language::parser (struct parser_state *par_state) const
988 /* Setting up the parser state. */
989 scoped_restore pstate_restore = make_scoped_restore (&pstate);
990 gdb_assert (par_state != NULL);
991 pstate = par_state;
992 paren_depth = 0;
994 int result = yyparse ();
995 if (!result)
996 pstate->set_operation (pstate->pop ());
997 return result;
1000 static void
1001 yyerror (const char *msg)
1003 pstate->parse_error (msg);