Replies: 6 comments 9 replies
-
According to Wikipedia, PL/I does have reserved words... |
Beta Was this translation helpful? Give feedback.
-
Probably @Korporal means context keywords. These words can be either keywords or identifiers depending on context. And such words are being recognized on the parser stage, not on the lexer. SQL dialects (MySql, PL/SQL, T-SQL) have a lot of such words. The following syntax can be used for description, but semantic predicates are required: getter
: {_input.LT(1).getText().equals("get")}? Identifier propertyName
; |
Beta Was this translation helpful? Give feedback.
-
Hi, well this is interesting because I'm developing a grammar for a not-yet-existing language and it will have no reserved words. I want to distinguish too between "keywords" and "reserved words". A keyword is a word (same lexical structure as an identifier) that also carries a meaning within the language like A reserved word is a word that cannot be used as an identifier, it is reserved, unavailable for use as a variable or method or type name. PL/I has no reserved words, so this is entirely valid and parsed without problem:
Nobody would write stuff like that but the language lets you, it does not care. The reason it lets you is that this design means new keywords can be be added in the future without issue, because even if the new keyword had been used as an identifier by someone it matters not. I just have no idea if these kinds of parsing tools can generate parsers for these kinds of languages. I developed a compiler for PL/I several decades ago and had no access to tools like this. So I "hand crafted" a recursive descent parser written in C. This worked fine and was in fact able to generate linkable COFF binaries for 32-bit Windows NT (as it was called back then). But I know this is very uncommon in language design and so tools may simply not bother with the problem. |
Beta Was this translation helpful? Give feedback.
-
Are you looking to build a PL/I parser in a supported language target (such as Java, C#, C++, Python) or build a parser generator for PL/I (i.e. a new ANTLR language target) ? |
Beta Was this translation helpful? Give feedback.
-
Back to your previous example it’s trivial for a grammar to accept a keyword as an identifier:
IF: ‘if’;
IDENTIFIER: [a-z]+;
some_rule:
IF identifier_or_keyword …;
identifier_or_keyword:
IDENTIFIER
| IF;
In that sense, you can build a grammar with no reserved words.
… Le 28 oct. 2021 à 00:22, Hugh Gleaves ***@***.***> a écrit :
Are you looking to build a PL/I parser in a supported language target (such as Java, C#, C++, Python) or build a parser generator for PL/I (i.e. a new ANTLR language target) ?
Neither, I'm curious about developing a new grammar that has no reserved words, this grammar will - not immediately - be developed so that it can represent all that C# can do.
So, I'm developing a new grammar that could eventually replace the C# grammar, and one difference is that it would have no reserved words.
So I'm just curious as to whether ANTLR can be configured to consume some grammar definition where that grammar does not reserve words.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#3321 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAZNQJBAYUDM3PAKFRLLAV3UJB3TFANCNFSM5GYIUWIQ>.
|
Beta Was this translation helpful? Give feedback.
-
The Rexx language doesn't have reserved words - similar to PL/I, certain words are reserved in certain contexts. There's an example grammar for it in https://github.com/antlr/grammars-v4/tree/master/rexx. It works just fine. |
Beta Was this translation helpful? Give feedback.
-
I'd like to ask if there is any inherent restriction within ANTLR that prevents it from generating a parser for a language that has no reserved words, one example of such a language is PL/I and there are probably more.
Any info appreciated.
Beta Was this translation helpful? Give feedback.
All reactions