[fpc-devel] Alternative parsers

Hans-Peter Diettrich DrDiettrich1 at aol.com
Thu Oct 21 13:23:38 CEST 2010


Marco van de Voort schrieb:

>> Still, C would be doable, for porting SOME existing code to co-operarate 
>> directly with pascal code. If the C code uses lots of library calls it can't 
>> be used directly. But, there is code for math and compression etc. which don't 
>> call libraries much.
> 
> The implementation is much easier I guess yes. But the interoperability
> remains the same. You still won't be able to access C headers directly from
> Pascal.

Why not?

When currently the compiler searches for .pas and .pp units, in order to 
evaluate a Uses or Requires clause, a future version could search for .c 
and .h files as well.


> Moreover I think the goals of such project can be much easier accomplished
> by having a C compiler that outputs (FPC) pascal source.

Why do you think that this way would be easier? I've already implemented 
such an compiler, in Delphi, so that it will not be a big deal to use 
its front-end. Remains to connect it to the FPC internal data structures 
and API.

The separated approch has the drawback that a recompilation of every 
update of the C sources is required, i.e. that compiler must become part 
of the build process (Makefiles...).

The readability of the generated files is questionable, and eventual 
manual post-processing (e.g. typing int parameters into sets or enums) 
is required after every recompilation. Workarounds have to be used for C 
elements, which do not map straight to Pascal elements. Such workarounds 
can be eliminated in a direct translation into nodes and other internal 
data structures.



>> Languages like ADA, Modula (and Fortran ? and Basic ? ) would be
>> realistic.
> 
> Modula2 is a special case since very related to Pascal. It needs some work
> in the module handling (but that work can be recycled for other pascal
> dialects that were inspired by that, like ISO Pascal too), but the main
> problem is the lexer/parser, because M2 is case sensitive and has a
> different block structure (which goes beyond merely being a pascal dialect).

I like just that different block structure, because it eliminates any 
fruitless discussion about the placement of the no more required Begins :-)

Case sensitivity can be subject to an mode switch, and the compiler can 
at least warn about conflicting declarations in case-insensitive mode.

DoDi




More information about the fpc-devel mailing list