Related articles |
---|
Polymorphism in Pattern Matching the_artful_parser@null.net (Quinn Tyler Jackson) (1997-01-25) |
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 |
Hello!
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:
=== CODE EXAMPLE FOLLOWS ===
void run_polymorphic_lpm_test
(
void
)
{
// 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);
parent_pattern.RegisterMacroContext(mt);
// 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.
Cheers,
Quinn Tyler Jackson
--
the_artful_parser@null.net
http://mypage.direct.ca/q/qjackson/
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.