First I'll say I know very little about the inner workings of an actual compiler. I took a course on formal language theory ages ago so I do have some understanding of the theory. Lately my interests have been pulling me toward projects that either benefit from or depend on static analysis. So I'm finding myself in need of a parser for object pascal. I'm wondering if fpc exposes any of the output (syntax trees, graphs, etc) from the parser that could be consumed by an external tool?
Mailing lists / fpc-pascal / 2012-08
Access to compiler's internal data structures
9 messages · 6 people · –
- KKenneth Cochran 2
- MMichael Van Canneyt 2
- SSven Barth 2
- BBernd 1
- GGraeme Geldenhuys 1
- 印印場 乃亜 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Kenneth Cochran wroteSo I'm finding myself in need of a parser for object pascal.
The FPC compiler has it's own built-in parser that is optimised for its needs. There is a more general purpose object pascal compiler included in FCL (part of FPC too), in the 'fcl-passrc' directory. The 'fpdoc' tool uses it, and I think a few others too.
Graeme.
First I'll say I know very little about the inner workings of an actual compiler. I took…
2012/8/31 Kenneth Cochran :
I'm finding myself in need of a parser for object pascal. I'm wondering if fpc exposes any of the output (syntax trees, graphs, etc) from the parser that could be consumed by an external tool?
Depending on what exactly you need and how difficult it is to get a syntax tree from the compiler itself there exist at least two more parsers that *might* be useful for you: one of them is in the CodeTools package in Lazarus and is used for autocomplete, refactoring, etc and another totally separate parser is in the Jedi code formating package (also part of Lazarus) that is used for re-formatting the code of a single unit.
These parsers were written with different goals in mind and for different purposes, so they work slightly different and provide different output, for example the jedi parser will only parse one unit (and is not very closely connected with the IDE and can probably easily be ripped out of it and be used in a separate project) while the codetools parsers are able to follow used units, include files, respect currently active defines, etc. but are deeply integrated into the IDE and probably also depending on many parts of he IDE.
If the project you have in mind would be something that helps coding or understanding and analyzing existing code it might probably be very nice to have it available as a part of the Lazarus IDE (as an installable package) and let it extend the CodeTools parsers.
First I'll say I know very little about the inner workings of an actual compiler. I took…
Kenneth Cochran wroteFirst I'll say I know very little about the inner workings of an actual compiler. I took a course on formal language theory ages ago so I do have some understanding of the theory. Lately my interests have been pulling me toward projects that either benefit from or depend on static analysis. So I'm finding myself in need of a parser for object pascal. I'm wondering if fpc exposes any of the output (syntax trees, graphs, etc) from the parser that could be consumed by an external tool?
Fpc's fcl-passrc package gives you a parser that produces an abstract syntax tree of the units that have been parsed. (pparser, pastree units)
There are people that use this to analyse their code. It is used to create webservices from existing interfaces. The documentation is produced from the abstract syntax tree.
Maybe it is useful for your purposes as well.
Michael.
First I'll say I know very little about the inner workings of an actual compiler. I took…
Kenneth Cochran wrote 7 lines
While the responses of the others are all good and well your original questions wasn't answered: no, the compiler does not provide such a possibility.
Regards,
Sven
Sven Barth wrote 12 lines
Though you could take a look at the tree.log provided when you add the option "-vp". But be warned: this output is only intended for debugging and its structure can change from one revision to the next without warning.
Regards,
Sven
2012/8/31 Kenneth Cochran : Depending on what exactly you need and how difficult it is to…
My goal is to make it an IDE expert so the CodeTools parser sounds ideal. Just didn't want to reinvent the wheel. I also wanted to avoid the problem Delphi has been plagued with for years, that is, CodeInsight flagging code with syntax errors that the compiler readily accepts because they use different parsers.
"Bernd" wrote 32 lines
Kenneth Cochran wroteMy goal is to make it an IDE expert so the CodeTools parser sounds ideal. Just didn't want to reinvent the wheel. I also wanted to avoid the problem Delphi has been plagued with for years, that is, CodeInsight flagging code with syntax errors that the compiler readily accepts because they use different parsers.
You'll still be plagued with that, since the codetools are not the same as the compiler ? (although they come close)
Michael.
First I'll say I know very little about the inner workings of an actual compiler. I took…
Hi,
I am sure the ones included in FCL are much fancier and know OOP, etc. I have a relatively primitive one used here too:
https://github.com/GalapagosAdmin/PasViz
I just use it for analyzing unit dependencies, so I don't need too many fancy features. Also, I didn't write the parser, and it is a bit out of date - I would like to modernize it, but free time is elusive these days. Also, if you like this one, I do have a newer version of the parser from the original author, which I haven't integrated into the project above yet. Obviously, it's open source, so I can share it with you if you like.
Thank you,
Noah Silva
Kenneth Cochran wroteFirst I'll say I know very little about the inner workings of an actual compiler. I took a course on formal language theory ages ago so I do have some understanding of the theory. Lately my interests have been pulling me toward projects that either benefit from or depend on static analysis. So I'm finding myself in need of a parser for object pascal. I'm wondering if fpc exposes any of the output (syntax trees, graphs, etc) from the parser that could be consumed by an external tool? _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
