help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Delaying activation of actions


From: Frans Englich
Subject: Delaying activation of actions
Date: Tue, 13 Feb 2007 14:32:48 +0100
User-agent: KMail/1.9.1

Hello all,

I have a design problem that I don't know how to solve, so any pointer would 
be highly appreciated!

The problem is that is that in a parser for pseudo-XML, I need to delay the 
lookup of certain names, to after all namespace declarations has been parsed. 
Here's an example:

<e attribute="{p:herePrefixPisUsed}" 
xmlns:p="http://example.com/HerePrefixPisDeclared"/>

As can be seen, "xmlns:p" appears after "p:herePrefixPisUsed".

The problem is that the parser operates sequentially, and attempts to resolve 
"p" inside "p:herePrefixPisUsed", but since "xmlns:p" hasn't been encountered 
yet, it doesn't know about it, and hence fails.

One way to solve this, is to delay all name resolution, such that it's done as 
a separate AST pass, after all parsing has been done. I would prefer to not 
do it this way, because it's messy in my implementation!

So can one do this somehow on the parser level, with bison?

I'm thinking about something like this:

1. When the start of attributes starts, set skipNameResolution to true
2. When any name needs to be resolved and skipNameResolution is true, it does 
nothing
3. When reaching the end of the attributes, skipNameResolution is set to 
false, and the parser re-parses from the beginning of the attributes. Since 
the namespace declarations were read in the previous pass, name resolution 
will work.

Now, I couldn't find any Bison feature offering that, but can anyone think of 
a way to do it, or possibly some another way?

Another possibility could perhaps be to make the parser a GLR parser, force an 
ambiguity at the beginning of attributes, somehow get actions for namespace 
declarations applied, and resolve the ambiguity at the end of the attributes.

So, any creative solutions are welcome!


Cheers,

                Frans




reply via email to

[Prev in Thread] Current Thread [Next in Thread]