Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Samenvatting

Summary CS 101 Description of the JavaCC Grammar File

Beoordeling
-
Verkocht
-
Pagina's
14
Geüpload op
08-04-2022
Geschreven in
2021/2022

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. Other files such as "T", "ParseE", 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" i

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

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 )* "}" ]

Geschreven voor

Vak

Documentinformatie

Geüpload op
8 april 2022
Aantal pagina's
14
Geschreven in
2021/2022
Type
SAMENVATTING

Onderwerpen

$16.99
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
ACADEMICAIDSTORE Chamberlain College Of Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
1214
Lid sinds
4 jaar
Aantal volgers
892
Documenten
12026
Laatst verkocht
2 dagen geleden
ACADEMICAID STORE

Welcome to ACADEMICAID store! We specialize in reliable test banks, exam questions with verified answers, practice exams, study guides, and complete exam review materials to help students pass on the first try. Our uploads support Nursing programs, professional certifications, business courses, accounting classes, and college-level exams. All documents are well-organized, accurate, exam-focused, and easy to follow, making them ideal for quizzes, midterms, finals, ATI &amp; HESI prep, NCLEX-style practice, certification exams, and last-minute reviews. If you’re looking for trusted test banks, comprehensive exam prep, and time-saving study resources, you’re in the right place.

Lees meer Lees minder
4.1

176 beoordelingen

5
98
4
29
3
28
2
6
1
15

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen