[fpc-pascal] Writing a compiler
gerardusmercator at gmail.com
Mon Jan 5 11:06:02 CET 2009
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
> Cons: Needs changes from original version (my lecturer doesn't give EBNF
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.
More information about the fpc-pascal