Using antlr for kdev4

Andreas Pakulat apaku at
Fri Dec 1 11:15:41 UTC 2006

On 30.11.06 21:20:31, Matt Rogers wrote:
> Andreas Pakulat wrote:
> > Hi,
> > 
> > as my first attempts with Flex/Bison for the qmake parser in KDevelop4
> > weren't very successfull I had a look at antlr.
> > 
> > Writing a Parser and Lexer for variable assignments was pretty easy with
> > antlr and the syntax to write the lexer and parser suits me better than
> > the one of bison. Especially being able to use *,? and co within parser
> > rules (or does bison allow for that? I did not read its huge manual, so
> > I might not know yet).
> > 
> > My first simple grammar couldn't build a AST, due to a segfault
> > somewhere in the generated code. But we do get C++ classes for the Lexer
> > and the Parser which allows to easily parse parts of a qmake project
> > file.
> > 
> > I also see that kdevelop3 used antlr for some of its language supports,
> > so I am asking what the optinions of the other kdev4 developers are
> > about using antlr for the qmake parser?
> > 
> > Andreas
> > 
> Don't we already have a QMake parser in KDevelop 3.4? What's wrong with 
> using and adapting that?

Because it can't really parse qmake projects. It doesn't regocnize
nested function calls like

foobar( somearg, $$otherfunc( somearg ) )

for that we get a function call foobar with an argument string
containing the rest. I also can't parse the | Operator that qmake

As for adapting: That's not possible without basically rewriting the
parser and the lexer. And as I pointed out, flex/bison are really giving
me headaches - which probably only means that I can't quite "think" in
LALR grammar...

> I also assume that you've looked at using KDevelop-PG as well. Although 
> Jakob says he's argued against it, I don't recall the conversation.

The biggest problem with kdev-pg is, that the AST it generates doesn't
allow for modifications, which means I'd have to think about other ways
to change the project file. If I understood adymo correctly he mentioned
that we could use the AST to get the proper position where to insert a
new variable (or anything else) and then insert directly into the file.
This would of course mean having to reparse on every change to a file
and possibly also reparse the subprojects...

> I'm totally for using the best tool for the job, but the amount of 
> dependencies KDevelop has/will have is starting to bug me a bit. Are you 
> planning on eliminating the need to use antlr at build time?

Thats not really possible, although one doesn't need the antlr
executable. However the library or better their headers are needed to

What I absolutely don't know atm is if we then get a runtime-dependecy
on libantlr or not, because I'm not sure wether I can link a shared lib
into the parser lib and make it a static lib at the end (which doesn't
need the shared lib anymore).

Just in case you didn't notice: I'm also not very happy with KDev4
getting another build-time-dependecy, I may give flex/bison another try
this weekend...


Your life would be very empty if you had nothing to regret.

More information about the KDevelop-devel mailing list