Re: Parsing implicit operators with recursive descent?

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Sat, 7 Feb 2009 16:47:48 +0100

          From comp.compilers

Related articles
Parsing implicit operators with recursive descent? johann@myrkraverk.com (Johann 'Myrkraverk' Oskarsson) (2009-02-06)
Re: Parsing implicit operators with recursive descent? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2009-02-07)
Re: Parsing implicit operators with recursive descent? armelasselin@hotmail.com (Armel) (2009-02-07)
Re: Parsing implicit operators with recursive descent? torbenm@pc-003.diku.dk (2009-02-09)
Re: Parsing implicit operators with recursive descent? barry.j.kelly@gmail.com (Barry Kelly) (2009-02-12)
Re: Parsing implicit operators with recursive descent? johann@myrkraverk.com (Johann 'Myrkraverk' Oskarsson) (2010-01-30)
Re: Parsing implicit operators with recursive descent? kkylheku@gmail.com (Kaz Kylheku) (2010-02-01)
| List of all articles for this month |

From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: Sat, 7 Feb 2009 16:47:48 +0100
Organization: cbb software GmbH
References: 09-02-013
Keywords: parse, LL(1)
Posted-Date: 07 Feb 2009 12:56:34 EST

On Fri, 06 Feb 2009 02:34:56 +0000, Johann 'Myrkraverk' Oskarsson wrote:


> That is, to be explicit, is it possible to make a recursive descent
> parser that produces (*) the following parse tree on this input "aab":
>
> @
> / \
> @ b
> / \
> a a
>
> Where @ is the implicit concatenation operator?


Yes, it is possible. There are two techniques I m using:


1. When a table of tokens expected in the infix operation context does not
match the input, a "missing operation" handler is called. This handler
emulates some default operation. It can be "multiply" or "catenation" as in
the case of pattern expressions.


2. Simply put an empty token into the table of infix operations (*). This
approach is straightforward, but it will require "missing operand" handler
that would discard always matched empty token when that was recognized at
the expression end. Usually I have also some context check that verifies
matched tokens not to break some rules. For example "ab" is not accepted
when found in "abcdef," but accepted when found in "ab(1)" etc. Such checks
can be deployed here to avoid empty token match at the expression end.


--------------------------------------
* I do not tokenize the source, this makes dealing things like empty tokens
a lot easier. Token tables are matched directly against the source.


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.