Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Produce Delphi Code that will Parse a file with a given BNF format

Is there parser code or a parser component for Delphi or a program that will accept BNF (Backus-Naur Form) notation as input and produce Delphi (or pascal) code to do the parsing?

The reason for this is that I am going to be attempting to perfectly parse data sets following various versions of the GEDCOM standard (used for genealogy), and will need to process the file from state to state as tokens are reached. I would prefer an automated program to do the grunt work of setting up the basic pascal code to do the state to state processing for me.

Otherwise, I'll have to manually build the state structures myself.

I did see the following question (and TinyPG looks good, but I need Delphi code): Parser-generator that outputs C# given a BNF grammar?

If there isn't such a beast, are there any other tools available that will make this task easier?

like image 462
lkessler Avatar asked Feb 23 '12 01:02

lkessler


1 Answers

I recommend you the GOLD parsing system. GOLD grammars are based on Backus-Naur form and regular expressions.

Resources

  • gold-parser
  • Wikipedia entry page
  • Yahoo group

Engines

Engines for Delphi are particularly listed here.

This one for Object Pascal by Rob van den Brink might be of interest.

Quote:

Rob van den Brink updated his engine for the Object Pascal Programming Language. His implementation uses a program template to create a full-functioning program. This approach embeds the parse tables directly in the source code. As a result, you do not need to load a Compiled Grammar Table file. The download contains a program template as well as several examples.

Sample project using GOLD

GOLD is powerfull, it is used as the parsing engine of dcu2pas, a Delphi Compiled Unit (dcu files) decompiler which is hosted here (bitbucket.org). Notice instead that it's written in d.

like image 152
menjaraz Avatar answered Sep 20 '22 16:09

menjaraz