-
Notifications
You must be signed in to change notification settings - Fork 92
ANTLR-isation of parse/syntactic grammar #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
99abf1e
82fecf6
dcfbfb5
aeee09a
3e0ecf6
87af7ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1130,6 +1130,8 @@ primary_no_array_creation_expression | |
; | ||
``` | ||
|
||
> *Note*: These grammar rules are not ANTLR-ready as they are part of a set of mutually left-recursive rules (`primary_expression`, `primary_no_array_creation_expression`, `member_access`, `invocation_expression`, `element_access`, `post_increment_expression`, `post_decrement_expression`, `pointer_member_access` and `pointer_element_access`) which ANTLR does not handle. Standard techniques can be used to transform the grammar to remove the mutual left-recursion. This has not been done as not all parsing strategies require it (e.g. an LALR parser would not) and doing so would obfuscate the structure and description. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the one mutual left recursive set of rules being left. To factor the rules in the list can be inlined into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with your comment in the change that a refactoring would obscure the structure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree as well. |
||
|
||
*pointer_member_access* ([§23.6.3](unsafe-code.md#2363-pointer-member-access)) and *pointer_element_access* ([§23.6.4](unsafe-code.md#2364-pointer-element-access)) are only available in unsafe code ([§23](unsafe-code.md#23-unsafe-code)). | ||
|
||
Primary expressions are divided between *array_creation_expression*s and *primary_no_array_creation_expression*s. Treating *array_creation_expression* in this way, rather than listing it along with the other simple expression forms, enables the grammar to disallow potentially confusing code such as | ||
|
@@ -2330,14 +2332,13 @@ nameof_expression | |
; | ||
|
||
named_entity | ||
: simple_name | ||
| named_entity_target '.' identifier type_argument_list? | ||
: named_entity_target ('.' identifier type_argument_list?)* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trivial MLR removal |
||
; | ||
|
||
named_entity_target | ||
: 'this' | ||
: simple_name | ||
| 'this' | ||
| 'base' | ||
| named_entity | ||
| predefined_type | ||
| qualified_alias_member | ||
; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,14 +139,18 @@ A value type is either a struct type or an enumeration type. C# provides a set o | |
|
||
```ANTLR | ||
value_type | ||
: non_nullable_value_type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rules here formed an MLR set, just a bit or re-org fixed that. |
||
| nullable_value_type | ||
; | ||
|
||
non_nullable_value_type | ||
: struct_type | ||
| enum_type | ||
; | ||
|
||
struct_type | ||
: type_name | ||
| simple_type | ||
| nullable_value_type | ||
; | ||
|
||
simple_type | ||
|
@@ -177,17 +181,13 @@ floating_point_type | |
| 'double' | ||
; | ||
|
||
nullable_value_type | ||
: non_nullable_value_type '?' | ||
; | ||
|
||
non_nullable_value_type | ||
: type | ||
; | ||
|
||
enum_type | ||
: type_name | ||
; | ||
|
||
nullable_value_type | ||
: non_nullable_value_type '?' | ||
; | ||
``` | ||
|
||
Unlike a variable of a reference type, a variable of a value type can contain the value `null` only if the value type is a nullable value type [§9.3.11](types.md#9311-nullable-value-types). For every non-nullable value type there is a corresponding nullable value type denoting the same set of values plus the value `null`. | ||
|
@@ -612,7 +612,8 @@ Because of this equivalence, the following holds: | |
|
||
```ANTLR | ||
unmanaged_type | ||
: type | ||
: value_type | ||
| pointer_type // unsafe code support | ||
; | ||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes narrow down
enum_base
to avoid bad stuff happening. Text below has a small addition to describe the two alternatives.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems fine