Establish a common terminology for non-terminals #4274
Replies: 2 comments 3 replies
-
Could you explain what you mean by "common terminology"? Is it a naming convention, or are you looking at a common, reusable set of grammar rules? |
Beta Was this translation helpful? Give feedback.
-
Some syntax is defined to avoid grammatical ambiguity. Java partitions if-statements into "no short form" vs. a "short form" https://docs.oracle.com/javase/specs/jls/se23/html/jls-14.html#jls-14.5. (NB: this has nothing to do with the tertiary operator.) This is done to avoid the "dangling else" problem. For example,
This grammar is ambiguous for input
Java solves this in the JLS by defining "no short" productions. So, grammar XXX would be corrected.
If I wanted to write a program that analyzes the parse tree to count the number of if-statements, I would have to count not only the number of
However, this could be easily rewritten to an AST that has only one "ifstmt" node type. How would you handle this if an if-statement is just called "ifStatement" across all programming language grammars? |
Beta Was this translation helpful? Give feedback.
-
I'm working on an application that analyzes source code. The lack of uniform terminology for non-terminals serving the same purpose in other programming languages is quite problematic for me. Perhaps others have written tools which have limited applicability due to the incompatibility between grammars.
There was a previous discussion on establishing a single format for the various grammars #3816.
I hope a collection of grammars for ANTLR4 conforming to a single convention for terminology already exists, or there is a willingness of the community to establish and adhere to one if not.
Beta Was this translation helpful? Give feedback.
All reactions