home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts.zip / pccts / antlr / antlr1.txt < prev    next >
Text File  |  1994-03-31  |  15KB  |  397 lines

  1.  
  2.  
  3.  
  4. ANTLR(1)                PCCTS Manual Pages               ANTLR(1)
  5.  
  6.  
  7. NNAAMMEE
  8.        antlr - ANother Tool for Language Recognition
  9.  
  10. SSYYNNTTAAXX
  11.        aannttllrr [_o_p_t_i_o_n_s] _g_r_a_m_m_a_r___f_i_l_e_s
  12.  
  13. DDEESSCCRRIIPPTTIIOONN
  14.        _A_n_t_l_r  converts  an  extended form of context-free grammar
  15.        into a set of C  functions  which  directly  implement  an
  16.        efficient  form  of  deterministic recursive-descent LL(k)
  17.        parser.  Context-free grammars may be augmented with pred-
  18.        icates  to  allow  semantics  to  influence  parsing; this
  19.        allows a form  of  context-sensitive  parsing.   Selective
  20.        backtracking  is  also  available  to handle non-LL(k) and
  21.        even non-LALR(k) constructs.  _A_n_t_l_r also produces a  defi-
  22.        nition  of  a  lexer  which can be automatically converted
  23.        into C code for a DFA-based lexer by  _d_l_g.   Hence,  _a_n_t_l_r
  24.        serves  a  function much like that of _y_a_c_c, however, it is
  25.        notably more flexible and is more integrated with a  lexer
  26.        generator (_a_n_t_l_r directly generates _d_l_g code, whereas _y_a_c_c
  27.        and _l_e_x are given independent descriptions).  Unlike  _y_a_c_c
  28.        which  accepts LALR(1) grammars, _a_n_t_l_r accepts LL(k) gram-
  29.        mars in an extended BNF notation -- which  eliminates  the
  30.        need for precedence rules.
  31.  
  32.        Like  _y_a_c_c grammars, _a_n_t_l_r grammars can use automatically-
  33.        maintained symbol attribute values  referenced  as  dollar
  34.        variables.   Further,  because  _a_n_t_l_r  generates  top-down
  35.        parsers, arbitrary values may  be  inherited  from  parent
  36.        rules (passed like function parameters).  _A_n_t_l_r also has a
  37.        mechanism for creating and  manipulating  abstract-syntax-
  38.        trees.
  39.  
  40.        There  are  various other niceties in _a_n_t_l_r, including the
  41.        ability to spread one grammar over multiple files or  even
  42.        multiple  grammars in a single file, the ability to gener-
  43.        ate a version of the grammar  with  actions  stripped  out
  44.        (for documentation purposes), and lots more.
  45.  
  46. OOPPTTIIOONNSS
  47.        --cckk _n  Use  up  to  _n symbols of lookahead when using com-
  48.               pressed  (linear  approximation)  lookahead.   This
  49.               type  of  lookahead is very cheap to compute and is
  50.               attempted before full LL(k) lookahead, which is  of
  51.               exponential  complexity in the worst case.  In gen-
  52.               eral, the compressed lookahead can be  much  deeper
  53.               (e.g,  --cckk  1100) than the full lookahead (which usu-
  54.               ally must be less than 4).
  55.  
  56.        --CCCC    Generate C++ output from both ANTLR and DLG.
  57.  
  58.        --ccrr    Generate a cross-reference for all rules.  For each
  59.               rule,  print  a list of all other rules that refer-
  60.               ence it.
  61.  
  62.  
  63.  
  64. ANTLR                       April 1994                          1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ANTLR(1)                PCCTS Manual Pages               ANTLR(1)
  71.  
  72.  
  73.        --cctt    Do not make copies of tokens passed to  the  parser
  74.               in  C++  mode (default=to copy).  When using DLG in
  75.               conjunction with ANTLR, you will always want  ANTLR
  76.               to  make  copies because DLG only has space for one
  77.               AANNTTLLRRTTookkeenn (which is passed  to  the  scanner  with
  78.               sseettTTookkeenn);  this  address  is  always returned and,
  79.               hence, without copies, all $-variables would  point
  80.               to the same AANNTTLLRRTTookkeenn.
  81.  
  82.        --ee11    Ambiguities/errors shown in low detail (default).
  83.  
  84.        --ee22    Ambiguities/errors shown in more detail.
  85.  
  86.        --ee33    Ambiguities/errors shown in excruciating detail.
  87.  
  88.        --ffee file
  89.               Rename eerrrr..cc to file.
  90.  
  91.        --ffhh file
  92.               Rename ssttddppccccttss..hh header (turns on --gghh) to file.
  93.  
  94.        --ffll file
  95.               Rename lexical output, ppaarrsseerr..ddllgg, to file.
  96.  
  97.        --ffmm file
  98.               Rename  file with lexical mode definitions, mmooddee..hh,
  99.               to file.
  100.  
  101.        --ffrr file
  102.               Rename file which remaps globally visible  symbols,
  103.               rreemmaapp..hh, to file.
  104.  
  105.        --fftt file
  106.               Rename ttookkeennss..hh to file.
  107.  
  108.        --ggaa    Generate ANSI-compatible code (default case).  This
  109.               has not been rigorously tested to be  ANSI  XJ11  C
  110.               compliant,  but  it is close.  The normal output of
  111.               _a_n_t_l_r is currently compilable under both K&R,  ANSI
  112.               C,  and C++--this option does nothing because _a_n_t_l_r
  113.               generates a bunch of #ifdef's to do the right thing
  114.               depending on the language.
  115.  
  116.        --ggcc    Indicates  that  _a_n_t_l_r  should  generate no C code,
  117.               i.e., only perform analysis on the grammar.
  118.  
  119.        --ggdd    C code is inserted in each of the  _a_n_t_l_r  generated
  120.               parsing  functions to provide for user-defined han-
  121.               dling of a detailed parse trace.  The inserted code
  122.               consists  of  calls  to the user-supplied macros or
  123.               functions called  zzzzTTRRAACCEEIINN  and  zzzzTTRRAACCEEOOUUTT.   The
  124.               only  argument  is  a  _c_h_a_r _* pointing to a C-style
  125.               string which is the grammar rule recognized by  the
  126.               current  parsing  function.   If  no  definition is
  127.  
  128.  
  129.  
  130. ANTLR                       April 1994                          2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ANTLR(1)                PCCTS Manual Pages               ANTLR(1)
  137.  
  138.  
  139.               given for the trace functions, upon rule entry  and
  140.               exit,  a  message will be printed indicating that a
  141.               particular rule as been entered or exited.
  142.  
  143.        --ggee    Generate an error class for each non-terminal.
  144.  
  145.        --gghh    Generate ssttddppccccttss..hh for  non-ANTLR-generated  files
  146.               to  include.  This file contains all defines needed
  147.               to describe the type of parser generated  by  _a_n_t_l_r
  148.               (e.g. how much lookahead is used and whether or not
  149.               trees are  constructed)  and  contains  the  hheeaaddeerr
  150.               action specified by the user.
  151.  
  152.        --ggkk    Generate parsers that delay lookahead fetches until
  153.               needed.   Without  this  option,  _a_n_t_l_r   generates
  154.               parsers  which  always  have  _k tokens of lookahead
  155.               available.  This option is  incompatible  with  --pprr
  156.               and  renders  references  to  LLAA((_i))  invalid as one
  157.               never knows when the _i_t_h token of lookahead will be
  158.               fetched.
  159.  
  160.        --ggll    Generate  line  info  about  grammar  actions  in C
  161.               parser of the form ## _l_i_n_e ""_f_i_l_e"" which makes  error
  162.               messages from the C/C++ compiler make more sense as
  163.               they will point  into  the  grammar  file  not  the
  164.               resulting  C  file.   Debugging  is easier as well,
  165.               because you will step through  the  grammar  not  C
  166.               file.
  167.  
  168.        --ggpp _p_r_e_f_i_x
  169.               Prefix all functions generated from rules with _p_r_e_-
  170.               _f_i_x.  This is now obsolete.  Use the #parser "name"
  171.               _a_n_t_l_r directive.
  172.  
  173.        --ggss    Do  not  generate  sets for token expression lists;
  174.               instead  generate  a   ||||-separated   sequence   of
  175.               LLAA((11))====_t_o_k_e_n___n_u_m_b_e_r.   The  default  is to generate
  176.               sets.
  177.  
  178.        --ggtt    Generate code for Abstract-Syntax Trees.
  179.  
  180.        --ggxx    Do not create  the  lexical  analyzer  files  (dlg-
  181.               related).   This  option  should  be given when the
  182.               user wishes to provide a  customized  lexical  ana-
  183.               lyzer.   It  may  also  be  used in _m_a_k_e scripts to
  184.               cause only the parser to be rebuilt when  a  change
  185.               not  affecting the lexical structure is made to the
  186.               input grammars.
  187.  
  188.        --kk _n   Set k of LL(k) to _n; i.e. set tokens of  look-ahead
  189.               (default==1).
  190.  
  191.        --oo dir Directory    where    output    files   should   go
  192.               (default=".").  This is very nice for  keeping  the
  193.  
  194.  
  195.  
  196. ANTLR                       April 1994                          3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ANTLR(1)                PCCTS Manual Pages               ANTLR(1)
  203.  
  204.  
  205.               source directory clear of ANTLR and DLG spawn.
  206.  
  207.        --pp     The  complete  grammar,  collected  from  all input
  208.               grammar files and  stripped  of  all  comments  and
  209.               embedded  actions,  is  listed  to ssttddoouutt.  This is
  210.               intended to aid in viewing the entire grammar as  a
  211.               whole  and  to  eliminate  the need to keep actions
  212.               concisely stated so that the grammar is  easier  to
  213.               read.   Hence,  it is preferable to embed even com-
  214.               plex actions directly in the grammar,  rather  than
  215.               to  call  them as subroutines, since the subroutine
  216.               call overhead will be saved.
  217.  
  218.        --ppaa    This option is the same as --pp except that the  out-
  219.               put  is  annotated  with  the first sets determined
  220.               from grammar analysis.
  221.  
  222.        --pprr    Obsolete -- used to turn on use  of  predicates  in
  223.               parsing  decisions  in release 1.06.  Now, in 1.10,
  224.               the specification of a predicate  implies  that  it
  225.               should be used.  When a syntactic ambiguity is dis-
  226.               covered, _a_n_t_l_r searches for predicates that can  be
  227.               used to disambiguate the decision.  Predicates have
  228.               dual roles as semantic validation  and  disambigua-
  229.               tion predicates.
  230.  
  231.        --pprrcc oonn
  232.               Turn  on  the computation and hoisting of predicate
  233.               context.
  234.  
  235.        --pprrcc ooffff
  236.               Turn off the computation and hoisting of  predicate
  237.               context.   This  option  makes 1.10 behave like the
  238.               1.06 release with option --pprr on.  Context  computa-
  239.               tion is off by default.
  240.  
  241.        --rrll _n  Limit  the  maximum  number  of  tree nodes used by
  242.               grammar analysis  to  _n.   Occasionally,  _a_n_t_l_r  is
  243.               unable  to analyze a grammar submitted by the user.
  244.               This rare situation can only occur when the grammar
  245.               is  large  and  the  amount of lookahead is greater
  246.               than one.  A nonlinear analysis algorithm  is  used
  247.               by  PCCTS to handle the general case of LL(k) pars-
  248.               ing.  The average complexity of analysis,  however,
  249.               is  near  linear  due to some fancy footwork in the
  250.               implementation which reduces the number of calls to
  251.               the full LL(k) algorithm.  An error message will be
  252.               displayed, if this limit is  reached,  which  indi-
  253.               cates  the  grammar  construct  being analyzed when
  254.               _a_n_t_l_r hit a  non-linearity.   Use  this  option  if
  255.               _a_n_t_l_r  seems to go out to lunch and your disk start
  256.               thrashing; try _n=10000 to start.  Once the  offend-
  257.               ing  construct  has  been identified, try to remove
  258.               the ambiguity that _a_n_t_l_r  was  trying  to  overcome
  259.  
  260.  
  261.  
  262. ANTLR                       April 1994                          4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ANTLR(1)                PCCTS Manual Pages               ANTLR(1)
  269.  
  270.  
  271.               with large lookahead analysis.  The introduction of
  272.               (...)? backtracking blocks eliminates some of these
  273.               problems --  _a_n_t_l_r  does  not  analyze alternatives
  274.               that begin with (...)? (it  simply  backtracks,  if
  275.               necessary, at run time).
  276.  
  277.        --ww11    Set  low  warning  level.   Do not warn if semantic
  278.               predicates and/or  (...)?  blocks  are  assumed  to
  279.               cover ambiguous alternatives.
  280.  
  281.        --ww22    Ambiguous  parsing decisions yield warnings even if
  282.               semantic predicates  or  (...)?  blocks  are  used.
  283.               Warn  if  predicate  context  computed and semantic
  284.               predicates  incompletely  disambiguate  alternative
  285.               productions.
  286.  
  287.        --      Read  grammar  from  standard  input  and  generate
  288.               ssttddiinn..cc as the parser file.
  289.  
  290. SSPPEECCIIAALL CCOONNSSIIDDEERRAATTIIOONNSS
  291.        _A_n_t_l_r works...  we think.  There is no implicit  guarantee
  292.        of  anything.   We reserve no lleeggaall rights to the software
  293.        known as the Purdue Compiler Construction Tool Set (PCCTS)
  294.        --  PCCTS  is in the public domain.  An individual or com-
  295.        pany may do whatever  they  wish  with  source  code  dis-
  296.        tributed  with  PCCTS  or  the  code  generated  by PCCTS,
  297.        including the incorporation of PCCTS, or its output,  into
  298.        commercial  software.  We encourage users to develop soft-
  299.        ware with PCCTS.  However, we do ask that credit is  given
  300.        to  us for developing PCCTS.  By "credit", we mean that if
  301.        you incorporate our source code into one of your  programs
  302.        (commercial  product, research project, or otherwise) that
  303.        you acknowledge this fact somewhere in the  documentation,
  304.        research report, etc...  If you like PCCTS and have devel-
  305.        oped a nice tool with the output, please mention that  you
  306.        developed it using PCCTS.  As long as these guidelines are
  307.        followed, we expect to continue enhancing this system  and
  308.        expect  to  make  other  tools  available as they are com-
  309.        pleted.
  310.  
  311. FFIILLEESS
  312.        *.c    output C parser
  313.  
  314.        *.C    output C++ parser when C++ mode is used
  315.  
  316.        ppaarrsseerr..ddllgg
  317.               output _d_l_g lexical analyzer
  318.  
  319.        eerrrr..cc  token string array, error sets  and  error  support
  320.               routines
  321.  
  322.        rreemmaapp..hh
  323.               file  that  redefines  all  globally visible parser
  324.               symbols.  The use of the #parser directive  creates
  325.  
  326.  
  327.  
  328. ANTLR                       April 1994                          5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. ANTLR(1)                PCCTS Manual Pages               ANTLR(1)
  335.  
  336.  
  337.               this file
  338.  
  339.        ssttddppccccttss..hh
  340.               list  of  definitions needed by C files, not gener-
  341.               ated by PCCTS, that reference PCCTS objects.   This
  342.               is not generated by default.
  343.  
  344.        ttookkeennss..hh
  345.               output _#_d_e_f_i_n_e_s for tokens used and function proto-
  346.               types for functions generated for rules
  347.  
  348. SSEEEE AALLSSOO
  349.        dlg(1), pccts(1)
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. ANTLR                       April 1994                          6
  395.  
  396.  
  397.