Recent

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

guest65278

  • Guest
Am I did it wrong all the time?
« on: February 23, 2020, 01:46:36 pm »
https://everything2.com/title/When+to+use+a+semicolon+in+Pascal

I used to think it's just like C.

p/s: I come here from Modula-2, I come to Modula-2 from Oberon-07 and I come to Oberon-07 from C.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Am I did it wrong all the time?
« Reply #1 on: February 23, 2020, 02:20:57 pm »
In Pascal the semicolon is a statement separator, unlike in C and similar where it's a terminator. That means that you only need to add it if the next element is another statement, but  frankly speaking most people don't ever bother: we just add a semicolon as a matter of course ... with one exception: before an else, where it's actually forbidden.

The reason for that "careless" actitude (beyond laziness :)) is that if you later add statements you don't have to go back to see whether the statement before the insertion point have a semicolon or not; you already know it has. With the exception, of course, of pre-"else" statements, but then you'll have to add a "begin..end" block if there'are more than one statement, so no much problem there either.

And yes, adding a semicolon where it's not needed introduces an empty statement but, so what? Empty statements cause very little (if any) delay in parsing and produce no code, so better safe than sorry ;)

HTH.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 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 #2 on: February 23, 2020, 03:04:06 pm »
@lucamar: that's the reason why I left Oberon. Pascal and Modula-2 are more tolerant. Oberon is too strict. The code is compact but most of the time I found myself stuck figuring out why my code doesn't compile, it's usually because missing of an END or missing of a semicolon somewhere but after checked the code serveral times I still can't figure out where it is. Interfacing with C library is a tricky hack depends on each compiler. You can't even write a shared lib. Oberon might found it place on very small embedded device programming but I found myself totally unproductive with it. I miss the way C use semicolon, it's stupidly simple but just works. Luckily, Pascal doesn't care about empty statement so it's almost just like C.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Am I did it wrong all the time?
« Reply #3 on: February 23, 2020, 03:19:59 pm »
I like Oberon; it reflects the distilled wisdom gained through the design and building of Pascal and Modula, and it ruthlesly hacks away the dead wood and over-complication added to those through the years.

Unfortunately there is no mainstream, production-ready, multiplatform compiler and tools for it (AFAIK) and it has even less users than Pascal, so there'll probably never be one.

Note that the strictness of Oberon plays in its favor: almost any sintatic error will have just one reason and one solution, and most parsers will stop at the correct point (or thereabout) where the error ocurred.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 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 #4 on: February 23, 2020, 03:31:41 pm »
I like Oberon; it reflects the distilled wisdom gained through the design and building of Pascal and Modula, and it ruthlesly hacks away the dead wood and over-complication added to those through the years.

Unfortunately there is no mainstream, production-ready, multiplatform compiler and tools for it (AFAIK) and it has even less users than Pascal, so there'll probably never be one.

Note that the strictness of Oberon plays in its favor: almost any sintatic error will have just one reason and one solution, and most parsers will stop at the correct point (or thereabout) where the error ocurred.

Our poor man just want his code to compile to see if it works  :-[

Joking aside. There are many compiler for Oberon:

Vishap Oberon (VOC): it's Oberon-2, but understands Oberon-07, too.

OBNC: it's an Oberon-07 compiler, very small and just works.

The above compiler translate Oberon code into C source and use a C compiler to get the final binary. Note: I found VOC's generated C source is more readable than ONBC but both of them produce very readable C source.

There is Oberonc, too. This guy compiles into Java bytecode and will work on any JVM >= 1.8  :P

I use CudaText for coding Oberon. Case sensitive sucks, though. Here is my workaround: only use the Modula-2 lexer as it will ask you to choose between each lexer everytime you open a .mod file if you install the Oberon lexer, too. Always use uppercase, use Auto Replace plugin to overwrite proper function and library name for convenient. e.g: OUT.STRING will be overwrite to Out.String automatically by the Auto Replace plugin  :)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Am I did it wrong all the time?
« Reply #5 on: February 23, 2020, 03:34:13 pm »
In Pascal the semicolon is a statement separator, unlike in C and similar where it's a terminator. That means that you only need to add it if the next element is another statement, but  frankly speaking most people don't ever bother: we just add a semicolon as a matter of course ... with one exception: before an else, where it's actually forbidden.
A minor amendment:

...with one exception: before an else in an if statement, where it's actually forbidden.

Before an else in a case construct the separating semicolon is actually required unless there is a begin/end block immediately preceding the else, when the semicolon after the 'end' is optional, at least in FPC.
« Last Edit: February 23, 2020, 03:38:24 pm by howardpc »

julkas

  • Guest
Re: Am I did it wrong all the time?
« Reply #6 on: February 23, 2020, 04:09:51 pm »
Compiler Construction - The Art of Niklaus Wirth
ftp://ftp.ssw.uni-linz.ac.at/pub/Papers/Moe00b.pdf

guest65278

  • Guest
Re: Am I did it wrong all the time?
« Reply #7 on: February 23, 2020, 04:27:20 pm »
In Pascal the semicolon is a statement separator, unlike in C and similar where it's a terminator. That means that you only need to add it if the next element is another statement, but  frankly speaking most people don't ever bother: we just add a semicolon as a matter of course ... with one exception: before an else, where it's actually forbidden.
A minor amendment:

...with one exception: before an else in an if statement, where it's actually forbidden.

Before an else in a case construct the separating semicolon is actually required unless there is a begin/end block immediately preceding the else, when the semicolon after the 'end' is optional, at least in FPC.

This sound complicated. Why not let life easier?  :P

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #8 on: February 23, 2020, 04:40:27 pm »
Hello everyone.

Note that the strictness of Oberon plays in its favor: almost any sintatic error will have just one reason and one solution, and most parsers will stop at the correct point (or thereabout) where the error ocurred.

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.

However, I have already been told that the developers of FPC are too busy.

Greetings.
Otto.
« Last Edit: February 23, 2020, 04:48:44 pm by Otto »
Kind regards.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Am I did it wrong all the time?
« Reply #9 on: February 23, 2020, 05:03:00 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.
« Last Edit: February 23, 2020, 05:04:53 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Am I did it wrong all the time?
« Reply #10 on: February 23, 2020, 05:42:54 pm »
@ lucamar

Hi, I imagined something like that.

The more I study the source code of Lazarus IDE, the more I appreciate many of the decisions that have been made; so I understand your opinion well.

Greetings.
Otto.
Kind regards.

guest65278

  • Guest
Re: Am I did it wrong all the time?
« Reply #11 on: February 23, 2020, 06:16:08 pm »
@lucamar, @Otto: Please, I don't want Free Pascal to be like Oberon at all. I have stuck hours without success figuring out why my code didn't compile, the compiler just said it's missing an END. You know? I didn't missed any END. It's just because I forgot to place a semicolon and it's refused to compile my code and said again and again RETURN unexpected, expecting END or IDENT unexpected, expecting END... Write some code in Oberon-07 and compile with OBNC and you will know the misery!

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Am I did it wrong all the time?
« Reply #12 on: February 23, 2020, 07:48:02 pm »
Compiler Construction - The Art of Niklaus Wirth
ftp://ftp.ssw.uni-linz.ac.at/pub/Papers/Moe00b.pdf
That paper was a genuine pleasure to read. A load of simplicity and common sense.  Thank you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Am I did it wrong all the time?
« Reply #13 on: February 23, 2020, 08:28:27 pm »
Analogous:

"Programming languages ​​are developed by someone alone, not by committees."

Niklaus Wirth

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Re: Am I did it wrong all the time?
« Reply #14 on: February 24, 2020, 12:40:14 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.

 

TinyPortal © 2005-2018