dcsimg
can't run parser before main()
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ronnie_Maor
Posted On:   Saturday, June 30, 2001 07:37 AM

This FEATURE REQUEST is relevant for the C++ code generator. I needed to use an ANTLR generated parser from some registration code, which typically runs before main(). The problem was that ANTLR uses some static members of type antlr::BitSet. The constructors for these members are not guaranteed to be called at any point before main(), and in fact were not called yet, so that parser failed. I used the option codeGenBitsetTestThreshold=999; to disable the bitsets, which made the parser safe to run before main(). My problem is that I have no guarantee that the next version of ANTLR will not make this solution impossible (add other static members, for example).    More>>

This FEATURE REQUEST is relevant for the C++ code generator.



I needed to use an ANTLR generated parser from some registration code, which typically runs before main().
The problem was that ANTLR uses some static members of type antlr::BitSet. The constructors for these members are not guaranteed to be called at any point before main(), and in fact were not called yet, so that parser failed.


I used the option

codeGenBitsetTestThreshold=999;

to disable the bitsets, which made the parser safe to run before main().


My problem is that I have no guarantee that the next version of ANTLR will not make this solution impossible (add other static members, for example).


Could this be fixed? (you could make the BitSets non-static, or use an active singleton or similar method to make sure they are constructed before they are called). This could be done generally or with an option.

Anyway, I would like a dependable way to build a parser that can be run before main().


thanks,

Ronnie

   <<Less

Re: can't run parser before main()

Posted By:   Ric_Klaren  
Posted On:   Monday, July 2, 2001 01:26 AM


> I needed to use an ANTLR generated parser from some registration code, which typically runs before

> main().

Pretty hairy construct I must say...

> I used the option codeGenBitsetTestThreshold=999;

> to disable the bitsets, which made the parser safe to run before main()

That works yeah. The bitsetthreshold options are afaik not expected to change.
In the new version a one or two new static members
are generated (int typed so that should not be a problem)

I must say that I'm not very enthusiastic about fixing this.
If it goes on my list of things to fix it will
probably be at the bottom regions.

Of course if you submit a patch that makes this an option
And it does not riddle the code with lots of specialcase
checks, then I'll probably incorporate it.

> I would like a dependable way to build a parser that can be run before main().

Using a C++ parser before main is hairy bussiness,
you might get breakage from the STL (or other sources)
on other platforms/compilers and other
maintenance nightmares.
IMHO this solution is built to break.

With some compilers you can find out the
symbols/functions that do these constructions.
Gcc being one (I don't have a direct pointer it would
be on their mailinglists somewhere (or on libstdc++'s).
With help of those you could manually ensure that
stuff is constructed. (but again leads to
hackery)

You might write a postprocessor for antlr's code
that 'unstatics' stuff. Depending on knowledge of
perl/tcl this might be the fastest fix.

Cheers,

Ric

About | Sitemap | Contact