⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 antlr.1

📁 本工具提供一个词法分析器和语法分析器的集成开发环境
💻 1
字号:
.TH ANTLR 1 "September 1995" "ANTLR" "PCCTS Manual Pages".SH NAMEantlr \- ANother Tool for Language Recognition.SH SYNTAX.LP\fBantlr\fR [\fIoptions\fR] \fIgrammar_files\fR.SH DESCRIPTION.PP\fIAntlr\fP converts an extended form of context-free grammar into aset of C functions which directly implement an efficient form ofdeterministic recursive-descent LL(k) parser.  Context-free grammarsmay be augmented with predicates to allow semantics to influenceparsing; this allows a form of context-sensitive parsing.  Selectivebacktracking is also available to handle non-LL(k) and evennon-LALR(k) constructs.  \fIAntlr\fP also produces a definition of alexer which can be automatically converted into C code for a DFA-basedlexer by \fIdlg\fR.  Hence, \fIantlr\fR serves a function much likethat of \fIyacc\fR, however, it is notably more flexible and is moreintegrated with a lexer generator (\fIantlr\fR directly generates\fIdlg\fR code, whereas \fIyacc\fR and \fIlex\fR are given independentdescriptions).  Unlike \fIyacc\fR which accepts LALR(1) grammars,\fIantlr\fR accepts LL(k) grammars in an extended BNF notation \(emwhich eliminates the need for precedence rules..PPLike \fIyacc\fR grammars, \fIantlr\fR grammars can useautomatically-maintained symbol attribute values referenced as dollarvariables.  Further, because \fIantlr\fR generates top-down parsers,arbitrary values may be inherited from parent rules (passed likefunction parameters).  \fIAntlr\fP also has a mechanism for creatingand manipulating abstract-syntax-trees..PPThere are various other niceties in \fIantlr\fR, including the ability tospread one grammar over multiple files or even multiple grammars in a singlefile, the ability to generate a version of the grammar with actions strippedout (for documentation purposes), and lots more..SH OPTIONS.IP "\fB-ck \fIn\fR"Use up to \fIn\fR symbols of lookahead when using compressed (linearapproximation) lookahead.  This type of lookahead is very cheap tocompute and is attempted before full LL(k) lookahead, which is ofexponential complexity in the worst case.  In general, the compressedlookahead can be much deeper (e.g, \f(CW-ck 10\fP) than the fulllookahead (which usually must be less than 4)..IP \fB-CC\fPGenerate C++ output from both ANTLR and DLG..IP \fB-cr\fPGenerate a cross-reference for all rules.  For each rule, print a listof all other rules that reference it..IP \fB-e1\fPAmbiguities/errors shown in low detail (default)..IP \fB-e2\fPAmbiguities/errors shown in more detail..IP \fB-e3\fPAmbiguities/errors shown in excruciating detail..IP "\fB-fe\fP file"Rename \fBerr.c\fP to file..IP "\fB-fh\fP file"Rename \fBstdpccts.h\fP header (turns on \fB-gh\fP) to file..IP "\fB-fl\fP file"Rename lexical output, \fBparser.dlg\fP, to file..IP "\fB-fm\fP file"Rename file with lexical mode definitions, \fBmode.h\fP, to file..IP "\fB-fr\fP file"Rename file which remaps globally visible symbols, \fBremap.h\fP, to file..IP "\fB-ft\fP file"Rename \fBtokens.h\fP to file..IP \fB-ga\fPGenerate ANSI-compatible code (default case).  This has not beenrigorously tested to be ANSI XJ11 C compliant, but it is close.  Thenormal output of \fIantlr\fP is currently compilable under both K&R,ANSI C, and C++\(emthis option does nothing because \fIantlr\fPgenerates a bunch of #ifdef's to do the right thing depending on thelanguage..IP \fB-gc\fPIndicates that \fIantlr\fP should generate no C code, i.e., onlyperform analysis on the grammar..IP \fB-gd\fPC code is inserted in each of the \fIantlr\fR generated parsing functions toprovide for user-defined handling of a detailed parse trace.  The insertedcode consists of calls to the user-supplied macros or functions called\fBzzTRACEIN\fR and \fBzzTRACEOUT\fP.  The only argument is a\fIchar *\fR pointing to a C-style string which is the grammar rulerecognized by the current parsing function.  If no definition is givenfor the trace functions, upon rule entry and exit, a message will beprinted indicating that a particular rule as been entered or exited..IP \fB-ge\fPGenerate an error class for each non-terminal..IP \fB-gh\fPGenerate \fBstdpccts.h\fP for non-ANTLR-generated files to include.This file contains all defines needed to describe the type of parsergenerated by \fIantlr\fP (e.g. how much lookahead is used and whetheror not trees are constructed) and contains the \fBheader\fP actionspecified by the user..IP \fB-gk\fPGenerate parsers that delay lookahead fetches until needed.  Withoutthis option, \fIantlr\fP generates parsers which always have \fIk\fPtokens of lookahead available..IP \fB-gl\fPGenerate line info about grammar actions in C parser of the form\fB#\ \fIline\fP\ "\fIfile\fP"\fR which makes error messages fromthe C/C++ compiler make more sense as they will \*Qpoint\*U into thegrammar file not the resulting C file.  Debugging is easier as well,because you will step through the grammar not C file..IP \fB-gs\fRDo not generate sets for token expression lists; instead generate a\fB||\fP-separated sequence of \fBLA(1)==\fItoken_number\fR.  Thedefault is to generate sets..IP \fB-gt\fPGenerate code for Abstract-Syntax Trees..IP \fB-gx\fPDo not create the lexical analyzer files (dlg-related).  This optionshould be given when the user wishes to provide a customized lexicalanalyzer.  It may also be used in \fImake\fR scripts to cause only theparser to be rebuilt when a change not affecting the lexical structureis made to the input grammars..IP "\fB-k \fIn\fR"Set k of LL(k) to \fIn\fR; i.e. set tokens of look-ahead (default==1)..IP "\fB-o\fP dirDirectory where output files should go (default=".").  This is verynice for keeping the source directory clear of ANTLR and DLG spawn..IP \fB-p\fPThe complete grammar, collected from all input grammar files andstripped of all comments and embedded actions, is listed to\fBstdout\fP.  This is intended to aid in viewing the entire grammaras a whole and to eliminate the need to keep actions concisely statedso that the grammar is easier to read.  Hence, it is preferable toembed even complex actions directly in the grammar, rather than tocall them as subroutines, since the subroutine call overhead will besaved..IP \fB-pa\fPThis option is the same as \fB-p\fP except that the output isannotated with the first sets determined from grammar analysis..IP "\fB-prc on\fRTurn on the computation and hoisting of predicate context..IP "\fB-prc off\fRTurn off the computation and hoisting of predicate context.  Thisoption makes 1.10 behave like the 1.06 release with option \fB-pr\fRon.  Context computation is off by default..IP "\fB-rl \fIn\fRLimit the maximum number of tree nodes used by grammar analysis to\fIn\fP.  Occasionally, \fIantlr\fP is unable to analyze a grammarsubmitted by the user.  This rare situation can only occur when thegrammar is large and the amount of lookahead is greater than one.  Anonlinear analysis algorithm is used by PCCTS to handle the generalcase of LL(k) parsing.  The average complexity of analysis, however, isnear linear due to some fancy footwork in the implementation whichreduces the number of calls to the full LL(k) algorithm.  An errormessage will be displayed, if this limit is reached, which indicatesthe grammar construct being analyzed when \fIantlr\fP hit anon-linearity.  Use this option if \fIantlr\fP seems to go out tolunch and your disk start thrashing; try \fIn\fP=10000 to start.  Oncethe offending construct has been identified, try to remove theambiguity that \fIantlr\fP was trying to overcome with large lookaheadanalysis.  The introduction of (...)? backtracking blocks eliminatessome of these problems\ \(em \fIantlr\fP does not analyze alternativesthat begin with (...)? (it simply backtracks, if necessary, at runtime)..IP \fB-w1\fRSet low warning level.  Do not warn if semantic predicates and/or(...)? blocks are assumed to cover ambiguous alternatives..IP \fB-w2\fRAmbiguous parsing decisions yield warnings even if semantic predicatesor (...)? blocks are used.  Warn if predicate context computed andsemantic predicates incompletely disambiguate alternative productions..IP \fB-\fRRead grammar from standard input and generate \fBstdin.c\fP as theparser file..SH "SPECIAL CONSIDERATIONS".PP\fIAntlr\fP works...  we think.  There is no implicit guarantee ofanything.  We reserve no \fBlegal\fP rights to the software known asthe Purdue Compiler Construction Tool Set (PCCTS) \(em PCCTS is in thepublic domain.  An individual or company may do whatever they wishwith source code distributed with PCCTS or the code generated byPCCTS, including the incorporation of PCCTS, or its output, intocommercial software.  We encourage users to develop software withPCCTS.  However, we do ask that credit is given to us for developingPCCTS.  By "credit", we mean that if you incorporate our source codeinto one of your programs (commercial product, research project, orotherwise) that you acknowledge this fact somewhere in thedocumentation, research report, etc...  If you like PCCTS and havedeveloped a nice tool with the output, please mention that youdeveloped it using PCCTS.  As long as these guidelines are followed,we expect to continue enhancing this system and expect to make othertools available as they are completed..SH FILES.IP *.coutput C parser..IP *.cppoutput C++ parser when C++ mode is used..IP \fBparser.dlg\fPoutput \fIdlg\fR lexical analyzer..IP \fBerr.c\fPtoken string array, error sets and error support routines.  Not used inC++ mode..IP \fBremap.h\fPfile that redefines all globally visible parser symbols.  The use ofthe #parser directive creates this file.  Not used inC++ mode..IP \fBstdpccts.h\fPlist of definitions needed by C files, not generated by PCCTS, thatreference PCCTS objects.  This is not generated by default.  Not used inC++ mode..IP \fBtokens.h\fPoutput \fI#defines\fR for tokens used and function prototypes forfunctions generated for rules..SH "SEE ALSO".LPdlg(1), pccts(1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -