X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fparser.mly;h=f0580443abebd4fd66c71e8ccc375453dc00c805;hb=7f776dee39a35732964a30091e55aa795169bca5;hp=add72bb74106d6553d6a55a2f075e7b80c679760;hpb=8e1d9182f7573112cb36c7d0ff0c8612f34ffd57;p=goals.git diff --git a/src/parser.mly b/src/parser.mly index add72bb..f058044 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -25,21 +25,20 @@ open Printf %token CODE %token COLON %token COMMA -%token ID %token EQUALS %token EOF %token GOAL +%token ID %token LEFT_ARRAY %token LEFT_PAREN %token LET %token RIGHT_ARRAY %token RIGHT_PAREN %token STRING - -%type stmt +%token TACTIC (* Start nonterminals. *) -%start file +%start file %start expr %% @@ -48,41 +47,45 @@ file: ; stmts: - | list(stmt) { $1 } + | list(stmt) + { List.fold_left ( + fun env (name, expr) -> Ast.Env.add name expr env + ) Ast.Env.empty $1 + } ; stmt: | option(goal_stmt) patterns COLON barelist option(CODE) { let name, params = match $1 with | None -> - let pos = $startpos in - sprintf "_goal@%d" pos.pos_lnum, [] + sprintf "_goal@%d" $startpos.pos_lnum, [] | Some x -> x in - Ast.Goal (name, params, $2, $4, $5) + name, Ast.EGoal ($loc, (params, $2, $4, $5)) } | goal_stmt CODE { let name, params = $1 in - Ast.Goal (name, params, [], [], Some $2) + name, Ast.EGoal ($loc, (params, [], [], Some $2)) } - | LET ID EQUALS expr { Ast.Let ($2, $4) } + | LET ID EQUALS expr { $2, $4 } ; goal_stmt: - | GOAL ID option(param_decl) EQUALS + | GOAL ID option(params_decl) EQUALS { $2, match $3 with None -> [] | Some ps -> ps } ; -param_decl: - | LEFT_PAREN separated_list(COMMA, ID) RIGHT_PAREN { $2 } +params_decl: + | LEFT_PAREN separated_list(COMMA, param_decl) RIGHT_PAREN { $2 } ; +param_decl: + | ID { $1 } patterns: | separated_list(COMMA, pattern) { $1 } ; pattern: - | STRING { Ast.PTactic ("file", [$1]) } - | ID pattern_params { Ast.PTactic ($1, $2) } - | ID { Ast.PVarSubst $1 } + | STRING { Ast.PTactic ($loc, "file", [$1]) } + | ID pattern_params { Ast.PTactic ($loc, $1, $2) } ; pattern_params: | LEFT_PAREN separated_list(COMMA, pattern_param) RIGHT_PAREN { $2 } @@ -92,10 +95,11 @@ pattern_param: ; expr: - | ID params { Ast.ECall ($1, $2) } - | ID { Ast.EVar $1 (* This might be replaced with ECall later. *) } - | STRING { Ast.EString $1 } - | LEFT_ARRAY barelist RIGHT_ARRAY { Ast.EList $2 } + | ID params { Ast.ECall ($loc, $1, $2) } + | ID { Ast.EVar ($loc, $1) } + | TACTIC params { Ast.ETactic ($loc, $1, $2) } + | STRING { Ast.ESubsts ($loc, $1) } + | LEFT_ARRAY barelist RIGHT_ARRAY { Ast.EList ($loc, $2) } ; barelist: | separated_list(COMMA, expr) { $1 }