Exemplo n.º 1
0
// A member is a declaration within a class.
//
//    member-statement:
//      member-declaration
//
//    member-declaration:
//      variable-declaration
//      super-declaration
//      function-declaration
//      class-declaration
//      template-declaration
//
// TODO: Allow other kinds of statements to support metaprogramming.
Stmt&
Parser::member_statement()
{
  switch (lookahead()) {
    // Declaration specifiers.
    case tk::virtual_tok:
    case tk::abstract_tok:
    case tk::static_tok:
    case tk::inline_tok:
    case tk::explicit_tok:
    case tk::implicit_tok:
    case tk::public_tok:
    case tk::private_tok:
    case tk::protected_tok:
    // Declaration introducers.
    case tk::var_tok:
    case tk::super_tok:
    case tk::def_tok:
    case tk::class_tok:
    case tk::template_tok:
      return declaration_statement();
    
    default:
      error("expected member-statement");
      throw Syntax_error();
  }
}
Exemplo n.º 2
0
// Parse a statement.
//
//    statement:
//      compound-statement
//      return-statement
//      ...
//      declaration-statement
Stmt&
Parser::statement()
{
  switch (lookahead()) {
    case lbrace_tok:
      return compound_statement();
    case return_tok:
      return return_statement();

    case var_tok:
    case def_tok:
    case struct_tok:
    case class_tok:
    case enum_tok:
    case namespace_tok:
    case template_tok:
      return declaration_statement();

    default:
      return expression_statement();
  }
}