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

Mailing lists / fpc-pascal / 2017-05
19 messages · 10 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
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.
for playing around I would need a grammar of Object Pascal. I do not care for which tool…
Marc Santhoff wroteDoes 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
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.
Add generics to the 'minus' list.
Michael.
for playing around I would need a grammar of Object Pascal. I do not care for which tool…
I found grammar for Delphi once.
Trying to attach it.
In our previous episode, Marc Santhoff said: Not within FPC/Lazarus project, since those…
In our previous episode, Marco van de Voort said:
When I searched I saw a new entry, reportedly for XE7:
for playing around I would need a grammar of Object Pascal. I do not care for which tool…
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
Add generics to the 'minus' list. Michael.
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 ;-)
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.
Does it take into account little bizarre things like writable consts (assignable consts)…
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.
Regards,
Graeme
Was a typed const ever read only?
Mattias
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.
On Mon, 8 May 2017 09:22:48 +0100 Was a typed const ever read only? Mattias
Mattias Gaertner wroteWas 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.
Regards,
Graeme
I'm slowly but surely loosing all hope for Object Pascal. The language is becoming more…
Graeme Geldenhuys wroteOn 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.
And does CONSTANT in any other language mean writable? I think they have VAR for that.…
This is not something invented by FPC.
It is something inherited from Turbo Pascal.
See my other reply to Mattias.
Michael.
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.
Marco van de Voort wroteIn 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).
On Mon, 8 May 2017 09:22:48 +0100 Was a typed const ever read only? Mattias
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...