home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!gatech!concert!sas!mozart.unx.sas.com!sasghm
- From: sasghm@theseus.unx.sas.com (Gary Merrill)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Grammar
- Message-ID: <BuKq65.Cx7@unx.sas.com>
- Date: 14 Sep 92 15:10:52 GMT
- References: <Bu07v4.F66@csfb1.fir.fbc.com> <1992Sep6.232016.6573@cssc-syd.tansu.com.au> <BuD9Lx.JoD@unx.sas.com> <1992Sep12.021515.23609@cs.brown.edu>
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Organization: SAS Institute Inc.
- Lines: 48
- Originator: sasghm@theseus.unx.sas.com
- Nntp-Posting-Host: theseus.unx.sas.com
-
-
- In article <1992Sep12.021515.23609@cs.brown.edu>, ted@cs.brown.edu (Tony Davis) writes:
- |>
- |> Another common approach to parsing C++ with yacc is to make
- |> the lexicl analyzer more powerful. With this approach yacc
- |> can indeed be used to parse non-LR(k) languages. Granted,
- |> this might be called cheating since the lexical analyzer is
- |> doing enough parsing so that the language that the yacc portion
- |> of the system must parse IS now LR(k). Strictly speaking
- |> yacc does not parse a non-LR(k) language, but the parser as
- |> a whole does.
-
- This is either inaccurate or misleading (touche!). The lexical
- analyzer of course doesn't do the parsing. It does the lexical
- analysis -- which in this case means, among other things, the
- determination/insertion of artificial tokens. It may call a
- parser in order to make this determination.
-
- |> A C++ parser that one of my advisors has recently produced takes
- |> this approach. The lexer does look ahead to produce artificial
- |> tokens which yacc uses as ques to yield a correct parse (modulo
- |> any bugs that remain in the system). Soon I will be making that
- |> parser available for ftp. When it becomes available I will
- |> announce it here.
-
- I'm sure we all use basically the same technique here (whether
- the underlying parser is yacc-based or recursive descent). I do,
- nonethless, look forward to seeing how someone else has done this.
- Note, however, that in any case -- if the parsing is ultimately
- done correctly -- then either yyparse() must be called recursively
- as part of the lookahead process or some other method (recursive
- descent, for example) must be used in the "local" or "trial" parses
- necessary to determine what (if any) artificial token to insert.
- My changes to yacc include the recursive callability of yyparse(),
- a distinction between conditional and unconditional actions, a
- simple type of reduction tracking, and optimized dynamically allocated
- parser stacks. These are all relatively simple modifications to
- the code. Actually, quite a bit of work needs to go into the
- buffering of tokens and into error detection/recovery and diagnostics.
-
- Again, after going through this, I would advise anyone starting
- from scratch to use a recursive descent parser since I feel that
- it offers advantages in the areas of diagnostics, recovery, and
- maintainability.
- --
- Gary H. Merrill [Principal Systems Developer, C Compiler Development]
- SAS Institute Inc. / SAS Campus Dr. / Cary, NC 27513 / (919) 677-8000
- sasghm@theseus.unx.sas.com ... !mcnc!sas!sasghm
-