Add translations for various sub-directories
[binutils-gdb.git] / gdb / m2-exp.y
blob0201f84cfa542f635562660862aa6dce6da982be
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 ADR
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 : ADR '(' exp ')'
195 { pstate->wrap<unop_addr_operation> (); }
198 exp : HIGH '(' exp ')'
199 { pstate->wrap<m2_unop_high_operation> (); }
202 exp : MIN_FUNC '(' type ')'
203 { error (_("MIN function is not implemented")); }
206 exp : MAX_FUNC '(' type ')'
207 { error (_("MAX function is not implemented")); }
210 exp : FLOAT_FUNC '(' exp ')'
211 { error (_("FLOAT function is not implemented")); }
214 exp : VAL '(' type ',' exp ')'
215 { error (_("VAL function is not implemented")); }
218 exp : CHR '(' exp ')'
219 { error (_("CHR function is not implemented")); }
222 exp : ODD '(' exp ')'
223 { error (_("ODD function is not implemented")); }
226 exp : TRUNC '(' exp ')'
227 { error (_("TRUNC function is not implemented")); }
230 exp : TSIZE '(' exp ')'
231 { pstate->wrap<unop_sizeof_operation> (); }
234 exp : SIZE exp %prec UNARY
235 { pstate->wrap<unop_sizeof_operation> (); }
239 exp : INC '(' exp ')'
240 { pstate->wrap<preinc_operation> (); }
243 exp : INC '(' exp ',' exp ')'
245 operation_up rhs = pstate->pop ();
246 operation_up lhs = pstate->pop ();
247 pstate->push_new<assign_modify_operation>
248 (BINOP_ADD, std::move (lhs), std::move (rhs));
252 exp : DEC '(' exp ')'
253 { pstate->wrap<predec_operation> (); }
256 exp : DEC '(' exp ',' exp ')'
258 operation_up rhs = pstate->pop ();
259 operation_up lhs = pstate->pop ();
260 pstate->push_new<assign_modify_operation>
261 (BINOP_SUB, std::move (lhs), std::move (rhs));
265 exp : exp DOT NAME
267 pstate->push_new<structop_operation>
268 (pstate->pop (), copy_name ($3));
272 exp : set
275 exp : exp IN set
276 { error (_("Sets are not implemented."));}
279 exp : INCL '(' exp ',' exp ')'
280 { error (_("Sets are not implemented."));}
283 exp : EXCL '(' exp ',' exp ')'
284 { error (_("Sets are not implemented."));}
287 set : '{' arglist '}'
288 { error (_("Sets are not implemented."));}
289 | type '{' arglist '}'
290 { error (_("Sets are not implemented."));}
294 /* Modula-2 array subscript notation [a,b,c...]. */
295 exp : exp '['
296 /* This function just saves the number of arguments
297 that follow in the list. It is *not* specific to
298 function types */
299 { pstate->start_arglist(); }
300 non_empty_arglist ']' %prec DOT
302 gdb_assert (pstate->arglist_len > 0);
303 std::vector<operation_up> args
304 = pstate->pop_vector (pstate->end_arglist ());
305 pstate->push_new<multi_subscript_operation>
306 (pstate->pop (), std::move (args));
310 exp : exp '('
311 /* This is to save the value of arglist_len
312 being accumulated by an outer function call. */
313 { pstate->start_arglist (); }
314 arglist ')' %prec DOT
316 std::vector<operation_up> args
317 = pstate->pop_vector (pstate->end_arglist ());
318 pstate->push_new<funcall_operation>
319 (pstate->pop (), std::move (args));
323 arglist :
326 arglist : exp
327 { pstate->arglist_len = 1; }
330 arglist : arglist ',' exp %prec ABOVE_COMMA
331 { pstate->arglist_len++; }
334 non_empty_arglist
335 : exp
336 { pstate->arglist_len = 1; }
339 non_empty_arglist
340 : non_empty_arglist ',' exp %prec ABOVE_COMMA
341 { pstate->arglist_len++; }
344 /* GDB construct */
345 exp : '{' type '}' exp %prec UNARY
347 pstate->push_new<unop_memval_operation>
348 (pstate->pop (), $2);
352 exp : type '(' exp ')' %prec UNARY
354 pstate->push_new<unop_cast_operation>
355 (pstate->pop (), $1);
359 exp : '(' exp ')'
363 /* Binary operators in order of decreasing precedence. Note that some
364 of these operators are overloaded! (ie. sets) */
366 /* GDB construct */
367 exp : exp '@' exp
368 { pstate->wrap2<repeat_operation> (); }
371 exp : exp '*' exp
372 { pstate->wrap2<mul_operation> (); }
375 exp : exp '/' exp
376 { pstate->wrap2<div_operation> (); }
379 exp : exp DIV exp
380 { pstate->wrap2<intdiv_operation> (); }
383 exp : exp MOD exp
384 { pstate->wrap2<rem_operation> (); }
387 exp : exp '+' exp
388 { pstate->wrap2<add_operation> (); }
391 exp : exp '-' exp
392 { pstate->wrap2<sub_operation> (); }
395 exp : exp '=' exp
396 { pstate->wrap2<equal_operation> (); }
399 exp : exp NOTEQUAL exp
400 { pstate->wrap2<notequal_operation> (); }
401 | exp '#' exp
402 { pstate->wrap2<notequal_operation> (); }
405 exp : exp LEQ exp
406 { pstate->wrap2<leq_operation> (); }
409 exp : exp GEQ exp
410 { pstate->wrap2<geq_operation> (); }
413 exp : exp '<' exp
414 { pstate->wrap2<less_operation> (); }
417 exp : exp '>' exp
418 { pstate->wrap2<gtr_operation> (); }
421 exp : exp LOGICAL_AND exp
422 { pstate->wrap2<logical_and_operation> (); }
425 exp : exp OROR exp
426 { pstate->wrap2<logical_or_operation> (); }
429 exp : exp ASSIGN exp
430 { pstate->wrap2<assign_operation> (); }
434 /* Constants */
436 exp : M2_TRUE
437 { pstate->push_new<bool_operation> ($1); }
440 exp : M2_FALSE
441 { pstate->push_new<bool_operation> ($1); }
444 exp : INT
446 pstate->push_new<long_const_operation>
447 (parse_m2_type (pstate)->builtin_int, $1);
451 exp : UINT
453 pstate->push_new<long_const_operation>
454 (parse_m2_type (pstate)->builtin_card, $1);
458 exp : CHAR
460 pstate->push_new<long_const_operation>
461 (parse_m2_type (pstate)->builtin_char, $1);
466 exp : FLOAT
468 float_data data;
469 std::copy (std::begin ($1), std::end ($1),
470 std::begin (data));
471 pstate->push_new<float_const_operation>
472 (parse_m2_type (pstate)->builtin_real, data);
476 exp : variable
479 exp : SIZE '(' type ')' %prec UNARY
481 pstate->push_new<long_const_operation>
482 (parse_m2_type (pstate)->builtin_int,
483 $3->length ());
487 exp : STRING
488 { error (_("strings are not implemented")); }
491 /* This will be used for extensions later. Like adding modules. */
492 block : fblock
493 { $$ = $1->value_block (); }
496 fblock : BLOCKNAME
497 { struct symbol *sym
498 = lookup_symbol (copy_name ($1).c_str (),
499 pstate->expression_context_block,
500 SEARCH_VFT, 0).symbol;
501 $$ = sym;}
505 /* GDB scope operator */
506 fblock : block COLONCOLON BLOCKNAME
507 { struct symbol *tem
508 = lookup_symbol (copy_name ($3).c_str (), $1,
509 SEARCH_VFT, 0).symbol;
510 if (!tem || tem->aclass () != LOC_BLOCK)
511 error (_("No function \"%s\" in specified context."),
512 copy_name ($3).c_str ());
513 $$ = tem;
517 /* Useful for assigning to PROCEDURE variables */
518 variable: fblock
520 block_symbol sym { $1, nullptr };
521 pstate->push_new<var_value_operation> (sym);
525 /* GDB internal ($foo) variable */
526 variable: DOLLAR_VARIABLE
527 { pstate->push_dollar ($1); }
530 /* GDB scope operator */
531 variable: block COLONCOLON NAME
532 { struct block_symbol sym
533 = lookup_symbol (copy_name ($3).c_str (), $1,
534 SEARCH_VFT, 0);
536 if (sym.symbol == 0)
537 error (_("No symbol \"%s\" in specified context."),
538 copy_name ($3).c_str ());
539 if (symbol_read_needs_frame (sym.symbol))
540 pstate->block_tracker->update (sym);
542 pstate->push_new<var_value_operation> (sym);
546 /* Base case for variables. */
547 variable: NAME
548 { struct block_symbol sym;
549 struct field_of_this_result is_a_field_of_this;
551 std::string name = copy_name ($1);
553 = lookup_symbol (name.c_str (),
554 pstate->expression_context_block,
555 SEARCH_VFT,
556 &is_a_field_of_this);
558 pstate->push_symbol (name.c_str (), sym);
562 type
563 : TYPENAME
564 { $$
565 = lookup_typename (pstate->language (),
566 copy_name ($1).c_str (),
567 pstate->expression_context_block,
575 /* Take care of parsing a number (anything that starts with a digit).
576 Set yylval and return the token type; update lexptr.
577 LEN is the number of characters in it. */
579 /*** Needs some error checking for the float case ***/
581 static int
582 parse_number (int olen)
584 const char *p = pstate->lexptr;
585 ULONGEST n = 0;
586 ULONGEST prevn = 0;
587 int c,i,ischar=0;
588 int base = input_radix;
589 int len = olen;
591 if(p[len-1] == 'H')
593 base = 16;
594 len--;
596 else if(p[len-1] == 'C' || p[len-1] == 'B')
598 base = 8;
599 ischar = p[len-1] == 'C';
600 len--;
603 /* Scan the number */
604 for (c = 0; c < len; c++)
606 if (p[c] == '.' && base == 10)
608 /* It's a float since it contains a point. */
609 if (!parse_float (p, len,
610 parse_m2_type (pstate)->builtin_real,
611 yylval.val))
612 return ERROR;
614 pstate->lexptr += len;
615 return FLOAT;
617 if (p[c] == '.' && base != 10)
618 error (_("Floating point numbers must be base 10."));
619 if (base == 10 && (p[c] < '0' || p[c] > '9'))
620 error (_("Invalid digit \'%c\' in number."),p[c]);
623 while (len-- > 0)
625 c = *p++;
626 n *= base;
627 if( base == 8 && (c == '8' || c == '9'))
628 error (_("Invalid digit \'%c\' in octal number."),c);
629 if (c >= '0' && c <= '9')
630 i = c - '0';
631 else
633 if (base == 16 && c >= 'A' && c <= 'F')
634 i = c - 'A' + 10;
635 else
636 return ERROR;
638 n+=i;
639 if(i >= base)
640 return ERROR;
641 if (n == 0 && prevn == 0)
643 else if (RANGE_CHECK && prevn >= n)
644 range_error (_("Overflow on numeric constant."));
646 prevn=n;
649 pstate->lexptr = p;
650 if(*p == 'B' || *p == 'C' || *p == 'H')
651 pstate->lexptr++; /* Advance past B,C or H */
653 if (ischar)
655 yylval.ulval = n;
656 return CHAR;
659 int int_bits = gdbarch_int_bit (pstate->gdbarch ());
660 bool have_signed = number_sign == -1;
661 bool have_unsigned = number_sign == 1;
662 if (have_signed && fits_in_type (number_sign, n, int_bits, true))
664 yylval.lval = n;
665 return INT;
667 else if (have_unsigned && fits_in_type (number_sign, n, int_bits, false))
669 yylval.ulval = n;
670 return UINT;
672 else
673 error (_("Overflow on numeric constant."));
677 /* Some tokens */
679 static struct
681 char name[2];
682 int token;
683 } tokentab2[] =
685 { {'<', '>'}, NOTEQUAL },
686 { {':', '='}, ASSIGN },
687 { {'<', '='}, LEQ },
688 { {'>', '='}, GEQ },
689 { {':', ':'}, COLONCOLON },
693 /* Some specific keywords */
695 struct keyword {
696 char keyw[10];
697 int token;
700 static struct keyword keytab[] =
702 {"OR" , OROR },
703 {"IN", IN },/* Note space after IN */
704 {"AND", LOGICAL_AND},
705 {"ABS", ABS },
706 {"ADR", ADR },
707 {"CHR", CHR },
708 {"DEC", DEC },
709 {"NOT", NOT },
710 {"DIV", DIV },
711 {"INC", INC },
712 {"MAX", MAX_FUNC },
713 {"MIN", MIN_FUNC },
714 {"MOD", MOD },
715 {"ODD", ODD },
716 {"CAP", CAP },
717 {"ORD", ORD },
718 {"VAL", VAL },
719 {"EXCL", EXCL },
720 {"HIGH", HIGH },
721 {"INCL", INCL },
722 {"SIZE", SIZE },
723 {"FLOAT", FLOAT_FUNC },
724 {"TRUNC", TRUNC },
725 {"TSIZE", SIZE },
729 /* Depth of parentheses. */
730 static int paren_depth;
732 /* Read one token, getting characters through lexptr. */
734 /* This is where we will check to make sure that the language and the
735 operators used are compatible */
737 static int
738 yylex (void)
740 int c;
741 int namelen;
742 int i;
743 const char *tokstart;
744 char quote;
746 retry:
748 pstate->prev_lexptr = pstate->lexptr;
750 tokstart = pstate->lexptr;
753 /* See if it is a special token of length 2 */
754 for( i = 0 ; i < (int) (sizeof tokentab2 / sizeof tokentab2[0]) ; i++)
755 if (strncmp (tokentab2[i].name, tokstart, 2) == 0)
757 pstate->lexptr += 2;
758 return tokentab2[i].token;
761 switch (c = *tokstart)
763 case 0:
764 return 0;
766 case ' ':
767 case '\t':
768 case '\n':
769 pstate->lexptr++;
770 goto retry;
772 case '(':
773 paren_depth++;
774 pstate->lexptr++;
775 return c;
777 case ')':
778 if (paren_depth == 0)
779 return 0;
780 paren_depth--;
781 pstate->lexptr++;
782 return c;
784 case ',':
785 if (pstate->comma_terminates && paren_depth == 0)
786 return 0;
787 pstate->lexptr++;
788 return c;
790 case '.':
791 /* Might be a floating point number. */
792 if (pstate->lexptr[1] >= '0' && pstate->lexptr[1] <= '9')
793 break; /* Falls into number code. */
794 else
796 pstate->lexptr++;
797 return DOT;
800 /* These are character tokens that appear as-is in the YACC grammar */
801 case '+':
802 case '-':
803 case '*':
804 case '/':
805 case '^':
806 case '<':
807 case '>':
808 case '[':
809 case ']':
810 case '=':
811 case '{':
812 case '}':
813 case '#':
814 case '@':
815 case '~':
816 case '&':
817 pstate->lexptr++;
818 return c;
820 case '\'' :
821 case '"':
822 quote = c;
823 for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
824 if (c == '\\')
826 c = tokstart[++namelen];
827 if (c >= '0' && c <= '9')
829 c = tokstart[++namelen];
830 if (c >= '0' && c <= '9')
831 c = tokstart[++namelen];
834 if(c != quote)
835 error (_("Unterminated string or character constant."));
836 yylval.sval.ptr = tokstart + 1;
837 yylval.sval.length = namelen - 1;
838 pstate->lexptr += namelen + 1;
840 if(namelen == 2) /* Single character */
842 yylval.ulval = tokstart[1];
843 return CHAR;
845 else
846 return STRING;
849 /* Is it a number? */
850 /* Note: We have already dealt with the case of the token '.'.
851 See case '.' above. */
852 if ((c >= '0' && c <= '9'))
854 /* It's a number. */
855 int got_dot = 0, got_e = 0;
856 const char *p = tokstart;
857 int toktype;
859 for (++p ;; ++p)
861 if (!got_e && (*p == 'e' || *p == 'E'))
862 got_dot = got_e = 1;
863 else if (!got_dot && *p == '.')
864 got_dot = 1;
865 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
866 && (*p == '-' || *p == '+'))
867 /* This is the sign of the exponent, not the end of the
868 number. */
869 continue;
870 else if ((*p < '0' || *p > '9') &&
871 (*p < 'A' || *p > 'F') &&
872 (*p != 'H')) /* Modula-2 hexadecimal number */
873 break;
875 toktype = parse_number (p - tokstart);
876 if (toktype == ERROR)
877 error (_("Invalid number \"%.*s\"."), (int) (p - tokstart),
878 tokstart);
879 pstate->lexptr = p;
880 return toktype;
883 if (!(c == '_' || c == '$'
884 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
885 /* We must have come across a bad character (e.g. ';'). */
886 error (_("Invalid character '%c' in expression."), c);
888 /* It's a name. See how long it is. */
889 namelen = 0;
890 for (c = tokstart[namelen];
891 (c == '_' || c == '$' || (c >= '0' && c <= '9')
892 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
893 c = tokstart[++namelen])
896 /* The token "if" terminates the expression and is NOT
897 removed from the input stream. */
898 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
900 return 0;
903 pstate->lexptr += namelen;
905 /* Lookup special keywords */
906 for(i = 0 ; i < (int) (sizeof(keytab) / sizeof(keytab[0])) ; i++)
907 if (namelen == strlen (keytab[i].keyw)
908 && strncmp (tokstart, keytab[i].keyw, namelen) == 0)
909 return keytab[i].token;
911 yylval.sval.ptr = tokstart;
912 yylval.sval.length = namelen;
914 if (*tokstart == '$')
915 return DOLLAR_VARIABLE;
917 /* Use token-type BLOCKNAME for symbols that happen to be defined as
918 functions. If this is not so, then ...
919 Use token-type TYPENAME for symbols that happen to be defined
920 currently as names of types; NAME for other symbols.
921 The caller is not constrained to care about the distinction. */
923 std::string tmp = copy_name (yylval.sval);
924 struct symbol *sym;
926 if (lookup_symtab (current_program_space, tmp.c_str ()) != nullptr)
927 return BLOCKNAME;
929 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
930 SEARCH_VFT, 0).symbol;
931 if (sym && sym->aclass () == LOC_BLOCK)
932 return BLOCKNAME;
933 if (lookup_typename (pstate->language (),
934 tmp.c_str (), pstate->expression_context_block, 1))
935 return TYPENAME;
937 if(sym)
939 switch(sym->aclass ())
941 case LOC_STATIC:
942 case LOC_REGISTER:
943 case LOC_ARG:
944 case LOC_REF_ARG:
945 case LOC_REGPARM_ADDR:
946 case LOC_LOCAL:
947 case LOC_CONST:
948 case LOC_CONST_BYTES:
949 case LOC_OPTIMIZED_OUT:
950 case LOC_COMPUTED:
951 return NAME;
953 case LOC_TYPEDEF:
954 return TYPENAME;
956 case LOC_BLOCK:
957 return BLOCKNAME;
959 case LOC_UNDEF:
960 error (_("internal: Undefined class in m2lex()"));
962 case LOC_LABEL:
963 case LOC_UNRESOLVED:
964 error (_("internal: Unforeseen case in m2lex()"));
966 default:
967 error (_("unhandled token in m2lex()"));
968 break;
971 else
973 /* Built-in BOOLEAN type. This is sort of a hack. */
974 if (startswith (tokstart, "TRUE"))
976 yylval.ulval = 1;
977 return M2_TRUE;
979 else if (startswith (tokstart, "FALSE"))
981 yylval.ulval = 0;
982 return M2_FALSE;
986 /* Must be another type of name... */
987 return NAME;
992 m2_language::parser (struct parser_state *par_state) const
994 /* Setting up the parser state. */
995 scoped_restore pstate_restore = make_scoped_restore (&pstate);
996 gdb_assert (par_state != NULL);
997 pstate = par_state;
998 paren_depth = 0;
1000 int result = yyparse ();
1001 if (!result)
1002 pstate->set_operation (pstate->pop ());
1003 return result;
1006 static void
1007 yyerror (const char *msg)
1009 pstate->parse_error (msg);