Loading ...
Sorry, an error occurred while loading the content.

tree parser example PDF docs and ANTLR Patterns (was Re: the tree parser exampl)

Expand Messages
  • lgcraymer
    ... I think that your idea is good, but not quite on target. I think that the items you mention tend to have to do with grammar structuring (a catalog of
    Message 1 of 10 , May 7 2:08 PM
    • 0 Attachment
      --- In antlr-interest@y..., "jsrs701" <jsrs701@y...> wrote:
      > Speaking of medium-sized ANTLR projects, has anyone else thought
      > about putting together an ANTLR Patterns collection? A few that I'm

      I think that your idea is good, but not quite on target. I think that
      the items you mention tend to have to do with grammar structuring
      (a catalog of refactoring principles would be useful), rewriting, and
      interfacing to backend processors. These are all worthy topics. Some
      specifics follow.

      > thinking about, to whit:
      >
      > * Expression parsers with precedence

      This is a tree structuring issue, and the principle is "structure your
      grammar so that the syntax trees reflect operator precedence". The
      Calc examples demonstrate this.

      > * Successively applied tree parsers for optimization/transformation
      > sequences

      This is on applying rewrite rules for grammar transformation. There
      has been quite a bit of research on rewriting, and it would be
      interesting to interface the BURG (bottom up rewrite
      generator)algorithm with ANTLR to do the "match pattern and rewrite"
      approach to rule and tree transformation (as opposed to ANTLR's match
      rule and rewrite according to user annotations).

      BTW, I just received a letter that okays release of my rewriting
      support and tree grammar generation extensions under copyright. Now I
      have to find out what else I need to do to actually release it, but I
      can hope for an early June release. This is probably a good starting
      point for incorporating meta-level rewrite rules--the extensions
      generate a syntax tree for the output grammar from an input grammar.

      > * Text scanners (like Ter's "really big lookahead" article) vs...
      > * Compilers

      This is a matter of interfacing to a backend. An interesting start in
      this direction would be for someone to generate RTL from a transformed
      ANTLR syntax tree. Monty's GNU C grammar is much cleaner than the GNU
      C flex/bison (at least the gcc front end used to be a case of "abandon
      hope all ye who enter here"--I haven't looked at the source since a
      1.xx release) and an ANTLR C++ front end would be a major improvement.

      > * Interpreters

      I don't know of an interpreter written in ANTLR, although Ter has
      provided a few hooks for the purpose. It would be interesting to hear
      of any experiences with ANTLR in this area.

      >
      > What do people think?
      >
      > JSRS

      --Loring Craymer
    • Ruslan Zasukhin
      ... This will be great STEP for ANTLR. If continue this logic...I again want remind to Terr, that I was very disappointed by inheritance of ANTLR. When I
      Message 2 of 10 , May 7 2:21 PM
      • 0 Attachment
        on 5/7/02 23:04, jsrs701 at jsrs701@... wrote:

        > Speaking of medium-sized ANTLR projects, has anyone else thought
        > about putting together an ANTLR Patterns collection? A few that I'm
        > thinking about, to whit:
        >
        > * Expression parsers with precedence
        > * Successively applied tree parsers for optimization/transformation
        > sequences
        > * Text scanners (like Ter's "really big lookahead" article) vs...
        > * Compilers
        > * Interpreters
        >
        > What do people think?

        This will be great STEP for ANTLR.

        If continue this logic...I again want remind to Terr, that I was very
        disappointed by "inheritance" of ANTLR.

        When I have read about "inheritance" of grammar I was sure that I can have
        few grammars that extend one other (like C++ classes), and I was going to
        have

        grammar A
        -----> grammar B
        -----> grammar C

        All in one application. I did expect to see that ANTL will generate 3
        classes:


        class A_Parser
        class B_Parser : public A_parser
        class C_Parser : public A_parser

        Instead I have to see only B and C classes that just CONTAIN common part of
        A grammar :-(

        Terr, you need ... No, you MUST invent how produce classes as I above.

        Also will be great to have EASY way include that PATTERNS of grammar by
        simple "include" and later referencing of a root rule of pattern.


        --
        Best regards,
        Ruslan Zasukhin

        -------------------------
        Paradigma.

        e-mail: ruslan@...
        web : http://www.paradigmasoft.com

        To subscribe to the Valentina mail list
        send a letter to valentina-on@...
      • Terence Parr
        ... Ah...the inheritance is screwed up guy :) Howdy. Long time no chat. I think you ll find by my prior letters in this list that grammar inheritance
        Message 3 of 10 , May 8 8:39 AM
        • 0 Attachment
          On Tuesday, May 7, 2002, at 02:21 PM, Ruslan Zasukhin wrote:
          > If continue this logic...I again want remind to Terr, that I was very
          > disappointed by "inheritance" of ANTLR.

          Ah...the "inheritance is screwed up" guy :) Howdy. Long time no chat.

          I think you'll find by my prior letters in this list that grammar
          inheritance cannot operate exactly like class inheritance...i even made
          a FAQ entry:

          http://www.jguru.com/faq/view.jsp?EID=68255

          So you are bound to be disappointed if you don't realize what is going
          on. The crux of the problem is that if you, for example, modify what an
          expr is by subclassing then you necessarily modify the lookahead sets
          for a whole bunch of other rules. I MUST...repeat MUST reproduce this
          rule to have it's altered lookahead sets useful to your subclass. Rules
          whose sets do not change are also included because I was too busy to
          figure out which had changed ;)

          BTW, inheritance even in java is a fancy word for "include plus
          override", right? Just because you can see it happen in antlr shouldn't
          bother you at all.

          I trust this is the last we'll hear about this? ;)

          Terence

          > When I have read about "inheritance" of grammar I was sure that I can
          > have
          > few grammars that extend one other (like C++ classes), and I was going
          > to
          > have
          >
          > grammar A
          > -----> grammar B
          > -----> grammar C
          >
          > All in one application. I did expect to see that ANTL will generate 3
          > classes:
          >
          >
          > class A_Parser
          > class B_Parser : public A_parser
          > class C_Parser : public A_parser
          >
          > Instead I have to see only B and C classes that just CONTAIN common
          > part of
          > A grammar :-(
          --
          Co-founder, http://www.jguru.com
          Creator, ANTLR Parser Generator: http://www.antlr.org
        • Ruslan Zasukhin
          ... Hi Terr, ... I see your point, but 1) you mean that expr can be overridden in sub-grammar ? Or you mean that a sub-grammar ALWAYS change lookahed set? In
          Message 4 of 10 , May 8 9:44 AM
          • 0 Attachment
            on 5/8/02 18:39, Terence Parr at parrt@... wrote:

            > On Tuesday, May 7, 2002, at 02:21 PM, Ruslan Zasukhin wrote:
            >> If continue this logic...I again want remind to Terr, that I was very
            >> disappointed by "inheritance" of ANTLR.
            >
            > Ah...the "inheritance is screwed up" guy :) Howdy. Long time no chat.

            Hi Terr,

            > I think you'll find by my prior letters in this list that grammar
            > inheritance cannot operate exactly like class inheritance...i even made
            > a FAQ entry:
            >
            > http://www.jguru.com/faq/view.jsp?EID=68255
            >
            > So you are bound to be disappointed if you don't realize what is going
            > on. The crux of the problem is that if you, for example, modify what an
            > expr is by subclassing then you necessarily modify the lookahead sets
            > for a whole bunch of other rules. I MUST...repeat MUST reproduce this
            > rule to have it's altered lookahead sets useful to your subclass. Rules
            > whose sets do not change are also included because I was too busy to
            > figure out which had changed ;)

            I see your point, but

            1) you mean that expr can be overridden in sub-grammar ?
            Or you mean that a sub-grammar ALWAYS change lookahed set?

            In the first case you can PROHIBIT overridden.
            In the second you can try resolve task sending lookahead sets as parameter.

            > BTW, inheritance even in java is a fancy word for "include plus
            > override", right? Just because you can see it happen in antlr shouldn't
            > bother you at all.
            >
            > I trust this is the last we'll hear about this? ;)

            :-) I don't know.

            I was going to have simple Expr parser, and its subclass -- SQL parser.

            Of course I can use single C++ class, and use Expr() as entry point for the
            first parser....

            I just do not like possible repetition of code in case we really have
            several subclasses.


            --
            Best regards,
            Ruslan Zasukhin

            -------------------------
            Paradigma.

            e-mail: ruslan@...
            web : http://www.paradigmasoft.com

            To subscribe to the Valentina mail list
            send a letter to valentina-on@...
          • Terence Parr
            ... Both. By overriding you can change the lookahead of other rules. ... What s the point of subclassing if you can t override? ;) ... That is not always
            Message 5 of 10 , May 9 10:34 AM
            • 0 Attachment
              On Wednesday, May 8, 2002, at 09:44 AM, Ruslan Zasukhin wrote:
              > I see your point, but
              >
              > 1) you mean that expr can be overridden in sub-grammar ?
              > Or you mean that a sub-grammar ALWAYS change lookahed set?

              Both. By overriding you can change the lookahead of other rules.

              > In the first case you can PROHIBIT overridden.

              What's the point of subclassing if you can't override? ;)

              > In the second you can try resolve task sending lookahead sets as
              > parameter.

              That is not always possible because I often encode sets in raw java like
              LA(1)==IDENT for efficiency. You are suggesting a more interpreted
              model which would easily work, but would be slower.

              >> BTW, inheritance even in java is a fancy word for "include plus
              >> override", right? Just because you can see it happen in antlr
              >> shouldn't
              >> bother you at all.
              >>
              >> I trust this is the last we'll hear about this? ;)
              >
              > :-) I don't know.
              >
              > I was going to have simple Expr parser, and its subclass -- SQL parser.
              >
              > Of course I can use single C++ class, and use Expr() as entry point for
              > the
              > first parser....
              >
              > I just do not like possible repetition of code in case we really have
              > several subclasses.

              Unless you are deploying on a small device, it can't possibly matter if
              I replicate some code, can it?

              Ter
              > --
              Co-founder, http://www.jguru.com
              Creator, ANTLR Parser Generator: http://www.antlr.org
            Your message has been successfully submitted and would be delivered to recipients shortly.