featherweight.opp.exp 7.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
File "featherweight.mly", line 47, characters 28-38:
Warning: the token APOSTROPHE is unused.
File "featherweight.mly", line 49, characters 28-33:
Warning: the token ARROW is unused.
File "featherweight.mly", line 50, characters 28-32:
Warning: the token BANG is unused.
File "featherweight.mly", line 51, characters 28-33:
Warning: the token BARGT is unused.
File "featherweight.mly", line 52, characters 28-37:
Warning: the token BARRCURLY is unused.
File "featherweight.mly", line 53, characters 28-38:
Warning: the token BARRSQUARE is unused.
File "featherweight.mly", line 55, characters 28-38:
Warning: the token COLONCOLON is unused.
File "featherweight.mly", line 56, characters 28-35:
Warning: the token COLONEQ is unused.
File "featherweight.mly", line 57, characters 28-37:
Warning: the token COLONHASH is unused.
File "featherweight.mly", line 59, characters 28-34:
Warning: the token DARROW is unused.
File "featherweight.mly", line 60, characters 28-35:
Warning: the token DDARROW is unused.
File "featherweight.mly", line 48, characters 28-34:
Warning: the token DQUOTE is unused.
File "featherweight.mly", line 62, characters 28-31:
Warning: the token EOF is unused.
File "featherweight.mly", line 64, characters 28-32:
Warning: the token EQEQ is unused.
File "featherweight.mly", line 65, characters 28-34:
Warning: the token EXISTS is unused.
File "featherweight.mly", line 42, characters 38-44:
Warning: the token FLOATV is unused.
File "featherweight.mly", line 66, characters 28-30:
Warning: the token GT is unused.
File "featherweight.mly", line 67, characters 28-32:
Warning: the token HASH is unused.
File "featherweight.mly", line 41, characters 36-40:
Warning: the token INTV is unused.
File "featherweight.mly", line 69, characters 28-37:
Warning: the token LCURLYBAR is unused.
File "featherweight.mly", line 70, characters 28-37:
Warning: the token LEFTARROW is unused.
File "featherweight.mly", line 72, characters 28-35:
Warning: the token LSQUARE is unused.
File "featherweight.mly", line 73, characters 28-38:
Warning: the token LSQUAREBAR is unused.
File "featherweight.mly", line 74, characters 28-30:
Warning: the token LT is unused.
File "featherweight.mly", line 77, characters 28-35:
Warning: the token RSQUARE is unused.
File "featherweight.mly", line 79, characters 28-33:
Warning: the token SLASH is unused.
File "featherweight.mly", line 80, characters 28-32:
Warning: the token STAR is unused.
File "featherweight.mly", line 43, characters 39-46:
Warning: the token STRINGV is unused.
File "featherweight.mly", line 81, characters 28-36:
Warning: the token TRIANGLE is unused.
File "featherweight.mly", line 82, characters 28-34:
Warning: the token USCORE is unused.
File "featherweight.mly", line 83, characters 28-32:
Warning: the token VBAR is unused.
%{
open Support.Error
open Support.Pervasive
open Syntax
%}
%start toplevel
%token <Support.Error.info> VBAR
%token <Support.Error.info> USCORE
%token <Support.Error.info> TRIANGLE
%token <Support.Error.info> THIS
%token <Support.Error.info> SUPER
%token <string Support.Error.withinfo> STRINGV
%token <Support.Error.info> STAR
%token <Support.Error.info> SLASH
%token <Support.Error.info> SEMI
%token <Support.Error.info> RSQUARE
%token <Support.Error.info> RPAREN
%token <Support.Error.info> RETURN
%token <Support.Error.info> RCURLY
%token <Support.Error.info> NEW
%token <Support.Error.info> LT
%token <Support.Error.info> LSQUAREBAR
%token <Support.Error.info> LSQUARE
%token <Support.Error.info> LPAREN
%token <Support.Error.info> LEFTARROW
%token <Support.Error.info> LCURLYBAR
%token <Support.Error.info> LCURLY
%token <int Support.Error.withinfo> INTV
%token <string Support.Error.withinfo> ID
%token <Support.Error.info> HASH
%token <Support.Error.info> GT
%token <float Support.Error.withinfo> FLOATV
%token <Support.Error.info> EXTENDS
%token <Support.Error.info> EXISTS
%token <Support.Error.info> EQEQ
%token <Support.Error.info> EQ
%token <Support.Error.info> EOF
%token <Support.Error.info> DQUOTE
%token <Support.Error.info> DOT
%token <Support.Error.info> DDARROW
%token <Support.Error.info> DARROW
%token <Support.Error.info> COMMAND
%token <Support.Error.info> COMMA
%token <Support.Error.info> COLONHASH
%token <Support.Error.info> COLONEQ
%token <Support.Error.info> COLONCOLON
%token <Support.Error.info> COLON
%token <Support.Error.info> CLASS
%token <Support.Error.info> BARRSQUARE
%token <Support.Error.info> BARRCURLY
%token <Support.Error.info> BARGT
%token <Support.Error.info> BANG
%token <Support.Error.info> ARROW
%token <Support.Error.info> APOSTROPHE

%type < Syntax.program > toplevel
%%

toplevel:
| classDecs COLON termDef
    { Program($1,$3) }

classDecs:
| COMMAND
    { [] }
| classDec classDecs
    {  let decl = $1 in
          let decls = $2 in
	      decl::decls }

classDec:
| CLASS ID EXTENDS ID LCURLY fieldDefs constructorDef methodDefs RCURLY
    { Class (Name($2.v), SuperName($4.v), $6, $7, $8) }
| CLASS ID EXTENDS ID LCURLY fieldDefs constructorDef RCURLY
    { Class (Name($2.v), SuperName($4.v), $6, $7, []) }
| CLASS ID EXTENDS ID LCURLY constructorDef methodDefs RCURLY
    { Class (Name($2.v), SuperName($4.v), [], $6, $7) }
| CLASS ID EXTENDS ID LCURLY constructorDef RCURLY
    { Class (Name($2.v), SuperName($4.v), [], $6, []) }

fieldDefs:
| SEMI
    { [] }
| fieldDef SEMI fieldDefs
    { let fDef = $1 in
		  let fDefs = $3 in
		  fDef::fDefs }

fieldDef:
| ID ID
    { Field(Type($1.v), Name($2.v)) }

constructorDef:
| ID LPAREN paramDefs RPAREN LCURLY SUPER LPAREN argDefs RPAREN SEMI fieldAssignmentDefs RCURLY
    { Constructor(Name($1.v), $3, SuperConstructorCall($8), $11) }

paramDefs:
| 
    { [] }
| paramDef
    { let pDef = $1 in
          let pDefs = [] in
          pDef::pDefs }
| paramDef COMMA paramDefs
    { let pDef = $1 in
          let pDefs = $3 in
          pDef::pDefs }

paramDef:
| ID ID
    { Param (Type($1.v), Name($2.v)) }

argDefs:
| 
    {	[] }
| argDef
    {	let aDef = $1 in
	  let aDefs = [] in
	  aDef::aDefs }
| argDef COMMA argDefs
    {	let aDef = $1 in
	  let aDefs = $3 in
	  aDef::aDefs }

argDef:
| ID
    { Arg($1.v) }

fieldAssignmentDefs:
| 
    { [] }
| fieldAssignmentDef fieldAssignmentDefs
    { let faDef = $1 in
          let faDefs = $2 in
	  faDef::faDefs }

fieldAssignmentDef:
| THIS DOT ID EQ ID SEMI
    { FieldAssignment (Name($3.v), Value($5.v)) }

methodDefs:
| SEMI
    { [] }
| methodDef methodDefs
    { let mDef = $1 in
          let mDefs = $2 in
	      mDef::mDefs }

methodDef:
| ID ID LPAREN paramDefs RPAREN LCURLY RETURN termDef SEMI RCURLY
    { Method(ReturnType($1.v),Name($2.v),$4,$8) }

termDef:
| TmVarDef
    { $1 }
| TmFieldAccessDef
    { $1 }
| TmMethodInvocationDef
    { $1 }
| TmObjectCreationDef
    { $1 }
| TmCastDef
    { $1 }
| TmThis
    { $1 }
| LPAREN TmFieldAccessDef RPAREN
    { $2 }
| LPAREN TmMethodInvocationDef RPAREN
    { $2 }
| LPAREN TmObjectCreationDef RPAREN
    { $2 }
| LPAREN TmCastDef RPAREN
    { $2 }

TmThis:
| THIS
    { TmVar("this") }

TmVarDef:
| ID
    { TmVar($1.v) }

TmFieldAccessDef:
| termDef DOT ID
    { TmFieldAccess($1,$3.v) }

TmMethodInvocationDef:
| termDef DOT ID LPAREN termDefs RPAREN
    { TmMethodInvocation($1,$3.v,$5) }

TmObjectCreationDef:
| NEW ID LPAREN termDefs RPAREN
    { TmObjectCreation($2.v,$4) }

TmCastDef:
| LPAREN ID RPAREN termDef
    { TmCast($2.v,$4) }

termDefs:
| 
    { [] }
| termDef
    { let tDef = $1 in
          let tDefs = [] in
          tDef::tDefs }
| termDef COMMA termDefs
    { let tDef = $1 in
          let tDefs = $3 in
          tDef::tDefs }

%%