[fpc-pascal] Writing a compiler

Frank Peelo f26p at eircom.net
Mon Jan 5 11:43:00 CET 2009


Gerard N/A wrote:
> Hi,
> 
> On Mon, Jan 5, 2009 at 6:50 AM, leledumbo <leledumbo_cool at yahoo.co.id> wrote:
> 
>>I just finished taking compiler techniques class this semester and I'd like
>>to write my own based on the one used in the class. The class uses Java with
>>JLex and JavaCUP, but I don't really like Java and I want to rewrite it in
>>FP. However, there are some choices for writing the scanner and parser:
>>
>>2. Coco/R
>>  Question: TP vs Delphi version, which one is more appropriate for FP?
>>  Pros: Very close to EBNF, Modula-2 / Oberon-like structure, has many
>>features
>>  Cons: Needs changes from original version (my lecturer doesn't give EBNF
>>notation)
>>
> 
> There is also Gold Parser builder at http://www.devincook.com/ , wich
> has a Delphi engine.
> IIRC, it uses BNF for the grammars, though.
> 
> 
>>3. Handwritten
>>  Question: Need some references other than Jack Crenshaw's book
>>  Pros: Easier to maintain (someone said, but no prove)
>>  Cons: I don't have any practical background on this
>>
>>>From the given choices, which one will you suggest?
> 
> 
> It depends on the language, basically. If the language you want to
> compile can be easily parsed by a recursive descent parser, then it's
> not that difficult.
> I don't think it's easier to maintain. If you change the grammar, in a
> table driven parser you would only have to regenerate the tables. In a
> hand written parser, you must implement the changes yourself.
> On the other hand, it's YOUR code that you are maintaining, so it
> should make some sense to you. ;-)
> Wirth's book "Algorithms + Data Structures = Programs" contanis a
> recursive descent parser+p-code compiler+p-code interpreter for a
> subset of pascal.
> I studied it and used it as a base for an integrated interpreter in a
> commercial app years ago with success.

There's also "Compiler Construction" by Prof. Wirth, Addison-Wesley, 
1996, ISBN 0-201-40353-6. It describes a subset of Oberon, rather than 
Pascal, but it does have the advantage that he seems to have released it 
(or rather, a revised 3rd edition) as a PDF. The original link I found was

http://www.oberon.ethz.ch/WirthPubl/CBEAll.pdf

but http://www.oberon.ethz.ch/WirthPubl seems to have disappeared since 
he retired. Google says the PDF is on a website of the National 
Technical University of Athens, at

http://www.dbnet.ece.ntua.gr/~adamo/csbooksonline/CBEAll.pdf


Frank






More information about the fpc-pascal mailing list