* Rename remote-es1800.c to remote-es.c
[deliverable/binutils-gdb.git] / gdb / ch-exp.y
index 0a2efd15e5bf47d417e95aba0c6d0d9bbd3644ff..b35fe87e3aa02a4edd24c46caba633f4811d2e77 100644 (file)
@@ -1,5 +1,5 @@
 /* YACC grammar for Chill expressions, for GDB.
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright 1992, 1993 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -162,7 +162,6 @@ yyerror PARAMS ((char *));
 %token <voidval> FIXME_20
 %token <voidval> FIXME_21
 %token <voidval> FIXME_22
-%token <voidval> FIXME_23
 %token <voidval> FIXME_24
 %token <voidval> FIXME_25
 %token <voidval> FIXME_26
@@ -181,6 +180,8 @@ yyerror PARAMS ((char *));
 %token <voidval>       EMPTINESS_LITERAL
 %token <sval>          CHARACTER_STRING_LITERAL
 %token <sval>          BIT_STRING_LITERAL
+%token <tsym>          TYPENAME
+%token <sval>          FIELD_NAME
 
 %token <voidval>       '.'
 %token <voidval>       ';'
@@ -226,8 +227,8 @@ yyerror PARAMS ((char *));
 %token <voidval>       SUCC
 %token <voidval>       ABS
 %token <voidval>       CARD
-%token <voidval>       MAX
-%token <voidval>       MIN
+%token <voidval>       MAX_TOKEN
+%token <voidval>       MIN_TOKEN
 %token <voidval>       SIZE
 %token <voidval>       UPPER
 %token <voidval>       LOWER
@@ -290,12 +291,9 @@ yyerror PARAMS ((char *));
 %type <voidval>                lower_element
 %type <voidval>                upper_element
 %type <voidval>                first_element
-%type <voidval>                structure_primitive_value
-%type <voidval>                field_name
 %type <voidval>                mode_argument
 %type <voidval>                upper_lower_argument
 %type <voidval>                length_argument
-%type <voidval>                mode_name
 %type <voidval>                array_mode_name
 %type <voidval>                string_mode_name
 %type <voidval>                variant_structure_mode_name
@@ -304,13 +302,20 @@ yyerror PARAMS ((char *));
 %type <voidval>                subexpression
 %type <voidval>                case_label_specification
 %type <voidval>                buffer_location
-
 %type <voidval>                single_assignment_action
+%type <tsym>           mode_name
 
 %%
 
 /* Z.200, 5.3.1 */
 
+start  :       value { }
+       |       mode_name
+                       { write_exp_elt_opcode(OP_TYPE);
+                         write_exp_elt_type($1.type);
+                         write_exp_elt_opcode(OP_TYPE);}
+       ;
+
 value          :       expression
                        {
                          $$ = 0;       /* FIXME */
@@ -330,12 +335,9 @@ undefined_value    :       FIXME_01
 /* Z.200, 4.2.1 */
 
 location       :       access_name
+               |       primitive_value POINTER
                        {
-                         $$ = 0;       /* FIXME */
-                       }
-               |       FIXME_02
-                       {
-                         $$ = 0;       /* FIXME */
+                         write_exp_elt_opcode (UNOP_IND);
                        }
                ;
 
@@ -588,9 +590,10 @@ value_array_slice: array_primitive_value '(' lower_element ':' upper_element ')'
 
 /* Z.200, 5.2.10 */
 
-value_structure_field: structure_primitive_value '.' field_name
-                       {
-                         $$ = 0;       /* FIXME */
+value_structure_field: primitive_value FIELD_NAME
+                       { write_exp_elt_opcode (STRUCTOP_STRUCT);
+                         write_exp_string ($2);
+                         write_exp_elt_opcode (STRUCTOP_STRUCT);
                        }
                ;
 
@@ -598,7 +601,9 @@ value_structure_field:      structure_primitive_value '.' field_name
 
 expression_conversion: mode_name parenthesised_expression
                        {
-                         $$ = 0;       /* FIXME */
+                         write_exp_elt_opcode (UNOP_CAST);
+                         write_exp_elt_type ($1.type);
+                         write_exp_elt_opcode (UNOP_CAST);
                        }
                ;
 
@@ -648,6 +653,10 @@ expression :       operand_0
                        {
                          $$ = 0;       /* FIXME */
                        }
+               |       single_assignment_action
+                       {
+                         $$ = 0;       /* FIXME */
+                       }
                |       conditional_expression
                        {
                          $$ = 0;       /* FIXME */
@@ -710,10 +719,6 @@ operand_0  :       operand_1
                        {
                          write_exp_elt_opcode (BINOP_BITWISE_XOR);
                        }
-               |       single_assignment_action
-                       {
-                         $$ = 0;       /* FIXME */
-                       }
                ;
 
 /* Z.200, 5.3.4 */
@@ -814,8 +819,6 @@ operand_4   :       operand_5
                ;
 
 /* Z.200, 5.3.8 */
-/* Note that we accept any expression for BINOP_CONCAT, not just
-   integer literal expressions. (FIXME?) */
 
 operand_5      :       operand_6
                        {
@@ -829,7 +832,9 @@ operand_5   :       operand_6
                        {
                          write_exp_elt_opcode (UNOP_LOGICAL_NOT);
                        }
-               |       parenthesised_expression operand_6
+               |       parenthesised_expression literal
+/* We require the string operand to be a literal, to avoid some
+   nasty parsing ambiguities. */
                        {
                          write_exp_elt_opcode (BINOP_CONCAT);
                        }
@@ -839,7 +844,7 @@ operand_5   :       operand_6
 
 operand_6      :       POINTER location
                        {
-                         $$ = 0;       /* FIXME */
+                         write_exp_elt_opcode (UNOP_ADDR);
                        }
                |       RECEIVE buffer_location
                        {
@@ -884,11 +889,11 @@ chill_value_built_in_routine_call :
                        {
                          $$ = 0;       /* FIXME */
                        }
-               |       MAX '(' expression ')'
+               |       MAX_TOKEN '(' expression ')'
                        {
                          $$ = 0;       /* FIXME */
                        }
-               |       MIN '(' expression ')'
+               |       MIN_TOKEN '(' expression ')'
                        {
                          $$ = 0;       /* FIXME */
                        }
@@ -932,11 +937,10 @@ mode_argument :           mode_name
                        }
                ;
 
-upper_lower_argument : location
-                       {
-                         $$ = 0;       /* FIXME */
-                       }
-               |       expression
+mode_name :            TYPENAME
+               ;
+
+upper_lower_argument : expression
                        {
                          $$ = 0;       /* FIXME */
                        }
@@ -946,11 +950,7 @@ upper_lower_argument :     location
                        }
                ;
 
-length_argument :      location
-                       {
-                         $$ = 0;       /* FIXME */
-                       }
-               |       expression
+length_argument :      expression
                        {
                          $$ = 0;       /* FIXME */
                        }
@@ -982,9 +982,6 @@ slice_size          :       FIXME_19 { $$ = 0; }
 lower_element          :       FIXME_20 { $$ = 0; }
 upper_element          :       FIXME_21 { $$ = 0; }
 first_element          :       FIXME_22 { $$ = 0; }
-structure_primitive_value:     FIXME_23 { $$ = 0; }
-field_name             :       FIXME_24 { $$ = 0; }
-mode_name              :       FIXME_25 { $$ = 0; }
 boolean_expression     :       FIXME_26 { $$ = 0; }
 case_selector_list     :       FIXME_27 { $$ = 0; }
 subexpression          :       FIXME_28 { $$ = 0; }
@@ -1043,13 +1040,18 @@ match_simple_name_string ()
 
   if (isalpha (*tokptr))
     {
+      char *result;
       do {
        tokptr++;
-      } while (isalpha (*tokptr) || isdigit (*tokptr) || (*tokptr == '_'));
+      } while (isalnum (*tokptr) || (*tokptr == '_'));
       yylval.sval.ptr = lexptr;
       yylval.sval.length = tokptr - lexptr;
       lexptr = tokptr;
-      return (copy_name (yylval.sval));
+      result = copy_name (yylval.sval);
+      for (tokptr = result; *tokptr; tokptr++)
+       if (isupper (*tokptr))
+         *tokptr = tolower(*tokptr);
+      return result;
     }
   return (NULL);
 }
@@ -1724,49 +1726,38 @@ struct token
   int token;
 };
 
-static const struct token tokentab6[] =
+static const struct token idtokentab[] =
 {
-    { "LENGTH", LENGTH }
-};
-
-static const struct token tokentab5[] =
-{
-    { "LOWER", LOWER },
-    { "UPPER", UPPER },
-    { "ANDIF", ANDIF }
-};
-
-static const struct token tokentab4[] =
-{
-    { "PRED", PRED },
-    { "SUCC", SUCC },
-    { "CARD", CARD },
-    { "SIZE", SIZE },
-    { "ORIF", ORIF }
-};
-
-static const struct token tokentab3[] =
-{
-    { "NUM", NUM },
-    { "ABS", ABS },
-    { "MAX", MAX },
-    { "MIN", MIN },
-    { "MOD", MOD },
-    { "REM", REM },
-    { "NOT", NOT },
-    { "XOR", LOGXOR },
-    { "AND", LOGAND }
+    { "length", LENGTH },
+    { "lower", LOWER },
+    { "upper", UPPER },
+    { "andif", ANDIF },
+    { "pred", PRED },
+    { "succ", SUCC },
+    { "card", CARD },
+    { "size", SIZE },
+    { "orif", ORIF },
+    { "num", NUM },
+    { "abs", ABS },
+    { "max", MAX_TOKEN },
+    { "min", MIN_TOKEN },
+    { "mod", MOD },
+    { "rem", REM },
+    { "not", NOT },
+    { "xor", LOGXOR },
+    { "and", LOGAND },
+    { "in", IN },
+    { "or", LOGIOR }
 };
 
 static const struct token tokentab2[] =
 {
     { ":=", GDB_ASSIGNMENT },
     { "//", SLASH_SLASH },
+    { "->", POINTER },
     { "/=", NOTEQUAL },
     { "<=", LEQ },
-    { ">=", GTR },
-    { "IN", IN },
-    { "OR", LOGIOR }
+    { ">=", GTR }
 };
 
 /* Read one token, getting characters through lexptr.  */
@@ -1797,7 +1788,6 @@ yylex ()
            case ';':
            case '!':
            case '+':
-           case '-':
            case '*':
            case '(':
            case ')':
@@ -1846,42 +1836,6 @@ yylex ()
            }
          break;
       }
-    /* See if it is a special token of length 6.  */
-    for (i = 0; i < sizeof (tokentab6) / sizeof (tokentab6[0]); i++)
-       {
-           if (STREQN (lexptr, tokentab6[i].operator, 6))
-               {
-                   lexptr += 6;
-                   return (tokentab6[i].token);
-               }
-       }
-    /* See if it is a special token of length 5.  */
-    for (i = 0; i < sizeof (tokentab5) / sizeof (tokentab5[0]); i++)
-       {
-           if (STREQN (lexptr, tokentab5[i].operator, 5))
-               {
-                   lexptr += 5;
-                   return (tokentab5[i].token);
-               }
-       }
-    /* See if it is a special token of length 4.  */
-    for (i = 0; i < sizeof (tokentab4) / sizeof (tokentab4[0]); i++)
-       {
-           if (STREQN (lexptr, tokentab4[i].operator, 4))
-               {
-                   lexptr += 4;
-                   return (tokentab4[i].token);
-               }
-       }
-    /* See if it is a special token of length 3.  */
-    for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
-       {
-           if (STREQN (lexptr, tokentab3[i].operator, 3))
-               {
-                   lexptr += 3;
-                   return (tokentab3[i].token);
-               }
-       }
     /* See if it is a special token of length 2.  */
     for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
        {
@@ -1896,25 +1850,13 @@ yylex ()
        would already have found it. */
     switch (*lexptr)
        {
+           case '-':
            case ':':
            case '/':
            case '<':
            case '>':
                return (*lexptr++);
        }
-    /* Look for other special tokens. */
-    if (STREQN (lexptr, "TRUE", 4)) /* FIXME:  What about lowercase? */
-       {
-           yylval.ulval = 1;
-           lexptr += 4;
-           return (BOOLEAN_LITERAL);
-       }
-    if (STREQN (lexptr, "FALSE", 5)) /* FIXME:  What about lowercase? */
-       {
-           yylval.ulval = 0;
-           lexptr += 5;
-           return (BOOLEAN_LITERAL);
-       }
     /* Look for a float literal before looking for an integer literal, so
        we match as much of the input stream as possible. */
     token = match_float_literal ();
@@ -1940,8 +1882,30 @@ yylex ()
        we can't classify what sort of name it is. */
 
     simplename = match_simple_name_string ();
+
     if (simplename != NULL)
       {
+       /* See if it is a reserved identifier. */
+       for (i = 0; i < sizeof (idtokentab) / sizeof (idtokentab[0]); i++)
+           {
+               if (STREQ (simplename, idtokentab[i].operator))
+                   {
+                       return (idtokentab[i].token);
+                   }
+           }
+
+       /* Look for other special tokens. */
+       if (STREQ (simplename, "true"))
+           {
+               yylval.ulval = 1;
+               return (BOOLEAN_LITERAL);
+           }
+       if (STREQ (simplename, "false"))
+           {
+               yylval.ulval = 0;
+               return (BOOLEAN_LITERAL);
+           }
+
        sym = lookup_symbol (simplename, expression_context_block,
                             VAR_NAMESPACE, (int *) NULL,
                             (struct symtab **) NULL);
@@ -1976,8 +1940,10 @@ yylex ()
              case LOC_LABEL:
                return (LOCATION_NAME);
                break;
-             case LOC_UNDEF:
              case LOC_TYPEDEF:
+               yylval.tsym.type = SYMBOL_TYPE (sym);
+               return TYPENAME;
+             case LOC_UNDEF:
              case LOC_CONST_BYTES:
              case LOC_OPTIMIZED_OUT:
                error ("Symbol \"%s\" names no location.", simplename);
@@ -2000,7 +1966,12 @@ yylex ()
     switch (*lexptr)
       {
        case '.':                       /* Not float for example. */
-         return (*lexptr++);
+         lexptr++;
+         while (isspace (*lexptr)) lexptr++;
+         simplename = match_simple_name_string ();
+         if (!simplename)
+           return '.';
+         return FIELD_NAME;
       }
 
     return (ILLEGAL_TOKEN);
This page took 0.027902 seconds and 4 git commands to generate.