29

I need a complete Object Pascal syntax (preferably Delphi 2009). Some of the syntax is given by the help files, but not all information is provided. So I started collecting loose bits of information. Recently I added these to a more or less complete syntax description (EBNF like).

Although it looks extensive, there are still bugs and I'm sure parts are missing (specially in the .NET syntax). So I'm asking the SO Delphi community. Do you have any information or can you correct the errors? In return I provide the complete syntax to the community. It probably saves you some time ;-). In the future, I like to do the same for other languages (Like C#/C++/Java).

The syntax description I already have is given: My Syntax sofar. Or if you like a Text version. (The XHTML is generated from the text version).

Please note that the syntax focusses on the syntactical part, because the lexical part is not really a problem.

Update

I have a new version of the Delphi Syntax. html version. It includes al versions including 2009. Prism extentions are still on the todo list. And I'm not sure if I'm going to keep them together.

For the real purists, it also contains the full assembler code (which does not support the full 100% of the intel set but only a few instructions are missed.).

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
  • What are you trying to achieve, i.e. what is your end goal? A grammar all by itself isn't useful for much. Is it meant to be machine-readable (e.g. for a parser generator)? – Barry Kelly Oct 05 '08 at 14:27
  • @menjaraz, nope, I have not found an additional resource. But I'm almost finished with the XE2 syntax using any info from sources, help, websites and trial and error. – Toon Krijthe Mar 30 '12 at 15:58
  • 3
    Your 2009 version of the Delphi grammar is now used in the Sonar Delphi Plugin which has been released February 2012, available at http://docs.codehaus.org/display/SONAR/Delphi+Plugin – mjn Jun 19 '12 at 11:50
  • A grammar can be very useful. At one a time, most books about the language included a grammar. It is one of the first things I looked for when I started using Delphi. I hadn't used Pascal since the 1990s. I don't remember whether Turbo Pascal's manual (which I recall being excellent in many ways) included a grammar. Today Embarcadero has a reference for their language on their website, but I couldn't find a grammar. Embarcadero must have a grammar, or something close to one, as part of the build for their compiler. I wish they would release it; it would help me a lot. – D A Vincent May 11 '14 at 09:12

6 Answers6

16

Try this: DGrok - Delphi grammar

DiGi
  • 2,528
  • 18
  • 26
3

There is no complete, published syntax for Delphi. Bear in mind that .net and win32 delphi have different syntaxes.

This project has hand-build Delphi parser in it. And lots of test cases of code that compiles but pushes the limits of the syntax.

Anthony
  • 5,176
  • 6
  • 65
  • 87
2

Delphi 7's grammar is in the back of the Object Pascal book.

You mean for a few thousand dollars they don't even send you that? Do they even send you a 6' x 6' poster?

Peter Turner
  • 11,199
  • 10
  • 68
  • 109
2

This might be a good help. It is the parser used in TwoDesk's Castalia.

Jim McKeeth
  • 38,225
  • 23
  • 120
  • 194
1

What exactly are the bugs and functionality you're missing?

From scanning over your document, it seems you mingle syntax and semantics. I do not understand why to distinguish between SimpleTypeFloat and SimpleTypeOrdinal on a syntactic level, or code operator precedence as syntactic feature in AddOp and MulOp. true, false, nil are identifiers just as any variable name you choose.

devio
  • 36,858
  • 7
  • 80
  • 143
0

You could always read the source to the Free Pascal Compiler. It supports Object Pascal.

Hugh Allen
  • 6,509
  • 1
  • 34
  • 44