[fpc-devel] rebuilding source form passrc parser token tree

Graeme Geldenhuys graemeg.lists at gmail.com
Sat Aug 21 13:30:41 CEST 2010


I'm working on a project where I parse source code, then use the token
tree to modify the source code, and write new units out again.

I found a few limitation in fcl-passrc which prevents rebuilding
source code from a token tree, but it was easy to fix by introducing a
few new tokens. I'll submit a patch for this on Monday.

Anyway, while working with fcl-passrc I noticed something really
strange. The token list is in reverse order! Why is that?  So to
insert for instance a new uses clause in the Interface section, I have
to do something like this:

  for i := tokenlist.Count-1 downto 0 do
     if tokenlist[i].token = tkUses then

Otherwise it finds the Implemenation section's uses clause first.
It's not hard to work with it like this (if you know about it), I just
find it odd and wondered if there is any technical reason why the
token tree is in reverse.

  - Graeme -

fpGUI - a cross-platform Free Pascal GUI toolkit

More information about the fpc-devel mailing list