Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-05

machine readable grammar of object pascal?

19 messages · 10 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

for playing around I would need a grammar of Object Pascal. I do not care for which tool it is written or at best if it is plain EBNF.

Does such grammar exist?

TIA,
Marc

Reply by email

Marco van de Voort
to Marc Santhoff

In our previous episode, Marc Santhoff said:

for playing around I would need a grammar of Object Pascal. I do not care for which tool it is written or at best if it is plain EBNF. Does such grammar exist?

Not within FPC/Lazarus project, since those use handcrafted recursive descent parsers. So that means websearch, and then your search is as good as mine.

The manual of older Delphi versions had a grammar for documentation (not use!) purposes, and many only Object Pascal grammars will be based on that, so check licensing of what you find thoroughly if you need it for a commercial setting.

Reply by email

Graeme Geldenhuys
to Marc Santhoff: for playing around I would need a grammar of Object Pascal. I do not care for which tool…
Marc Santhoff wrote
Does such grammar exist?

Not as part of the Free Pascal project. At one stage I have been maintaining my own Pascal Grammar in EBNF format as part of the documentation for fpGUI, but I haven’t kept up with all the recent FPC syntax changes though - no generic, advanced records (aka new style TP Objects) etc. I based the grammar on FPC’s “objfpc” compiler mode only.

The latest version can be found in the FPC Language Reference document (INF help format) here:

https://github.com/graemeg/fpGUI/blob/develop/docs/fpc_lang_ref.ipf

ps:
I can generate a INF binary help file viewable with fpGUI’s DocView help viewer if you want to see how it looks like in its final state. Otherwise, you can compile your own binary INF file. Everything needed is in the fpGUI code repository and pre-built binaries of DocView are available for download from SourceForge.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

denisgolovan
to Graeme Geldenhuys
On 2017-05-03 00:53, Marc Santhoff wrote: >  Does such grammar exist?

Well, it depends on what you are trying to solve.
If you want to parse Pascal using FPC - that's one way. If you want to get some king of AST using any available [command-line] tools - that's another one.

Talking about latter - I would take LPEG (Lua+PEG) and create a parser myself. It comes quite simple and intuitive (contrary to LL,LR,LALR,...). Most of Object Pascal is done right (minus sets/open arrays), so it can be parsed statically pretty easily. See http://lua-users.org/wiki/LpegRecipes for inspiration.

Regards, Denis Golovan

Reply by email

Michael Van Canneyt
to denisgolovan
denisgolovan wrote 10 lines
> On 2017-05-03 00:53, Marc Santhoff wrote: >>  Does such grammar exist? Well, it depends on what you are trying to solve. If you want to parse Pascal using FPC - that's one way. If you want to get some king of AST using any available [command-line] tools - that's another one. Talking about latter - I would take LPEG (Lua+PEG) and create a parser myself. It comes quite simple and intuitive (contrary to LL,LR,LALR,...). Most of Object Pascal is done right (minus sets/open arrays),

Add generics to the 'minus' list.

Michael.

Reply by email

Peter
to Marc Santhoff: for playing around I would need a grammar of Object Pascal. I do not care for which tool…
Marc Santhoff wrote 15 lines
Hi, for playing around I would need a grammar of Object Pascal. I do not care for which tool it is written or at best if it is plain EBNF. Does such grammar exist? TIA, Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

I found grammar for Delphi once.
Trying to attach it.

Reply by email

Marco van de Voort
to Marco van de Voort: In our previous episode, Marc Santhoff said: Not within FPC/Lazarus project, since those…

In our previous episode, Marco van de Voort said:

Show quoted text 10 lines
> Does such grammar exist? Not within FPC/Lazarus project, since those use handcrafted recursive descent parsers. So that means websearch, and then your search is as good as mine. The manual of older Delphi versions had a grammar for documentation (not use!) purposes, and many only Object Pascal grammars will be based on that, so check licensing of what you find thoroughly if you need it for a commercial setting.

When I searched I saw a new entry, reportedly for XE7:

https://github.com/fabriciocolombo/sonar-delphi/blob/master/src/main/antlr3/org/sonar/plugins/delphi/antlr/Delphi.g

Reply by email

Unknown author
to Marc Santhoff: for playing around I would need a grammar of Object Pascal. I do not care for which tool…
Marc Santhoff wrote 7 lines
Hi, for playing around I would need a grammar of Object Pascal. I do not care for which tool it is written or at best if it is plain EBNF. Does such grammar exist?

The issue is that there is no object pascal, or in other words, there's about 5 million different versions of it.
Delphi 5 is different than delphi 6, 7, 8, as things keep changing...

It's not like Plain C which stays mostly the same.

So in order to get a grammar, you'd need to only include a subset of object pascal in a certain version.

Delphi 5 compatibility would be a good candidate (subset)... as it is a fairly small language or subset (well, no, actually it's Big like Ada..) but would not include generics and all the other features of object pascal.

This is one of the biggest issues object pascal faces is that it is not very standard and keeps changing, but C++ is very similar to this, despite supposed standards existing

Reply by email

Unknown author
to Michael Van Canneyt: Add generics to the 'minus' list. Michael.
Michael Van Canneyt wrote 16 lines
On Wed, 3 May 2017, denisgolovan wrote: >> On 2017-05-03 00:53, Marc Santhoff wrote: >>>  Does such grammar exist? > > Well, it depends on what you are trying to solve. > If you want to parse Pascal using FPC - that's one way. If you want to > get some king of AST using any available [command-line] tools - that's > another one. > > Talking about latter - I would take LPEG (Lua+PEG) and create a parser > myself. It comes quite simple and intuitive (contrary to > LL,LR,LALR,...). > Most of Object Pascal is done right (minus sets/open arrays), Add generics to the 'minus' list.

Does it take into account little bizarre things like writable consts (assignable consts)

like

const
   i: integer = 0;

which is like a variable, but called a const ;-)

Reply by email

Unknown author
to Peter: I found grammar for Delphi once. Trying to attach it.
Peter wrote 15 lines
On 03/05/17 00:53, Marc Santhoff wrote: > Hi, > > for playing around I would need a grammar of Object Pascal. I do not > care for which tool it is written or at best if it is plain EBNF. > > Does such grammar exist? > > TIA, > Marc > I found grammar for Delphi once. Trying to attach it.

Which version? Delphi 5? 4? 7?

There is really no such thing as "delphi" language since there are more than 10 versions of it ;-)

But to find even a subset, would be handy.

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 6 lines
On 2017-05-08 04:26, wrote: > which is like a variable, but called a const ;-) I'm slowly but surely loosing all hope for Object Pascal. The language is becoming more and more mangled with every new release of Delphi and FPC.

Was a typed const ever read only?

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 11 lines
On Mon, 8 May 2017 09:22:48 +0100 Graeme Geldenhuys wrote: > On 2017-05-08 04:26, wrote: > > which is like a variable, but called a const ;-) > > I'm slowly but surely loosing all hope for Object Pascal. The language > is becoming more and more mangled with every new release of > Delphi and FPC. Was a typed const ever read only?

Writeable consts date from the Turbo Pascal days.

In Delphi (and FPC) there is a compiler directive that controls this.

{$WRITEABLECONST ON|OFF}
{$J+/-}

Best is of course to use {$J-}

Michael.

Reply by email

Mark Morgan Lloyd
to Graeme Geldenhuys: I'm slowly but surely loosing all hope for Object Pascal. The language is becoming more…
Graeme Geldenhuys wrote
On 2017-05-08 04:26, wrote:> which is like a variable, but called a const ;-) I'm slowly but surely loosing all hope for Object Pascal. The languageis becoming more and more mangled with every new release ofDelphi and FPC.

I'm not sure that it's worse than the alternatives, which either get bogged down in an attempt to be all things to all men (Perl 6 as a particular example) or are showcases for some community's idea of the one true way of programming.

Please excuse a quote, edited for conciseness:

"Back around September 2007, I was doing some minor but central work on an enormous Google C++ program, one you've all interacted with, and my compilations were taking about 45 minutes on our huge distributed compile cluster. An announcement came around that there was going to be a talk

"In the span of an hour at that talk we heard about something like 35 new features that were being planned.

"At this point I asked myself a question: Did the C++ committee really believe that was wrong with C++ was that it didn't have enough features?"

-- Ken Thompson
https://commandcenter.blogspot.co.uk/2012/06/less-is-exponentially-more.html

The problem is that those 35+ new features were things that somebody actually wanted or needed, either because it improved functionality or because it improved the rigour with which behaviour could be documented.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: And does CONSTANT in any other language mean writable? I think they have VAR for that.…
Graeme Geldenhuys wrote 6 lines
On 2017-05-08 09:49, Mattias Gaertner wrote: > Was a typed const ever read only? And does CONSTANT in any other language mean writable? I think they have VAR for that. Maybe it's just the terminology used in FPC.

This is not something invented by FPC.
It is something inherited from Turbo Pascal.

See my other reply to Mattias.

Michael.

Reply by email

Jürgen Hestermann
to Marco van de Voort
Marco van de Voort wrote
In our previous episode, Michael Van Canneyt said: > This is not something invented by FPC. > It is something inherited from Turbo Pascal. And Delphi up to D4 iirc.

Delphi inherited it from Turbo Pascal.
Actually, it was a hack.
Const defines end up in the global data segment
so writable local constants work like global variables but are only accessable from the declaring function.

There should have been a different syntax for this but Borland did not add one.
Now we have this syntax anomaly 'till the end of time...

This shows that before adding new "features" one should think twice (or three times).

Reply by email

Unknown author
to Mattias Gaertner: On Mon, 8 May 2017 09:22:48 +0100 Was a typed const ever read only? Mattias
Mattias Gaertner wrote 11 lines
On Mon, 8 May 2017 09:22:48 +0100 Graeme Geldenhuys wrote: > On 2017-05-08 04:26, wrote: >> which is like a variable, but called a const ;-) > > I'm slowly but surely loosing all hope for Object Pascal. The language > is becoming more and more mangled with every new release of > Delphi and FPC. Was a typed const ever read only?

i used them all the time in my TP days... some i used at the end of the exe binary to store configuration data that changed based on registration or user settings...

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email