My working unpac repository
at opam/upstream/seq 269 lines 7.2 kB view raw
1/**************************************************************************/ 2/* */ 3/* OCaml */ 4/* */ 5/* Jerome Vouillon, projet Cristal, INRIA Rocquencourt */ 6/* OCaml port by John Malecki and Xavier Leroy */ 7/* */ 8/* Copyright 1996 Institut National de Recherche en Informatique et */ 9/* en Automatique. */ 10/* */ 11/* All rights reserved. This file is distributed under the terms of */ 12/* the GNU Lesser General Public License version 2.1, with the */ 13/* special exception on linking described in the file LICENSE. */ 14/* */ 15/**************************************************************************/ 16 17%{ 18 19open Int64ops 20open Input_handling 21open Longident 22open Parser_aux 23open Debugcom 24 25%} 26 27%token <string> ARGUMENT 28%token <string> LIDENT 29%token <string> UIDENT 30%token <string> OPERATOR 31%token <int64> INTEGER 32%token STAR /* * */ 33%token MINUS /* - */ 34%token DOT /* . */ 35%token COLON /* : */ 36%token HASH /* # */ 37%token AT /* @ */ 38%token DOLLAR /* $ */ 39%token BANG /* ! */ 40%token LPAREN /* ( */ 41%token RPAREN /* ) */ 42%token LBRACKET /* [ */ 43%token RBRACKET /* ] */ 44%token EOL 45 46%right DOT 47%right BANG 48 49%start argument_list_eol 50%type <string list> argument_list_eol 51 52%start argument_eol 53%type <string> argument_eol 54 55%start integer_list_eol 56%type <int list> integer_list_eol 57 58%start integer_eol 59%type <int> integer_eol 60 61%start int64_eol 62%type <int64> int64_eol 63 64%start integer 65%type <int> integer 66 67%start opt_integer_eol 68%type <int option> opt_integer_eol 69 70%start opt_signed_integer_eol 71%type <int option> opt_signed_integer_eol 72 73%start opt_signed_int64_eol 74%type <int64 option> opt_signed_int64_eol 75 76%start identifier 77%type <string> identifier 78 79%start identifier_eol 80%type <string> identifier_eol 81 82%start identifier_or_eol 83%type <string option> identifier_or_eol 84 85%start opt_identifier 86%type <string option> opt_identifier 87 88%start opt_identifier_eol 89%type <string option> opt_identifier_eol 90 91%start expression_list_eol 92%type <Parser_aux.expression list> expression_list_eol 93 94%start break_argument_eol 95%type <Parser_aux.break_arg> break_argument_eol 96 97%start list_arguments_eol 98%type <Longident.t option * int option * int option> list_arguments_eol 99 100%start end_of_line 101%type <unit> end_of_line 102 103%start longident_eol 104%type <Longident.t> longident_eol 105 106%start opt_longident 107%type <Longident.t option> opt_longident 108 109%start opt_longident_eol 110%type <Longident.t option> opt_longident_eol 111 112%% 113 114/* Raw arguments */ 115 116argument_list_eol : 117 ARGUMENT argument_list_eol 118 { $1::$2 } 119 | end_of_line 120 { [] }; 121 122argument_eol : 123 ARGUMENT end_of_line 124 { $1 }; 125 126/* Integer */ 127 128integer_list_eol : 129 INTEGER integer_list_eol 130 { (to_int $1) :: $2 } 131 | end_of_line 132 { [] }; 133 134integer_eol : 135 INTEGER end_of_line 136 { to_int $1 }; 137 138int64_eol : 139 INTEGER end_of_line 140 { $1 }; 141 142integer : 143 INTEGER 144 { to_int $1 }; 145 146opt_integer_eol : 147 INTEGER end_of_line 148 { Some (to_int $1) } 149 | end_of_line 150 { None }; 151 152opt_int64_eol : 153 INTEGER end_of_line 154 { Some $1 } 155 | end_of_line 156 { None }; 157 158opt_signed_integer_eol : 159 MINUS integer_eol 160 { Some (- $2) } 161 | opt_integer_eol 162 { $1 }; 163 164opt_signed_int64_eol : 165 MINUS int64_eol 166 { Some (Int64.neg $2) } 167 | opt_int64_eol 168 { $1 }; 169 170/* Identifiers and long identifiers */ 171 172longident : 173 LIDENT 174 { Lident $1 } 175 | module_path DOT LIDENT 176 { Ldot(Location.mknoloc $1, Location.mknoloc $3) } 177 | OPERATOR 178 { Lident $1 } 179 | module_path DOT OPERATOR 180 { Ldot(Location.mknoloc $1, Location.mknoloc $3) } 181 | module_path DOT LPAREN OPERATOR RPAREN 182 { Ldot(Location.mknoloc $1, Location.mknoloc $4) } 183; 184 185module_path : 186 UIDENT 187 { Lident $1 } 188 | module_path DOT UIDENT 189 { Ldot(Location.mknoloc $1, Location.mknoloc $3) } 190; 191 192longident_eol : 193 longident end_of_line { $1 }; 194 195opt_longident : 196 UIDENT { Some (Lident $1) } 197 | LIDENT { Some (Lident $1) } 198 | module_path DOT UIDENT { Some (Ldot(Location.mknoloc $1, 199 Location.mknoloc $3)) } 200 | { None }; 201 202opt_longident_eol : 203 opt_longident end_of_line { $1 }; 204 205identifier : 206 LIDENT { $1 } 207 | UIDENT { $1 }; 208 209identifier_eol : 210 identifier end_of_line { $1 }; 211 212identifier_or_eol : 213 identifier { Some $1 } 214 | end_of_line { None }; 215 216opt_identifier : 217 identifier { Some $1 } 218 | { None }; 219 220opt_identifier_eol : 221 opt_identifier end_of_line { $1 }; 222 223/* Expressions */ 224 225expression: 226 longident { E_ident $1 } 227 | STAR { E_result } 228 | DOLLAR INTEGER { E_name (to_int $2) } 229 | expression DOT INTEGER { E_item($1, (to_int $3)) } 230 | expression DOT LBRACKET INTEGER RBRACKET { E_item($1, (to_int $4)) } 231 | expression DOT LPAREN INTEGER RPAREN { E_item($1, (to_int $4)) } 232 | expression DOT LIDENT { E_field($1, $3) } 233 | BANG expression { E_field($2, "contents") } 234 | LPAREN expression RPAREN { $2 } 235; 236 237/* Lists of expressions */ 238 239expression_list_eol : 240 expression expression_list_eol { $1::$2 } 241 | end_of_line { [] } 242; 243 244/* Arguments for breakpoint */ 245 246break_argument_eol : 247 end_of_line { BA_none } 248 | integer_eol { BA_pc {frag = main_frag; 249 pos = $1} } 250 | INTEGER COLON integer_eol { BA_pc {frag = to_int $1; 251 pos = $3} } 252 | expression end_of_line { BA_function $1 } 253 | AT opt_longident INTEGER opt_integer_eol { BA_pos1 ($2, (to_int $3), $4)} 254 | AT opt_longident HASH integer_eol { BA_pos2 ($2, $4) } 255; 256 257/* Arguments for list */ 258 259list_arguments_eol : 260 opt_longident integer opt_integer_eol 261 { ($1, Some $2, $3) } 262 | opt_longident_eol 263 { ($1, None, None) }; 264 265/* End of line */ 266 267end_of_line : 268 EOL { stop_user_input () } 269;