Skip to content

The Identifier grammar and its reference to keywords #260

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

Closed
RexJaeschke opened this issue Apr 9, 2021 · 3 comments
Closed

The Identifier grammar and its reference to keywords #260

RexJaeschke opened this issue Apr 9, 2021 · 3 comments
Assignees
Labels
status: dependency This issue or PR depends on another (see comments)
Milestone

Comments

@RexJaeschke
Copy link
Contributor

[This issue arose from my work on replacing the lexer grammar rule alternatives of the form '<...>' in Proposal 3 of #37. ]

Although the grammar syntax used below is ANTLR, this is not an ANTLR-specific issue.

In the lexical grammar, we currently have the following:

Identifier
    : Available_Identifier
    | '@' Identifier_Or_Keyword
    ;

Available_Identifier
    : '<An Identifier_Or_Keyword that is not a Keyword>' 
    ;

Identifier_Or_Keyword
    : Identifier_Start_Character Identifier_Part_Character*
    ;

What is confusing me is the existence and use of the rule Identifier_Or_Keyword. It might just be the name it was given, but I'm not so sure.

Contributing significantly to that confusion is the text "An Identifier_Or_Keyword that is not a Keyword." It seems to me that an identifier or keyword that is not a keyword must be an identifier! If that is not the case, then the rule name implies something that isn't true.

BTW, it seems to me that the use of "keyword" refers to those reserved words only and does not include contextual keywords, as the are always identifiers.

In Issue #259, I get close to this subject. Here, my concern is that if we already have a rule Keyword, which captures all and only keywords, then everything else that looks like an identifier is an Identifier, so why does the Identifier grammar have to mention keywords?

I looked at the latest C spec and its grammar for identifiers makes no mention of keywords. However, the Java spec says

Identifier:
    IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
    JavaLetter {JavaLetterOrDigit}

Note that the JLS is quite happy to describe in text that Identifier excludes three categories of things rather than expressing that using syntax.

Does anyone else find this section of the grammar confusing?

@RexJaeschke RexJaeschke added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Apr 9, 2021
@RexJaeschke RexJaeschke added this to the C# 6 milestone Apr 9, 2021
@RexJaeschke RexJaeschke self-assigned this Apr 9, 2021
@Nigel-Ecma
Copy link
Contributor

Nigel-Ecma commented Apr 9, 2021 via email

@RexJaeschke RexJaeschke removed the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label May 28, 2021
@Nigel-Ecma
Copy link
Contributor

Adding this to the #37 & #259 dependency group.

@Nigel-Ecma Nigel-Ecma added the status: dependency This issue or PR depends on another (see comments) label Jun 1, 2021
@RexJaeschke
Copy link
Contributor Author

This has been addressed by PR #342.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: dependency This issue or PR depends on another (see comments)
Projects
None yet
Development

No branches or pull requests

2 participants