Allow for attribute groups in function definitions.

master
Rohan Jacob-Rao 9 years ago
parent 8fbe358b34
commit 66aecca31f

@ -29,6 +29,9 @@ let id_special_char = ['-' '$' '.' '_']
let id_char = lower | upper | id_special_char let id_char = lower | upper | id_special_char
let id = id_char (id_char | digit)* let id = id_char (id_char | digit)*
(* definition of attribute group - not used for now *)
let attribute_junk = "attributes" [^ '\n']*
rule token = parse rule token = parse
| space | comment { token lexbuf } | space | comment { token lexbuf }
| newline { token lexbuf } | newline { token lexbuf }
@ -158,4 +161,8 @@ rule token = parse
| '%' (nonneg_int as i) { NUMBERED_LOCAL (int_of_string i) } | '%' (nonneg_int as i) { NUMBERED_LOCAL (int_of_string i) }
| id as str { IDENT str } | id as str { IDENT str }
(* attribute groups *)
| '#' (nonneg_int as i) { ATTRIBUTE_GROUP (int_of_string i) }
| attribute_junk { token lexbuf }
| eof { EOF } | eof { EOF }

@ -132,6 +132,8 @@
%token <int> NUMBERED_LOCAL %token <int> NUMBERED_LOCAL
%token <string> IDENT %token <string> IDENT
%token <int> ATTRIBUTE_GROUP
%token EOF %token EOF
%start prog %start prog
@ -146,8 +148,11 @@ prog:
| defs = list(func_def) EOF { Prog defs } | defs = list(func_def) EOF { Prog defs }
func_def: func_def:
| DEFINE ret_tp = ret_typ name = variable LPAREN params = separated_list(COMMA, pair(typ, IDENT)) RPAREN instrs = block { | DEFINE ret_tp = ret_typ name = variable LPAREN params =
FuncDef (name, ret_tp, params, instrs) } separated_list(COMMA, pair(typ, IDENT)) RPAREN list(attribute_group) instrs = block { FuncDef (name, ret_tp, params, instrs) }
attribute_group:
| i = ATTRIBUTE_GROUP { i }
ret_typ: ret_typ:
| VOID { None } | VOID { None }

Loading…
Cancel
Save