Recent

Author Topic: Making the semicolon useless  (Read 24822 times)

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Making the semicolon useless
« Reply #60 on: April 05, 2020, 11:34:18 am »
Hi Opaque,

I am talking about having the Source editor showing a code without semicolons. Either by converting it on the fly, or indeed by a compiler option. Such option need not a new compiler but could just enable a preprocessor that adds the semicolons.

I believe there are ways to deduce where to put the semicolons. This can be deduced from the tokens that begins and ends lines.
Conscience is the debugger of the mind

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Making the semicolon useless
« Reply #61 on: April 05, 2020, 11:42:54 am »
I believe there are ways to deduce where to put the semicolons. This can be deduced from the tokens that begins and ends lines.
Well, adapt the grammar. Can you provide proof for these "ways"? Because I can prove it will not work. (disprove)
The simplest parsetree will already fail because of dis-ambiguity.
« Last Edit: April 05, 2020, 11:45:25 am by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Making the semicolon useless
« Reply #62 on: April 05, 2020, 12:05:31 pm »
I am talking about having the Source editor showing a code without semicolons. Either by converting it on the fly, or indeed by a compiler option. Such option need not a new compiler but could just enable a preprocessor that adds the semicolons.

(Opague is the known troll nov97/giahung that likes to stir up language discussions. Note he never posts any Pascal code, and often compares to Freebasic, and often "pretends" to have discover new languages.  He just posts to create offtopic threads and keep them running)

As said several times, there are a few caveats that make this hard, even with correct code. But incorrect code will be mangled and the resulting errors will be incomprehensible. Which is the usual problem with hamfisted preprocessor usage.

Quote
I believe there are ways to deduce where to put the semicolons. This can be deduced from the tokens that begins and ends lines.

There are no tokens in pascal compilers for that. The scanner filters them already out before producing the real tokens.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Making the semicolon useless
« Reply #63 on: April 05, 2020, 12:54:54 pm »
I believe there are ways to deduce where to put the semicolons. This can be deduced from the tokens that begins and ends lines.
Getting rid of semicolons is not that simple.  For instance
Code: Pascal  [Select][+][-]
  1. procedure aproc(var a; d, e, f : Boolean);
when the entire statement is syntactically correct, it's not too hard to figure out where there should be a semicolon but, if there is a syntax error then it's a completely different story.  For instance
Code: Pascal  [Select][+][-]
  1. procedure aproc(var a d, e, f : Boolean);
parameter "a" is in both cases untyped and if the semicolon is missing between the "a" and "d", most Pascal compilers don't even try to emit the correct error message because the resulting statement is syntactically ambiguous.  "a" may be an untyped parameter, in which case there should be a semicolon between "a" and "d".  if the problem is that the comma is missing, the compiler _assumes_ that "d" is a data type and says it expected a colon ":" (which is incorrect in this case since "d" is not a data type) when it could have easily been that the comma is the missing element.

For a preprocessor to have _some_ chance of accurately placing semicolons in the source, it would have to be a complete parser (one that would have to be _smarter_ than the one implemented in the compiler.)  It would have to know that if "d" is a data type, either a colon between "a" and "d" or a semicolon after "a" are required.  There is no way for the parser (no matter how smart it may be) to figure out which case is applicable because there isn't enough auxiliary syntactic information in the statement to make the determination (without using type information.)

Your "semicolon paster" would end up declaring untyped parameters every time there is a comma missing between "var" parameters resulting in one parameter being untyped and the remainder being passed by value instead of reference and, the worst part is, the programmer would not have a clue that the missing comma resulted in a definition with a completely different meaning than what he/she intended.

And that doesn't include the additional problems caused by the possibility that the programmer forgot the "var" keyword (which is required to declare untyped parameter but not typed ones.)

It is also worth noting that while parsing Pascal is usually reasonably fast, your preprocessor, if it were a full parser, it would definitely result in perceptibly slower compile times.



« Last Edit: April 05, 2020, 12:57:12 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Making the semicolon useless
« Reply #64 on: April 05, 2020, 01:33:33 pm »
It is also worth noting that while parsing Pascal is usually reasonably fast, your preprocessor, if it were a full parser, it would definitely result in perceptibly slower compile times.

The preprocessor could be built into the IDE, and only update modified versions of the source files. Adding external preprocessor support to FPC has been rejected already many times.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Making the semicolon useless
« Reply #65 on: April 05, 2020, 01:45:09 pm »
Writing bindings is not the issue. You have to prove you can do it in the language itself...
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Making the semicolon useless
« Reply #66 on: April 05, 2020, 01:47:19 pm »
I would like to say that the question posed by circular is interesting, I believe that any proposal that aims to discuss a possible greater spread of Lazarus/FPC is to be considered. Simplifying code writing might be useful for this purpose.

If the feature results in increased maintenance (in this case increased complexity of the parser) for no real gain (really, you are all arguing about semicolons?!), then no it's not even remotely worth to be considered.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Making the semicolon useless
« Reply #67 on: April 05, 2020, 01:49:04 pm »
@opaque

Please calm down sir.
Just some misunderstanding.

I can understand why some people here are too sensitive. Recently the forum has been repeatedly visited by trolls (or maybe a troll).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Making the semicolon useless
« Reply #68 on: April 05, 2020, 02:01:45 pm »
Really? Did you forgot I done a IUP binding for Pascal and code is still on my github?

One swallow doesn't make summer.

Quote
Did you ever see I compared Pascal with Basic except I said Basic code is twice as long as Pascal and I don't like long code?

Yes, a whole monologue about that.

Quote
Did I said anything about other language except the news about Ada++ I found on Phoronix? Sorry if it's insult you but I only want to know how people react to such news and you are too sensitive. Reread the first post on my Ada++ thread, I said: "I will just put it here and don't said anything", did I post anything after that?

You posted an url-only post about it twice, one of which in a new thread. And you have been warned against such behaviour before.

Quote
Did you have proof I'm a troll? Please show it. Otherwise don't make such claim, so everyone would ignore me and all of my threads asking for help.

I have several likenesses in behaviour and account data, some of which I have commented on here. If you insist, I'll pass it all on to my co moderators for judgement in a query about account deletion.

Or you can just own up to it, and get a fair last chance, just because I also overstepped a bit in a bad mood.

Despite you deleted your account the last time when I pmed you with warnings, I should still have gone that way instead of posting in the thread out of the blue. Mea culpa, and a last chance for you if you are honest about it.

Quote
If you want, just delete my thread about Ada++.

Done.

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Making the semicolon useless
« Reply #69 on: April 05, 2020, 06:32:15 pm »
Quote
I believe there are ways to deduce where to put the semicolons. This can be deduced from the tokens that begins and ends lines.
There are no tokens in pascal compilers for that. The scanner filters them already out before producing the real tokens.
I was talking about the tokens like "+" etc. I was kind of expecting the end of lines not to be tokens but discarded as whitespace. Is it possible to know the position of a token? If not then that would make it difficult to add the preprocessor in the current compiler stack.

Though for an external tool, that's not complicated to add a way to determine tokens location.

Your "semicolon paster" would end up declaring untyped parameters every time there is a comma missing between "var" parameters resulting in one parameter being untyped and the remainder being passed by value instead of reference and, the worst part is, the programmer would not have a clue that the missing comma resulted in a definition with a completely different meaning than what he/she intended.
No no I am talking about semicolons for instruction ending. And in fact I am ok for semicolons within the line.
« Last Edit: April 05, 2020, 06:35:07 pm by circular »
Conscience is the debugger of the mind

GypsyPrince

  • Guest
Re: Making the semicolon useless
« Reply #70 on: April 05, 2020, 06:56:42 pm »
Quote
Here are some thoughts.  The exception you mentioned creates an inconsistency, sometimes the semicolon would be required, other times it wouldn't be.

In my own worthless opinion, I agree with 440bx on this point.
Inconsistency makes things more difficult and inefficient.

While I have no particular sway toward using the semicolon or not, I do agree that it should be used consistently or not at all.  But again, that is just my own opinion.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Making the semicolon useless
« Reply #71 on: April 05, 2020, 10:03:24 pm »
@PascalDragon

Hello.
I'm sorry for the misunderstanding caused by me.
I would like to say that the question posed by circular is interesting, I believe that any proposal that aims to discuss a possible greater spread of Lazarus/FPC is to be considered. Simplifying code writing might be useful for this purpose.

If the feature results in increased maintenance (in this case increased complexity of the parser) for no real gain (really, you are all arguing about semicolons?!), then no it's not even remotely worth to be considered.

It is possible that I did not explain myself clearly enough, but in the rest of my post (which you did not report) I explained that I am absolutely opposed to the abolition of the ";".
In fact, I took the example of how difficult it is, sometimes, to identify the true cause of errors within codes written in VB.net (language that does not use the ";") and the risk that pascal would take if it eliminated the ";".

I also suggested, in case it was necessary, the use of an external tool to convert the code from VB.pascal (proposed by circular) to FPC.

The introductory speech (which you have reported) is a general consideration, I think circular had a positive purpose in proposing it.
For me, an interesting proposal should be discussed even if I do not approve of the content of the proposal itself.

Otto.
Kind regards.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Making the semicolon useless
« Reply #72 on: April 05, 2020, 11:26:22 pm »
Quote
I believe there are ways to deduce where to put the semicolons. This can be deduced from the tokens that begins and ends lines.
There are no tokens in pascal compilers for that. The scanner filters them already out before producing the real tokens.
I was talking about the tokens like "+" etc. I was kind of expecting the end of lines not to be tokens but discarded as whitespace. Is it possible to know the position of a token? If not then that would make it difficult to add the preprocessor in the current compiler stack.

(purely hypothetical, as you are obviously not going to implement it, and nobody else believes it is doable)

There is an ability for location (line, column) of the current token I think. Most parsers do since that is needed to generate error information.

Since a compiler error needs that info. But the scanner (which includes the FPC internal preprocessor) and the parser are intertwined. It would be a colossal job to detangle them, create a new level inbetween to splice the external preprocessor into etc.

Quote
Though for an external tool, that's not complicated to add a way to determine tokens location.

Keep in mind the external tool would be extremely complicated since any manipulations must keep the token stream equivalent or the errors would be on the a different line and number. Study how the C preprocessor works etc etc.

And before to even attempt such thing (and then again, already purely hypothetical), you would have to demonstrate the concept using an own fork of FPC first, before one starts rearranging the whole parser.

Anyway, I think this is a dead end. If you really want something like that, you're better off crafting some language based on syntax concepts of a language that has no need for statement terminators like python or basic.
« Last Edit: April 06, 2020, 09:48:36 am by marcov »

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Making the semicolon useless
« Reply #73 on: April 06, 2020, 12:17:08 am »
No no I am talking about semicolons for instruction ending. And in fact I am ok for semicolons within the line.
Even only in the case of instruction ending, it's not only the compiler that uses the semicolons to figure things out.  Tools like "codetools" and the "Code Explorer" (and possibly others) in the IDE, are almost certain to depend on semicolons in one way or another to do their job (I haven't looked at their implementation, therefore I cannot be precise about this.)

The more I think about it, the more I believe it is not feasible.  Eliminating the semicolon affects the syntactic structure of the language and, there are a lot of consequences to that.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Making the semicolon useless
« Reply #74 on: April 06, 2020, 09:30:59 am »
@PascalDragon

Hello.
I'm sorry for the misunderstanding caused by me.
I would like to say that the question posed by circular is interesting, I believe that any proposal that aims to discuss a possible greater spread of Lazarus/FPC is to be considered. Simplifying code writing might be useful for this purpose.

If the feature results in increased maintenance (in this case increased complexity of the parser) for no real gain (really, you are all arguing about semicolons?!), then no it's not even remotely worth to be considered.

It is possible that I did not explain myself clearly enough, but in the rest of my post (which you did not report) I explained that I am absolutely opposed to the abolition of the ";".
In fact, I took the example of how difficult it is, sometimes, to identify the true cause of errors within codes written in VB.net (language that does not use the ";") and the risk that pascal would take if it eliminated the ";".

I also suggested, in case it was necessary, the use of an external tool to convert the code from VB.pascal (proposed by circular) to FPC.

The introductory speech (which you have reported) is a general consideration, I think circular had a positive purpose in proposing it.
For me, an interesting proposal should be discussed even if I do not approve of the content of the proposal itself.

Otto.

It's not only about this specific topic (the semicolons), but your generalisation I don't agree with:

I believe that any proposal that aims to discuss a possible greater spread of Lazarus/FPC is to be considered.

 

TinyPortal © 2005-2018