Bookstore

Recent

Author Topic: Am I did it wrong all the time?  (Read 1938 times)

lucamar

  • Hero Member
  • *****
  • Posts: 2588
Re: Am I did it wrong all the time?
« Reply #15 on: February 24, 2020, 10:21:42 am »
I don't quite understand nov97's drift. I use plenty of begin, end, semi-column,etc. even when not absolutely necessary. It helps me clarify the structure of my programs, and help the parser.

That's precisely his point: Oberon compilers barf on a lot of that extra "candy". For example, this a perfectly legitimite statement in Pascal but not in Oberon:
Code: Pascal  [Select]
  1. begin
  2.   begin begin
  3.     ;;;;;;;;; DoSomething; ;;;;;;;;;
  4.   end; end;
  5. end;

Also Oberon has a much stricter syntax with respect to "begin" and "end": for example, there are places where there can be no "begin" but the block must be terminated with an "end"; and so on.

All of this means that we, "lazy" Pascal programmers, may have unspected (and somewhat baffling) problems when writing Oberon code.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

guest65278

  • Guest
Re: Am I did it wrong all the time?
« Reply #16 on: February 24, 2020, 10:45:05 am »
I don't quite understand nov97's drift. I use plenty of begin, end, semi-column,etc. even when not absolutely necessary. It helps me clarify the structure of my programs, and help the parser.

I said about another language, Oberon, but not Pascal.

MarkMLl

  • Hero Member
  • *****
  • Posts: 711
Re: Am I did it wrong all the time?
« Reply #17 on: February 24, 2020, 11:38:54 am »
This sound complicated. Why not let life easier?  :P

It all boils down to what can be parsed. An if then is a particular kind of statement, an if then else is a different kind. The parser relies on being able to find either ; or else, and it uses that distinction to decide what it's looking at and how to continue: any suggestion that that should be "fixed" is a non-starter which is quite simply not worth discussing.

A number of the core developers and long-term users are, like myself, "refugees" from Modula-2 and are keenly aware of what's known as the "dangling else problem" and other Pascal shortcomings. It would be desirable to change the syntax to fix these, but it's quite simply not feasible since it would break backward-compatibility with Delphi and cause enormous problems to those of us who maintain older code... some of which dates back to Turbo Pascal and even older compilers.

One possibility would be a per-unit directive which mandated the Modula-style if then else end rather than the Pascal-style if then else. But that still wouldn't help people who refused to take the time to learn the fundamental syntax, or both lacked the background to understand why certain things are the way they are and refused to accept the guidance of those with more experience.

My own feeling is that Oberon is too restrictive, and while it was designed to be a systems programming language- and used as such by Wirth's research group- it is too inclined towards language "purity" at the expense of practical usability. Gutknecht wrote a paper on why "the best" languages generally weren't adopted, my own answer to that is that while a "pure" language might appear "obvious" to its designers it can be totally obscure to the remainder of the community.

Having noticed it discussed a few days ago, I would like to wrap up by mentioning Vector Pascal which is probably the last significant research effort using the Pascal syntax. My own feeling is that there are things which can usefully be learned from it, in particular that it would be desirable to distinguish between concatenation of strings and (dynamic) arrays and iterative addition of their elements.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1109
  • Compiler Developer
Re: Am I did it wrong all the time?
« Reply #18 on: February 24, 2020, 02:03:09 pm »
It would be interesting to add a new mode to the future version of the FPC (perhaps FPC 4.0)
that would allow us to have this feature.

I don't think it'll be possible: it depends almost exclusively on the sintax of the language. Any parser to has to continue parsing until it can't go further; it just happens that Oberon has an even stricter grammar than Pascal, so it stops (generally) at the most minor "infraction", while the Pascal parser may continue making (or tryng to make) sense for several (or a lot of) lines more.

A parser doesn't have to continue parsing. E.g. pas2js stops after the first error. It's just rather convenient if the parser tries to recover cause other errors can be reported in the same run as well. Though this increases the "dangers" of false errors if the code in question depends on the first error.

MarkMLl

  • Hero Member
  • *****
  • Posts: 711
Re: Am I did it wrong all the time?
« Reply #19 on: February 24, 2020, 02:49:45 pm »
A parser doesn't have to continue parsing. E.g. pas2js stops after the first error. It's just rather convenient if the parser tries to recover cause other errors can be reported in the same run as well. Though this increases the "dangers" of false errors if the code in question depends on the first error.

The paper by XXXXXXXXXXX that somebody cited earlier specifically talks about Oberon only trying to advance beyond a syntax error to a limited extent:

Quote
Recursive  descent  parsing  requires  the  grammar  of  a  language  to  be  LL(1),  that means it must be possible to analyze the language top-down from left to right with a single  lookahead  symbol.  Whenever  there  is  an  alternative  in  the  grammar,  the lookahead  symbol  must  lead  the  way  and  tell  the  compiler  which  alternative  to select.
[...]
Given  the  fact  that  computers  become  faster  and  faster,  it  is  not  necessary  any more  to  find  all  errors  in  a  single  compilation.  If  a  compilation  takes  less  than  a second, it is acceptable to find just some errors, correct them, and then compile the program  again  to  find  the  remaining  errors.  Thus  the  Oberon  compiler  does  not synchronize  with  the  followers  of  every  nonterminal  symbol  but  selects  a  few synchronization points in the grammar where recovery is particularly easy and safe.These  synchronization  points  are  the  beginning  of  a  statement,  a  declaration  or  a type  where  symbols  such  as  "IF",  "WHILE",  "TYPE"  or  "RECORD"  are  expected.These  symbols  are  considered  particularly  safe,  because  they  are  unlikely  to  been countered  in  the  wrong  context.

I love to read comments from people who say that "such-and-such behaviour in a parser is silly", and then go on to explain how it can be improved without breaking things. Regrettably, that's an extremely rare combination.

MarkMLl



Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

lucamar

  • Hero Member
  • *****
  • Posts: 2588
Re: Am I did it wrong all the time?
« Reply #20 on: February 24, 2020, 03:22:30 pm »
A parser doesn't have to continue parsing.

Which is why said it may continue parsing, not that all of them always do so (and most don't when they find a fatal error). ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

guest65278

  • Guest
Re: Am I did it wrong all the time?
« Reply #21 on: February 24, 2020, 05:43:10 pm »
My own feeling is that Oberon is too restrictive, and while it was designed to be a systems programming language- and used as such by Wirth's research group- it is too inclined towards language "purity" at the expense of practical usability. Gutknecht wrote a paper on why "the best" languages generally weren't adopted, my own answer to that is that while a "pure" language might appear "obvious" to its designers it can be totally obscure to the remainder of the community.

Having noticed it discussed a few days ago, I would like to wrap up by mentioning Vector Pascal which is probably the last significant research effort using the Pascal syntax. My own feeling is that there are things which can usefully be learned from it, in particular that it would be desirable to distinguish between concatenation of strings and (dynamic) arrays and iterative addition of their elements.

MarkMLl

Also notice Oberon use garbage collector and most of the compiler depends on the boehm-gc library (the JVM based one doesn't, of course). I found it's weird to type POINTER TO something without the ability to FREE something. Oberon has the NEW keywork, but no FREE or DISPOSE or something like that. Check here: https://miasap.se/obnc/oberon-report.html#sec3

Er, I don't think we should learn anything from Vector Pascal. This compiler allow you to type code in Unicode and the code will look very weird. Check it manual here: https://sourceforge.net/projects/vectorpascalcom/files/

PascalDragon

  • Hero Member
  • *****
  • Posts: 1109
  • Compiler Developer
Re: Am I did it wrong all the time?
« Reply #22 on: February 25, 2020, 09:48:36 am »
A parser doesn't have to continue parsing.

Which is why said it may continue parsing, not that all of them always do so (and most don't when they find a fatal error). ;)

Ehm, no, you said this:

Any parser to has to continue parsing until it can't go further

You didn't say that it may continue until it can't go further...  ;)

lucamar

  • Hero Member
  • *****
  • Posts: 2588
Re: Am I did it wrong all the time?
« Reply #23 on: February 25, 2020, 11:41:31 am »
Yes, an unfortunate election of words on my part :-[

Though I did say "[...] while the Pascal parser may continue making (or tryng to make) sense [...]".

But you're right; not my more brilliant post, is it? :)

Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 9809
Re: Am I did it wrong all the time?
« Reply #24 on: February 25, 2020, 01:37:08 pm »
Hm.. annoyed by those last two experts.
Pascal is designed to be a single pass compiler. We know that is not the case but the principle holds at most a one look ahead..... One of you is actually helping to destroy that.. to my joy...
";"
I am more like donkey than shrek

guest65278

  • Guest
Re: Am I did it wrong all the time?
« Reply #25 on: February 25, 2020, 05:15:23 pm »
A number of the core developers and long-term users are, like myself, "refugees" from Modula-2 and are keenly aware of what's known as the "dangling else problem" and other Pascal shortcomings. It would be desirable to change the syntax to fix these, but it's quite simply not feasible since it would break backward-compatibility with Delphi and cause enormous problems to those of us who maintain older code... some of which dates back to Turbo Pascal and even older compilers.

MarkMLl

I quote you only want to note that even though GNU Pascal was dead but GNU Modula-2 is still alive and kicking. Their latest release is based on gcc 8.2.0. They provided packages for Debian 9 but I'm using Debian 10 so I have to build from source. The process took more than one hour but everything was straight forward, just follow their document and you will be OK.

As I have said I set up CudaText to code Modula-2. But I finally migrated here because there is too little to zero documents for Modula-2. I only found a simple tutorial on the net. Modula-2 confused me a lot because there are so many dialects and a lot of incompatibility between them. I downloaded PIM books pdf version but can't stand the poor quality scanned text. And there is no way to found anything about the ISO dialect. So finally I'm here. Abandoned both Modula-2 and Oberon.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1109
  • Compiler Developer
Re: Am I did it wrong all the time?
« Reply #26 on: February 26, 2020, 09:41:14 am »
Hm.. annoyed by those last two experts.
Pascal is designed to be a single pass compiler. We know that is not the case but the principle holds at most a one look ahead..... One of you is actually helping to destroy that.. to my joy...
";"

That is precisely why I hate Delphi's generics syntax. It implodes the single token look ahead if you have something like if SomeVarOrType<SomeOtherVarOrType …. At the < the parser might not yet know whether it's dealing with a generic or an expression as the closing > might be many tokens away. In the FPC syntax however single token look ahead is working perfectly fine: if specialize SomeVarOrType<SomeOtherVarOrType …. As soon as the specialize is parsed the parser knows that it's dealing with a specialization and nothing else.

Thaddy

  • Hero Member
  • *****
  • Posts: 9809
Re: Am I did it wrong all the time?
« Reply #27 on: February 26, 2020, 09:49:43 am »
 O:-)
I am more like donkey than shrek

Otto

  • Full Member
  • ***
  • Posts: 178
Re: Am I did it wrong all the time?
« Reply #28 on: February 26, 2020, 03:02:24 pm »
Hello everyone.
Does the FPC compiler use custom directives?

To try to explain myself better I report an example:
Code: Pascal  [Select]
  1. // Esempio dimostrativo  utile al solo scopo di discutere aspetti inerenti la sintassi del FPC.
  2. // A demonstration example that is useful for the sole purpose of discussing aspects of FPC syntax.
  3. program Sintassi;
  4.  
  5. procedure FaiQualcosa(var a: integer; var b: integer);
  6. begin
  7.   {$mode WrongWay(PleaseDoNotDoThis(Begin))}
  8.   if (a=b) then begin
  9.     inc(a);
  10.   end else begin
  11.     inc(b);
  12.   end;
  13.   {$mode WrongWay(PleaseDoNotDoThis(End))}
  14. end;
  15.  
  16. var a, b: integer;
  17. begin
  18.   a:= 10; b:=34;
  19.   FaiQualcosa(a, b);
  20.   WriteLn(a);
  21.   WriteLn(b);
  22.   ReadLn;
  23. end.    
For example, in this case, the directives
{$mode WrongWay(PleaseDoNotDoThis(Begin))} {$mode WrongWay(PleaseDoNotDoThis(End))}
they would be intended to enable and disable the generation of warnings about the type of syntax used: if it were not of the desired type it would generate a warnings.
I believe that such a thing can be achieved by analyzing the code by a parser program, launched at the end of the compilation.
Of course, the use of these directives should not affect the program generated by the build in any way.

Otto.

« Last Edit: February 26, 2020, 03:07:06 pm by Otto »
Kind regards.

MarkMLl

  • Hero Member
  • *****
  • Posts: 711
Re: Am I did it wrong all the time?
« Reply #29 on: February 26, 2020, 03:05:39 pm »
Hello everyone.
Does the FPC compiler use custom directives?

Not in the sense that you're using them. Individual checks may be turned on/off, see https://www.freepascal.org/docs-html/current/prog/prog.html

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.