Polymorphism in Pattern Matching

"Quinn Tyler Jackson" <the_artful_parser@null.net>
25 Jan 1997 22:18:04 -0500

          From comp.compilers

Related articles
Polymorphism in Pattern Matching the_artful_parser@null.net (Quinn Tyler Jackson) (1997-01-25)
| List of all articles for this month |

From: "Quinn Tyler Jackson" <the_artful_parser@null.net>
Newsgroups: comp.compilers
Date: 25 Jan 1997 22:18:04 -0500
Organization: Parse City
Keywords: parse


I recently released a C++ class library called "Laleh's Pattern
Matcher". (Version 1.0 available at my homepage.)

I am currently preparing to work on a paper describing the next
generation of LPM -- a polymorphic version of the system -- and
invite any comment on the following model, which is now behaving in
the lab as follows:


    void run_polymorphic_lpm_test

        // The following, expressed as an RE, would be [a-z]+

        CLpmCompiler parent_pattern("[+'a-z'#");

        // The following macro <literal(ARG)> expands to ['ARG'$.
        // The macro is scoped to the pattern pattern:

        eLpmState ec = (eLpmState)0;
        CLpmMacroTable mt;
        mt.Add("literal", "ARG", "['{ARG}'$", ec);

        // A child pattern is created. Since the constructor points
        // to another pattern, this child inherits the behavior of
        // its parent:

        CLpm child_pattern(&parent_pattern);

        // A new pattern is created. Note that the macro <literal()>
        // cannot be resolved at the child level, and is only
        // resolved by looking at our parent. Thus, the macro def
        // is inherited:

        child_pattern = "<literal(dog)>"; // expands to ['dog'$

        if(child_pattern.Match("123 dog"))
            PRINT("Match Starts: " << child_pattern.HitStart());
            PRINT("Match Length: " << child_pattern.MatchLength());
        } // if

        // In the previous match, the child rule ['dog'$ is only applied
        // to those regions of the stream that first match the parent
        // rule [+'a-z'#. This is referred to in Francoise Balmas'
        // doctoral thesis as multistep matching. The idea is to
        // pre-filter using the least expensive patterns, reserving
        // the more expensive patterns for those situations where their
        // expense is called for.



Has anyone seen such a use of inheritance in declarative languages?

In my paper, which elements of the system do you feel ought to be
described (if any)? I can think of practical uses for OO-LPM, but I
may be unique in this conviction.

Quinn Tyler Jackson

Post a followup to this message

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