def read_declarator(rname, basety, params, ctx)
      if next_token?('(')
        # '(' is either beginning of grouping parentheses or of a function parameter list.
        # If the next token is a type name, a parameter list must follow.
        if is_type?(peek)
          return read_declarator_func(basety, params)
        end

        # If not, it's grouping. In that case we have to read from outside.
        # For example, consider int (*)(), which is "pointer to function returning int".
        # We have only read "int" so far. We don't want to pass "int" to
        # a recursive call, or otherwise we would get "pointer to int".
        # Here, we pass a dummy object to get "pointer to <something>" first,
        # continue reading to get "function returning int", and then combine them.
        stub = Type.make_stub_type
        t = read_declarator(rname, stub, params, ctx)
        expect!(')')
        stub.replace_by!(read_declarator_tail(basety, params))
        return t
      end

      if next_token?('*')
        skip_type_qualifiers!
        return read_declarator(rname, Type.make_ptr_type(basety), params, ctx)
      end

      tok = get
      if tok.kind == T::IDENT
        if ctx == DECL::CAST
          Util.errort!(tok, "identifier is not expected, but got #{tok}")
        end
        rname << tok.sval  # Write as return value
        return read_declarator_tail(basety, params)
      end

      if [DECL::BODY, DECL::PARAM].include?(ctx)
        Util.errort!(tok, "identifier, ( or * are expected, but got #{tok}")
      end
      @lexer.unget_token(tok)
      read_declarator_tail(basety, params)
    end
def read_declarator(rname, basety, params, ctx)
      if next_token?('(')
        # '(' is either beginning of grouping parentheses or of a function parameter list.
        # If the next token is a type name, a parameter list must follow.
        if is_type?(peek)
          return read_declarator_func(basety, params)
        end

        # If not, it's grouping. In that case we have to read from outside.
        # For example, consider int (*)(), which is "pointer to function returning int".
        # We have only read "int" so far. We don't want to pass "int" to
        # a recursive call, or otherwise we would get "pointer to int".
        # Here, we pass a dummy object to get "pointer to <something>" first,
        # continue reading to get "function returning int", and then combine them.
        stub = Type.make_stub_type
        t = read_declarator(rname, stub, params, ctx)
        expect!(')')
        stub.replace_by!(read_declarator_tail(basety, params))
        return t
      end

      if next_token?('*')
        skip_type_qualifiers!
        return read_declarator(rname, Type.make_ptr_type(basety), params, ctx)
      end

      tok = get
      if tok.kind == T::IDENT
        if ctx == DECL::CAST
          Util.errort!(tok, "identifier is not expected, but got #{tok}")
        end
        rname << tok.sval  # Write as return value
        return read_declarator_tail(basety, params)
      end

      if [DECL::BODY, DECL::PARAM].include?(ctx)
        Util.errort!(tok, "identifier, ( or * are expected, but got #{tok}")
      end
      @lexer.unget_token(tok)
      read_declarator_tail(basety, params)
    end
Declarator

 C's syntax for declaration is not only hard to read for humans but also
 hard to parse for hand-written parsers. Consider the following two cases:

   A: int *x;
   B: int *x();

 A is of type pointer to int, but B is not a pointer type, B is type of
 function returning a pointer to an integer. The meaning of the first half
 of the declaration ("int *" part) is different between them.

 In 8cc, delcarations are parsed by two functions: read_declarator
 and read_declarator_tail. The former function parses the first half of a
 declaration, and the latter parses the (possibly nonexistent) parentheses
 of a function or an array.

 C11 6.7.6: Declarators
 TODO(south37) Use return value for rname, params
 @param(return) [String] rname used as return value
 @param [Type] basety
 @param(return) [Array] params
 @param [DECL] ctx
 @return [Type]