Re: Good explanation of Recursive Ascent Parsing wanted

Kaz Kylheku <864-117-4973@kylheku.com>
Thu, 29 Sep 2022 22:32:10 -0000 (UTC)

          From comp.compilers

Related articles
Good explanation of Recursive Ascent Parsing wanted aaronngray@gmail.com (Aaron Gray) (2022-09-28)
Re: Good explanation of Recursive Ascent Parsing wanted 864-117-4973@kylheku.com (Kaz Kylheku) (2022-09-29)
Re: Good explanation of Recursive Ascent Parsing wanted aaronngray@gmail.com (Aaron Gray) (2022-09-29)
Re: Good explanation of Recursive Ascent Parsing wanted 864-117-4973@kylheku.com (Kaz Kylheku) (2022-09-29)
Re: Good explanation of Recursive Ascent Parsing wanted anton@mips.complang.tuwien.ac.at (2022-09-30)
Re: Good explanation of Recursive Ascent Parsing wanted johann@myrkraverk.invalid (Johann 'Myrkraverk' Oskarsson) (2022-09-30)
Re: Good explanation of Recursive Ascent Parsing wanted antispam@math.uni.wroc.pl (2022-10-06)
Re: Good explanation of Recursive Ascent Parsing wanted 864-117-4973@kylheku.com (Kaz Kylheku) (2022-10-07)
| List of all articles for this month |

From: Kaz Kylheku <864-117-4973@kylheku.com>
Newsgroups: comp.compilers
Date: Thu, 29 Sep 2022 22:32:10 -0000 (UTC)
Organization: A noiseless patient Spider
References: 22-09-018 22-09-019 22-09-020
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="70197"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, yacc
Posted-Date: 29 Sep 2022 20:25:33 EDT

On 2022-09-29, Aaron Gray <aaronngray@gmail.com> wrote:
> Kaz, Oh this sounds potentially very efficient, thank you, I will have
> a serious play and see if I can get this to work !


If you look at how Yacc programs typically work: they use goto anyway.


The reason I say this is that the parser actions all get compiled into
one big yyparse() function, right into its body, and end up as targets
of the labels of a switch() statement, or possibly gotos.


It's just that the gotos are computed, with the help of the parser
tables.


So basically what you're doing is eliminating the computed goto; instead
of changing some state variable and returning to the top of a loop to
switch on it, you just jump to the destination directly.


I think there are still situations where a computed goto is inevitable.
The LALR parser is a push-down automaton: where the LR(0) items form the
basic state transitions for recognizing the regular language of the
senential patterns. This is augmented by the stack to handle
the recursion in the grammar.


When reductions occur and the stack is popped, it is not statically
known which state the machine will end up in; so there cannot tbe
a hard coded goto or tail call. This is because the same phrase
structure, e,g, "expression" can occur in multiple contexts.


So here, the goto-based or tail-recursion-based implementation still
requires a computed goto. Thus in C a switch statement would be
used, or the GNU C computed labels; or else if tail calls are used,
then perhaps function pointers could be pushed into the stack.


I'm not looking at this at the required level of detail, but my
intuition for the problem space affords me a modicum of assurance. :)


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal



Post a followup to this message

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