예제 #1
0
// Parse a postfix type.
//
//    postfix-type -> primary_type
//                    postfix-type '[]'
//                  | postfix-type '[' expr ']'
//
// TODO: Allow prefix type expressions. These should
// bind more tightly than postfix type expressoins.
//
// TODO: Suffix notation will require parens for grouping.
// For example, a reference to an array would be:
//
//    ref (T[N])
//
// We would need to handle function types carefully.
Type const*
Parser::postfix_type()
{
  Type const* t = primary_type();
  while (true) {
    // Match array types.
    if (match_if(lbrack_tok)) {
      if (match_if(rbrack_tok))
        return on_block_type(t);
      Expr* e = expr();
      match(rbrack_tok);
      t = on_array_type(t, e);
    }

    // No postfix operators
    else
      break;
  }
  return t;
}
예제 #2
0
파일: parser.cpp 프로젝트: cjb129/beekar
// Parse a postfix type.
//
//    postfix-type -> primary_type
//                    postfix-type '&'
//                    postfix-type '[]'
//                  | postfix-type '[' expr ']'
//
// TODO: Allow prefix type expressions. These should
// bind more tightly than postfix type expressoins.
//
// TODO: Suffix notation will require parens for grouping.
// For example, a reference to an array would be:
//
//    ref (T[N])
//
// We would need to handle function types carefully.
Type const*
Parser::postfix_type()
{
  Type const* t = primary_type();
  while (true) {
    // reference-type
    if (match_if(amp_tok))
      t = on_reference_type(t);

    // array-types
    else if (match_if(lbrack_tok)) {
      if (match_if(rbrack_tok))
        return on_block_type(t);
      Expr* e = expr();
      match(rbrack_tok);
      t = on_array_type(t, e);
    }

    // No postfix operators
    else
      break;
  }
  return t;
}