Commit e86860ad authored by Pierre Brandone's avatar Pierre Brandone
Browse files

Syntactic specifications: separate object-related grammar

.../syntactic_specifications/object_syntax: Create,
.../syntactic_specifications/syntactic_specifications.rst,
.../syntactic_specifications/syntax: Here.
parent 9f5874d3
Pipeline #32698 passed with stage
in 1 minute
exp =
(* Object creation. *)
"new" type-id
(* Method call. *)
| lvalue "." id "(" [ exp { "," exp }] ")"
;
dec =
(* Class definition (alternative form). *)
"class" id [ "extends" type-id ] "{" classfields "}"
;
ty =
(* Class definition (canonical form). *)
"class" [ "extends" type-id ] "{" classfields "}"
;
classfields = { classfield } ;
(* Class fields. *)
classfield =
(* Attribute declaration. *)
vardec
(* Method declaration. *)
| "method" id "(" tyfields ")" [ ":" type-id ] "=" exp
;
......@@ -40,3 +40,9 @@ associative. All the remaining operators are left-associative.
| "(" exps ")"
(* Next rules ... *)
Tiger's object-oriented syntax implies additional rules as described below.
.. literalinclude:: object_syntax
:language: ebnf
......@@ -14,18 +14,12 @@ exp =
| type-id "[" exp "]" "of" exp
| type-id "{" [ id "=" exp { "," id "=" exp } ] "}"
(* Object creation. *)
| "new" type-id
(* Variables, field, elements of an array. *)
| lvalue
(* Function call. *)
| id "(" [ exp { "," exp }] ")"
(* Method call. *)
| lvalue "." id "(" [ exp { "," exp }] ")"
(* Operations. *)
| "-" exp
| exp op exp
......@@ -54,8 +48,6 @@ decs = { dec } ;
dec =
(* Type declaration. *)
"type" id "=" ty
(* Class definition (alternative form). *)
| "class" id [ "extends" type-id ] "{" classfields "}"
(* Variable declaration. *)
| vardec
(* Function declaration. *)
......@@ -70,16 +62,6 @@ dec =
vardec = "var" id [ ":" type-id ] ":=" exp ;
classfields = { classfield } ;
(* Class fields. *)
classfield =
(* Attribute declaration. *)
vardec
(* Method declaration. *)
| "method" id "(" tyfields ")" [ ":" type-id ] "=" exp
;
(* Types. *)
ty =
(* Type alias. *)
......@@ -88,8 +70,6 @@ ty =
| "{" tyfields "}"
(* Array type definition. *)
| "array" "of" type-id
(* Class definition (canonical form). *)
| "class" [ "extends" type-id ] "{" classfields "}"
;
tyfields = [ id ":" type-id { "," id ":" type-id } ] ;
type-id = id ;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment