Re: Parser question

Aeran <avron2006b@yahoo.com>
Sun, 13 Jul 2008 11:33:06 GMT

          From comp.compilers

Related articles
Parser question mike@sesamgames.com (Mike \(News\)) (2008-07-11)
Re: Parser question avron2006b@yahoo.com (Aeran) (2008-07-13)
Re: Parser question max@gustavus.edu (Max Hailperin) (2008-07-13)
Re: Parser question DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-07-15)
Re: Parser question mikael@sesamgames.com (Mikael =?ISO-8859-1?Q?Str=F6m?=) (2008-07-17)
Re: Parser question max@gustavus.edu (Max Hailperin) (2008-07-19)
| List of all articles for this month |
From: Aeran <avron2006b@yahoo.com>
Newsgroups: comp.compilers
Date: Sun, 13 Jul 2008 11:33:06 GMT
Organization: Telia Internet
References: 08-07-024
Keywords: parse
Posted-Date: 15 Jul 2008 01:31:17 EDT

You probably want to identify tail recursion. If nothing is built up on
the stack while recursing it is possible to avoid the recursive call. If
you have a grammar like: a -> Ba|N then you can when implementing the
parser instead of writing it like:
sub a()
    matchB
    if (look == 'N') matchN else a()
end sub


You could write it like this:
sub a()
      loop forever
          matchB
          if (look == 'N')
                matchN
                break out from loop


You can also avoid doing a procedure call for every nonterminal. The
grammar you wrote above you could fit into one procedure:


sub expr
      term()
      if (look == '+')
          match+
          term()
        elseif (look == '-')
          match-
          term()


The above procedure cover both expr and moreterms.


Post a followup to this message

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