2.4 Grammar notation: examples look inconsistent
Daniël p
daniel.fp.studio at gmail.com
Thu Aug 18 23:27:55 UTC 2016
While reading Chapter 2 of The Java Language Specification, Java SE 8
Edition, I may have spotted an inconsistency.
This topic about grammer is quite new for me though, so I might have just
misinterpreted the text.
If that is the case, my apologies, and I would appreciate if you would let
me know what my mistake was (although I understand that this email address
is not for Q & A).
Yet, I have been certain enough about the problem to send a comment anyway.
*The problem*
In the Java Language Specification, Chapter 2, the following statements are
made:
*2.2. The Lexical Grammar*
> These input elements, with white space (§3.6
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.6>)
> and comments (§3.7
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.7>)
> discarded, form the terminal symbols for the syntactic grammar for the Java
> programming language and are called *tokens* (§3.5
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.5>). *These
> tokens are the identifiers *(§3.8
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8>)*,
> keywords *(§3.9
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.9>)*,
> literals *(§3.10
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10>)*,
> separators *(§3.11
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.11>)*,
> and operators *(§3.12
> <http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.12>*)*
> of the Java programming language.
*2.3. The Syntactic Grammar* says that
> This grammar (the syntactic grammar) has *tokens defined by the lexical
> grammar as its terminal symbols*.
*2.4. Grammar Notation* says that
> *Terminal symbols are shown in fixed width** font* in the productions of
> the lexical and syntactic grammars.
This is the example shown:
For example, the syntactic production:
IfThenStatement:
if ( Expression ) Statement
states that the nonterminal IfThenStatement represents the token if,
followed by a left parenthesis token, followed by an Expression, followed
by a right parenthesis token, followed by a Statement.
So the *if*-keyword and the parentheses *()* are tokens (§3.5
<http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.5>), and
tokens are the terminal symbols of The Syntactic Grammer, and Terminal
symbols are shown in fixed width font.
Why are the tokens in this example and other examples in *italic* font
instead of just fixed with font, even if they are terminal symbols and not
nonterminal symbols in syntactic grammer?
*Final question:*Why is it if ( Expression ) Statement instead of if (
Expression ) Statement?
I hope I've made a contribution. Thank you in advance.
More information about the jls-jvms-spec-comments
mailing list