Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread wkitty42

On 05/08/2017 04:49 AM, Mattias Gaertner wrote:

On Mon, 8 May 2017 09:22:48 +0100
Graeme Geldenhuys  wrote:


On 2017-05-08 04:26, nore...@z505.com 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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Jürgen Hestermann

Am 2017-05-08 um 12:31 schrieb Marco van de Voort:

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).

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Marco van de Voort
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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Michael Van Canneyt



On Mon, 8 May 2017, Graeme Geldenhuys wrote:


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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Mark Morgan Lloyd

On 08/05/17 08:30, Graeme Geldenhuys wrote:

On 2017-05-08 04:26, nore...@z505.com 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]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Graeme Geldenhuys
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.

Regards,
  Graeme

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Michael Van Canneyt



On Mon, 8 May 2017, Mattias Gaertner wrote:


On Mon, 8 May 2017 09:22:48 +0100
Graeme Geldenhuys  wrote:


On 2017-05-08 04:26, nore...@z505.com 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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Mattias Gaertner
On Mon, 8 May 2017 09:22:48 +0100
Graeme Geldenhuys  wrote:

> On 2017-05-08 04:26, nore...@z505.com 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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-08 Thread Graeme Geldenhuys
On 2017-05-08 04:26, nore...@z505.com 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.

Regards,
  Graeme

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-07 Thread noreply

On 2017-05-03 06:49, Peter wrote:

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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-07 Thread noreply

On 2017-05-03 04:37, Michael Van Canneyt wrote:

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 ;-)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-07 Thread noreply

On 2017-05-02 18: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?



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

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-03 Thread Marco van de Voort
In our previous episode, Marco van de Voort said:
> > 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

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-03 Thread Peter
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
> 
> 
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 

I found grammar for Delphi once.
Trying to attach it.
start= program  | unit | library | package .

  identifier_list= ID_NAME { ',' ID_NAME } .
  unit_qualified_identifier= ID_NAME { '.' ID_NAME } .

  type_name= TYPE_NAME | STRING | FILE .
  unit_qualified_type_name= type_name [ '.' type_name ] .

  function_result_type= type_name .

  constant_expression= F .
  string_expression= ( STRING_NAME | STRING_LITTERAL )
  { '+' ( STRING_NAME | STRING_LITTERAL ) } .

  variable_access= ( ACCESS_NAME | STRING ) { end_access_ } .
end_access_= { array_access_ | record_access_ | '^' | function_parameters_ 
} .
  array_access_= '[' constant_expression { ',' constant_expression } ']' .
  record_access_= '.' variable_access .
  function_parameters_= '(' [ constant_expression { ',' constant_expression 
} ] ')' .

  set_factor= '[' [ set_element { ',' set_element } ] ']' .
set_element= constant_expression [ '..' constant_expression ] .

  constant_expression= simple_expression__ [ ('=' | '<>' | '<' | '<=' | '>' | 
'>=' | IN  )
  simple_expression__ ] .
simple_expression__= [ '+' | '-' ] term__ { ('+' | '-' | OR | XOR ) term__  
} .
  term__= factor__ { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) factor__ } .
factor__= NUMBER | STRING_LITTERAL | NIL
| variable_access
| NOT factor__ | '@' factor__ | set_factor
| '^' NAME
| '(' constant_expression ')'.

  typed_constant= simple_expression_ [ ('=' | '<>' | '<' | '<=' | '>' | '>=' | 
IN  )
  simple_expression_ ] .
simple_expression_= [ '+' | '-' ] term_ { ('+' | '-' | OR | XOR ) term_ } .
  term_= factor_ { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) factor_ } .
factor_= NUMBER | STRING_LITTERAL | NIL
// -- id or field "(f1: v1; f2: v2)"
| variable_access [ ':' typed_constant
{ ';' variable_access ':' typed_constant } ]
| NOT factor_ | '@' factor_
| '^' NAME
| '(' [ typed_constant_]  ')'
| set_factor .
  // -- array "(1, 2, 3)" or "fn(p1, p2")
  typed_constant_= typed_constant { ',' typed_constant } .

  formal_parameters= '(' formal_parameter { ';' formal_parameter } ')' .
formal_parameter= [ parameter | var_parameter
| const_parameter | out_parameter | in_parameter ] .
  parameter_name_list= PARAMETER_NAME { ',' PARAMETER_NAME } .
  array_or_name_type= ARRAY OF ( CONST | unit_qualified_type_name )
  | unit_qualified_type_name .
  parameter= parameter_name_list ':' array_or_name_type
  ['=' constant_expression ]  .
  var_parameter= VAR parameter_name_list [ ':' array_or_name_type ] .
  const_parameter= CONST parameter_name_list
  [ ':' array_or_name_type ['=' constant_expression ] ] .
  out_parameter= OUT parameter_name_list [ ':' array_or_name_type ] .
  in_parameter= IN parameter .

  dos_directives= NEAR | FAR | EXPORT | ASSEMBLER .
  calling_directives= CDECL | PASCAL | REGISTER | SAFECALL | STDCALL .
  overload_directive= OVERLOAD .
  method_directives= ABSTRACT | VIRTUAL | DYNAMIC
| OVERRIDE | REINTRODUCE | MESSAGE constant_expression .

  const_type_var_declarations= constant_definitions | resource_defintions
  | type_definitions | variable_declarations .

type= keyed_types | type_0 .
  // -- called by i_type
  enumeration_type= '(' identifier_list ')' .
  expression_t= simple_expression_t
  [ ( ('=' | '<>' | '<' | '<=' | '>' | '>=' | IN  ) simple_expression_t
| '..' end_range_type ) ] .
simple_expression_t= [ '+' | '-' ] term_t { ('+' | '-' | OR | XOR ) 
term_t } .
  term_t= factor_t { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) 
factor_t } .
factor_t= NUMBER | STRING_LITTERAL | NIL
| variable_access
| NOT factor_t | '@' factor_t
| '^' NAME
| '(' expression_t ')'
| set_factor .
end_range_type= simple_expression_t .
  type_0= ( NUMBER | STRING_LITTERAL | NIL | NOT | '+' | '-' | '@' | '(' | 
'[' | NAME )
  $i_type .
  keyed_types= string_type | structured_type | pointer_type | 
procedural_type .
// -- handle STRING as array[index_type]
string_type= STRING [ '[' constant_expression ']' ] .
structured_type= [ PACKED ] ( array_type | record_type | set_type | 
file_type  ) .
  array_type= ARRAY [ '[' index_type { ',' index_type } ']' ] OF type .
index_type= 

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-03 Thread Michael Van Canneyt



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.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-03 Thread denisgolovan
> 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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-03 Thread Graeme Geldenhuys
On 2017-05-03 00:53, 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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] machine readable grammar of object pascal?

2017-05-03 Thread Marco van de Voort
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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] machine readable grammar of object pascal?

2017-05-02 Thread 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


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal