Beispiel #1
0
// Parse a function declarator.
// fn-decl ::= n(p1, p2, ...) -> t
Tree*
parse_fn_decl(Parser& p, Tree* n) {
  if (Tree_seq* ps = parse_parm_clause(p))    
  //parsing parameter list as Lambda abstraction \(pi:Ti).e
  if (Tree* t = parse_return_type(p))
     return new Func_tree(n, ps, t);
  return nullptr;
}
Beispiel #2
0
// Parse a lambda abstraction.
//
//    lambda-expr ::= '\' parm-decl ':' type '=>' term
//                  | '\' parm-list '=>' term
Tree*
parse_lambda_expr(Parser& p) {
  if (const Token* k = parse::accept(p, backslash_tok)) {
    if(Tree* v = parse_parm_decl(p)) {
      if (parse::expect(p, map_tok)) {
        if (Tree* t = parse_expr(p))
          return new Abs_tree(k, v, t);
        else
          parse::parse_error(p) << "expected 'expr' after '.'";
      }
    } else if (Tree_seq* ps = parse_parm_clause(p)) {
      if (parse::expect(p, map_tok)) {
        if (Tree* t = parse_expr(p))
          return new Fn_tree(k, ps, t);
        else
          parse::parse_error(p) << "expected 'expr' after '.'";
      }
    } else {
      parse::parse_error(p) << "expected 'var-decl' or 'parm-clause' after '\\'";
    }
  }
  return nullptr;
}