comp.lang.ada
 help / color / mirror / Atom feed
* Stack Overflow when Pyparsing Ada 2005 Scoped Identifiers using Reference Manual Grammar
@ 2013-03-21  8:04 per.nordlow
  2013-03-21 12:55 ` Lucretia
  0 siblings, 1 reply; 2+ messages in thread
From: per.nordlow @ 2013-03-21  8:04 UTC (permalink / raw)


I'm currently implementing an Ada 2005 parser using Pyparsing and the reference manual grammar rules. We need this in order to analyze and transform parts of our aging Ada-codebase to C/C++.

Most things work.

However, one little annoying problem remains:

The grammar rule name when parsing scoped identifiers (rule selected_component) such as the expression "Global_Types.Integer2" fails because it is part of a left-associative grammar rule cycle.

Pyparsing infinite recursion and Python spits out maximum recursion depth exceeded.

I believe the problem is caused either by the fact that

•the associativity of the grammar rule selected_component is right-to-left. I've search the reference manual of Pyparsing but haven't found anything relevant. Should we treat dot (.) as an operator with right-to-left associativity or can we solve it throught extensions and restructurings of the grammar rules?

•or by the fact that there is no check in Pyparsing infinite recursions. I believe this wouldn't be too hard to implement. Use a map from currently active rules (functions) to source position/offset (getTokensEndLoc()) and always fail a rule if the current source input position/offset equals the position related to the rule just entered.

The problem also seems closely related to

"Need help in parsing part of python grammar": http://pyparsing.wikispaces.com/message/view/home/51617848

which unfortunately doesn't have answers yet.

Also see this thread

http://stackoverflow.com/questions/15438015/stack-overflow-when-pyparsing-ada-2005-scoped-identifiers-using-reference-manual?noredirect=1#comment22014663_15438015

Thanks in advance,
Per Nordlöw



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Stack Overflow when Pyparsing Ada 2005 Scoped Identifiers using Reference Manual Grammar
  2013-03-21  8:04 Stack Overflow when Pyparsing Ada 2005 Scoped Identifiers using Reference Manual Grammar per.nordlow
@ 2013-03-21 12:55 ` Lucretia
  0 siblings, 0 replies; 2+ messages in thread
From: Lucretia @ 2013-03-21 12:55 UTC (permalink / raw)


On Thursday, 21 March 2013 08:04:46 UTC, per.n...@gmail.com  wrote:
> The grammar rule name when parsing scoped identifiers (rule selected_component) such as the expression "Global_Types.Integer2" fails because it is part of a left-associative grammar rule cycle.

You'll need to remove left recursion by refactoring the grammar or adjusting it so that the rule accepts names with dots in it, then process the name matching to split it into component parts.

Luke.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-21 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-21  8:04 Stack Overflow when Pyparsing Ada 2005 Scoped Identifiers using Reference Manual Grammar per.nordlow
2013-03-21 12:55 ` Lucretia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox