Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Resume

Summary CS 101 Description of the JavaCC Grammar File

Note
-
Vendu
-
Pages
14
Publié le
12-02-2023
Écrit en
2022/2023

CS 101 Description of the JavaCC Grammar File This web page contains the complete syntax of Java Compiler Compiler grammar files with detailed explanations of each construct. Tokens in the grammar files follow the same conventions as for Java. Hence identifiers, strings, characters, etc. used in the grammars are the same as Java identifiers, Java strings, Java characters, etc. White space in the grammar files also follows the same conventions as for Java. This includes the syntax for comments. Most comments present in the grammar files are generated into the generated parser/lexical analyzer. Grammar files are preprocessed for Unicode escapes just as Java files are (i.e., occurrences of strings such as uxxxx - where xxxx is a hex value - are converted the the corresponding Unicode character before lexical analysis). Exceptions to the above rules: The Java operators "", "", "", "=", "=", and "=" are left out of Java Compiler Compiler's input token list in order to allow convenient nested use of token specifications. Finally, the following are the additional reserved words in the Java Compiler Compiler grammar files. EOF IGNORE_CASE JAVACODE LOOKAHEAD MORE options PARSER_BEGIN PARSER_END SKIP SPECIAL_TOKEN TOKEN TOKEN_MGR_DECLS Any Java entities used in the grammar rules that follow appear italicized with the prefix java_ (e.g., java_compilation_unit). javacc_input ::= javacc_options "PARSER_BEGIN" "(" IDENTIFIER ")" java_compilation_unit "PARSER_END" "(" IDENTIFIER ")" ( production )* EOF The grammar file starts with a list of options (which is optional). This is then followed by a Java compilation unit enclosed between "PARSER_BEGIN(name)" and "PARSER_END(name)". After this is a list of grammar productions. Options and productions are described later. The name that follows "PARSER_BEGIN" and "PARSER_END" must be the same and this identifies the name of the generated parser. For example, if name is "MyParser", then the following files are generated: MyP: The generate parser. MyParserTokenM: The generated token manager (or scanner/lexical analyzer). MyParserC: A bunch of useful constants.

Montrer plus Lire moins
Établissement
Cours

Aperçu du contenu

CS 101 Description of the JavaCC
Grammar File
This web page contains the complete syntax of Java Compiler Compiler grammar files with
detailed explanations of each construct.

Tokens in the grammar files follow the same conventions as for Java. Hence identifiers,
strings, characters, etc. used in the grammars are the same as Java identifiers, Java strings,
Java characters, etc.

White space in the grammar files also follows the same conventions as for Java. This includes
the syntax for comments. Most comments present in the grammar files are generated into the
generated parser/lexical analyzer.

Grammar files are preprocessed for Unicode escapes just as Java files are (i.e., occurrences of
strings such as \uxxxx - where xxxx is a hex value - are converted the the corresponding
Unicode character before lexical analysis).

Exceptions to the above rules: The Java operators "<<", ">>", ">>>", "<<=", ">>=", and
">>>=" are left out of Java Compiler Compiler's input token list in order to allow convenient
nested use of token specifications. Finally, the following are the additional reserved words in
the Java Compiler Compiler grammar files.


EOF IGNORE_CASE JAVACODE LOOKAHEAD

MORE options PARSER_BEGIN PARSER_END
SKIP SPECIAL_TOKEN TOKEN TOKEN_MGR_DECLS


Any Java entities used in the grammar rules that follow appear italicized with the prefix java_
(e.g., java_compilation_unit).



javacc_input ::= javacc_options
"PARSER_BEGIN" "(" <IDENTIFIER> ")"
java_compilation_unit
"PARSER_END" "(" <IDENTIFIER> ")"
( production )*
<EOF>


The grammar file starts with a list of options (which is optional). This is then followed by a
Java compilation unit enclosed between "PARSER_BEGIN(name)" and "PARSER_END(name)".
After this is a list of grammar productions. Options and productions are described later.

The name that follows "PARSER_BEGIN" and "PARSER_END" must be the same and this
identifies the name of the generated parser. For example, if name is "MyParser", then the
following files are generated:

MyParser.java: The generate parser.
MyParserTokenManager.java: The generated token manager (or scanner/lexical analyzer).
MyParserConstants.java: A bunch of useful constants.

, Other files such as "Token.java", "ParseError.java", etc. are also generated. However, these
files contain boilerplate code and are the same for any grammar and may be reused across
grammars.

Between the PARSER_BEGIN and PARSER_END constructs is a regular Java compilation unit (a
compilation unit in Java lingo is the entire contents of a Java file). This may be any arbitrary
Java compilation unit so long as it contains a class declaration whose name is the same as the
name of the generated parser ("MyParser" in the above example). Hence, in general, this part
of the grammar file looks like:

PARSER_BEGIN(parser_name)
. . .
class parser_name . . . {
. . .
}
. . .
PARSER_END(parser_name)

JavaCC does not perform detailed checks on the compilation unit, so it is possible for a
grammar file to pass through JavaCC and generate Java files that produce errors when they
are compiled.

If the compilation unit includes a package declaration, this is included in all the generated
files. If the compilation unit includes imports declarations, this is included in the generated
parser and token manager files.

The generated parser file contains everything in the compilation unit and in addition contains
the generated parser code that is included at the end of the parser class. For the above
example, the generated parser will look like:

. . .
class parser_name . . . {
. . .
// generated parser is inserted here.
}
. . .

The generated parser includes a public method declaration corresponding to each non-terminal
(see javacode_production and bnf_production) in the grammar file. Parsing with respect to a
non-terminal is achieved by calling the method corresponding to that non-terminal. Unlike
yacc, there is no single start symbol in JavaCC - one can parse with respect to any non-
terminal in the grammar.

The generated token manager provides one public method:

Token getNextToken() throws ParseError;

For more details on how this method may be used, please read the description of the Java
Compiler Compiler API.



javacc_options ::= [ "options" "{" ( option_binding )* "}" ]

École, étude et sujet

Cours

Infos sur le Document

Publié le
12 février 2023
Nombre de pages
14
Écrit en
2022/2023
Type
RESUME

Sujets

$13.76
Accéder à l'intégralité du document:

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Faites connaissance avec le vendeur

Seller avatar
Les scores de réputation sont basés sur le nombre de documents qu'un vendeur a vendus contre paiement ainsi que sur les avis qu'il a reçu pour ces documents. Il y a trois niveaux: Bronze, Argent et Or. Plus la réputation est bonne, plus vous pouvez faire confiance sur la qualité du travail des vendeurs.
magdamwikash23 Western Governers University
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
114
Membre depuis
3 année
Nombre de followers
94
Documents
5328
Dernière vente
2 mois de cela
Magda

NURSING STUDY GUIDES/EXAMS AND NOTES ALL VERIFIED BY EXPERTS All my uploaded documents, exams and essays are verified by relevant experts.I can assure an A or at least 90% if you use any of my documents.

3.9

14 revues

5
7
4
2
3
2
2
2
1
1

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Vous travaillez sur vos références ?

Créez des citations précises en APA, MLA et Harvard avec notre générateur de sources gratuit.

Vous travaillez sur vos références ?

Foire aux questions