next up previous
Next: Productions from 3: Lexical Up: An Analyzer for Java Previous: Support code


Phrase Structure

To solve the syntactic analysis subproblem, a Java processor must examine the sequence of tokens resulting from lexical analysis, grouping those tokens into a hierarchy of phrases. A context-free grammar is used to describe the phrase structure.

Character sequences that must appear exactly as specified are 'quoted' in grammar rules. No additional lexical specification of these literal terminals is given. Non-literal terminals of the grammar are represented by symbols, and the form of the character strings acceptable as instances of these terminals is described by separate regular expressions.

The definition of a nonterminal is introduced by the name of the nonterminal being defined, followed by a colon. One or more alternative expansions for the nonterminal then follow, separated by slashes (/). The entire set of alternatives is terminated by a period.

Eli's notation for an optional symbol in a context-free grammar is to surround that symbol with square brackets ([ ]). In a regular expression, square brackets indicate a set of characters rather than an option. This corresponds to the ``one of'' notation found in the Java specification, but it cannot be used in context-free grammars.

A type-con file specifies the syntactic analysis subproblem:

Phrase.con[38]:

Productions from 3: Lexical Structure[39]
Productions from 4: Types, Values, and Variables[40]
Productions from 6: Names[41]
Productions from 7: Packages[42]
Productions Only in the LALR(1) Grammar[43]
Productions from 8.1: Class Declaration[44]
Productions from 8.3: Field Declarations[45]
Productions from 8.4: Method Declarations[46]
Productions from 8.6 and 8.7: Class Initializers[47]
Productions from 8.8: Constructor Declarations[48]
Productions from 9.1: Interface Declarations[49]
Productions from 10: Arrays[50]
Productions from 14: Blocks and Statements[51]
Productions from 15: Expressions[52]
Compiling multiple compilation units[53]
This macro is attached to a product file.



Subsections
next up previous
Next: Productions from 3: Lexical Up: An Analyzer for Java Previous: Support code
2008-09-11