Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2337

Re: Regular expressions in lexing and parsing

From Quinn Jackson <quinn.jackson@ieee.org>
Newsgroups comp.compilers
Subject Re: Regular expressions in lexing and parsing
Date 2019-06-18 11:56 -0700
Organization Compilers Central
Message-ID <19-06-008@comp.compilers> (permalink)
References <19-06-005@comp.compilers>

Show all headers | View raw


On Tue, Jun 18, 2019 at 10:09 AM Christopher F Clark
<christopher.f.clark@compiler-resources.com> wrote:
>
> Hans-Peter Diettrich <DrDiettrich1@netscape.net> wrote:
>
> > I think that regular expressions are primarily usable in *formal* token
> > grammars. In contrast to parsers I'm missing *complete* formal grammars
> > for the tokens, including whitespace, comments, strings and other
> > special language elements, and how these fit together.

To which Christopher F Clark
<christopher.f.clark@compiler-resources.com> responded in part:

> I definitely would not discount the use of formal grammars both for
> lexing (i.e. formal regexes) and parsing and the use of tools.
> When we did Yacc++, we specifically made our lexer syntax look like
> our parser syntax (and used LR yacc-style productions extended with
> regular expressions on the right hand side) to make the notation
> formal, regular, and simple.  I would call that one of our successes.

When it comes to adaptive grammars, since the terminal and
non-terminal sets can have items added and removed dynamically during
a parse, it makes a lot of sense to treat lexing and parsing as one
and the same thing. I would add that even AST traversal and decoration
can be included in this family, in practice. Treating them
orthogonally is, in my experience, less useful overall. It also makes
it much simpler in practice to read such grammars at their level of
intent.

Pertinent to Hans-Peter's quote above: right down to the whitespace is
a good thing. Especially when parsing something other than a recent
computer language, such as -- oh, I don't know -- English or some
other Natural Language. (Outside the scope of the margins of this
list, however.)

> So, if someone were to seriously argue against formal grammars (and
> formal lexing specs too), I would challenge them to prove their
> contentions.

I echo Chris's challenge.

> I will let someone else have the soapbox now....

Be careful what you wish for. ;-)

--
Quinn Jackson CSci MIScT SMACM SMIEEE FRSA

LinkedIn:           http://ca.linkedin.com/in/quinnjackson/
ResearchGate: http://researchgate.net/profile/Quinn_Jackson/
[I agree with the sentiment to use formal grammars for both lex and
parse, but it always has seemed to me that running them separately as
coroutines makes it easier to deal with comments and whitespace
without having to hang them on every token definition.  I realize that
the more context sensitive the language, the more it is likely to make
sense to combine them. -John]

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Regular expressions in lexing and parsing Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2019-06-17 08:37 -0400
  Re: Regular expressions in lexing and parsing Quinn Jackson <quinn.jackson@ieee.org> - 2019-06-18 11:56 -0700
    Re: Regular expressions in lexing and parsing Quinn Jackson <quinn.jackson@ieee.org> - 2019-06-18 12:57 -0700
    Re: Regular expressions in lexing and parsing Kaz Kylheku <847-115-0292@kylheku.com> - 2019-06-18 20:01 +0000
  Re: Regular expressions in lexing and parsing Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2019-06-18 18:43 -0400

csiph-web