Re: Design Patterns and Functional programming
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Sun, 8 Jul 2007 20:58:52 +0200
On Sun, 08 Jul 2007 18:35:51 +0100, Jon Harrop wrote:
Dmitry A. Kazakov wrote:
How do you add that to the object oriented design?
No problem actually. You first derive from abstract expression an abstract
infix operation (that is - two arguments one result) and then specialize
it to concrete operation.
Could you post working code for that design, please?
http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc
It contains a complete sample for building parsing trees of Ada 95 infix
expressions with all bells and whistles.
BTW, in a real compiler you won't have them in the form you have proposed.
Most compilers written in Standard ML, Haskell or OCaml use this form.
Indeed, this carries through to machine code generation as the machine
itself doesn't implement n-ary addition.
Yes, but you definitely wanted to fold constants in expressions like 1+a+2.
How do you add precedence to your design?
Precedence is implemented the same way in the functional and OO styles. For
programmatic construction, it is inherited from the use of infix operators.
But your idea was to map that onto some [functional] language constructs,
which apparently do not take care of.
[...]
What would the equivalent be in an object oriented design?
Follow the link I have provided. The focus of the design was to avoid
hard-coded grammar. Therefore decomposition goes along different lines. It
is operations, arguments, sources and parsers. The approach is
table-driven, that is - lexical elements, like infix operations, their
precedence are defined dynamically. Static are only the classes of, like
operator, bracket, comma, ligature. This gives you the operation and
argument stack objects in a fully generic way.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.
- Follow-Ups:
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- References:
- Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: H. S. Lahman
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Daniel T.
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Re: Design Patterns and Functional programming
- From: Dmitry A. Kazakov
- Re: Design Patterns and Functional programming
- From: Jon Harrop
- Design Patterns and Functional programming
- Prev by Date: Re: Design Patterns and Functional programming
- Next by Date: Re: Design Patterns and Functional programming
- Previous by thread: Re: Design Patterns and Functional programming
- Next by thread: Re: Design Patterns and Functional programming
- Index(es):