Redefining existing keywords lazarus / 62-General ---------------------------------------------------------------------- Bofer · 2018-04-08 19:51 Is it possible to use {$define} in FPC to redefine existing reserved symbols? Quick trivial example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$define program := main}{$define begin := {}{$define end := }}{$define <> := !=} main someRandomProgram; var   s : string; {   s := 'Some random string.';   writeln(s);   readln}    (Perhaps in the example one must also take more care regarding the curly brackets. In any case, you get the idea.) ---------------------------------------------------------------------- Blaazen · 2018-04-08 19:55 Welcome to Free Pascal forum! ---------------------------------------------------------------------- Bofer · 2018-04-08 20:17 Quote from: Blaazen on April 08, 2018, 09:55:38 pm Welcome to Free Pascal forum! Hah hah, yes, thank you (but you did not answer the question, heh heh heh). I was just wondering if what I described is possible and how it all works. One reason for this is to learn FPC more and to possibly change some of the Pascal  syntax redundancies. One thing I want to do is to remove the begin keyword wherever it is used outside of the main program entry point. Is this at all possible in FPC by simply using {$define} and the necessary code, and, if yes, how would it work? Can one also, for example, change the <> operator? Just wondering. ---------------------------------------------------------------------- Edson · 2018-04-08 21:20 Symbols/Operators cannot be redefined that way. Delimiters { } are only for comments in Pascal. It's better you get used to Pascal syntax, instead of thinking of C. Using the IDE facilities can help a lot. ---------------------------------------------------------------------- Bart · 2018-04-08 21:29 Reminds me of this classic artice #include pascal.h on TheDailyWTF. Bart ---------------------------------------------------------------------- Bofer · 2018-04-08 23:13 Quote from: Edson on April 08, 2018, 11:20:55 pmSymbols/Operators cannot be redefined that way. Delimiters { } are only for comments in Pascal. It's better you get used to Pascal syntax, instead of thinking of C. Using the IDE facilities can help a lot. Then how, if using compiler directives? Or must one necessarily go to a deeper level in this case? (Why assume some of those things which you seemingly assumed? I am already used to Pascal syntax and it is even the programming language I prefer (and the first programming language I was exposed to). (I generally prefer Wirth-like imperative structured languages.) (But it is not for no good reason that Wirth himself invented other languages that improved upon Pascal.) And I am already using the IDE facilities, and even looked for information on the IDE on how to set up certain things which seemed to be tucked away. That example code (with or without C-like symbols) was trivial and was merely intended to get the thread going so that I may learn how this part of FPC works, if it can at all be done in such a way.) ---------------------------------------------------------------------- jamie · 2018-04-08 23:56 Fpc does have a couple of things from C *= += /= -= Does that bring a smile to your face ? ---------------------------------------------------------------------- Bofer · 2018-04-09 15:20 Quote from: jamie on April 09, 2018, 01:56:24 amFpc does have a couple of things from C *= += /= -= Does that bring a smile to your face ? Actually, it does not, nor do you. It seems to me that no one among you so far is willing to answer properly, but you rather seem to be willing to respond fallaciously. You probably even misunderstood some of my words and made conclusions you were not rationally allowed to make. I suppose it is a waste of time to further visit this forum. ---------------------------------------------------------------------- Thaddy · 2018-04-09 15:28 You can define some but not all keywords using the macro facility. You can override operators as well. What is the exact question? You have to be more exact.  I demo'd a crude "Dutch Pascal: here on the forum using macro's... works like a charm... See this: http://forum.lazarus.freepascal.org/index.php/topic,36887.ms g246265.html#msg246265 ---------------------------------------------------------------------- jamie · 2018-04-10 02:03 @bofer   Thanks, you made my day, you actually put a smile on my face, really!   You know you could always use FPC as a back end and write a language of your choice!  I did something like that years ago for a friend that knew fortran very well but didn't want to learn anything else, so I wrote a simple IDE using TP and used TP as a backend and had the IDE convert all of his fortran codings to object pascal at compile time and then had TP compile that!.  It's your ball game. ---------------------------------------------------------------------- Ñuño_Martínez · 2018-04-10 11:17 Quote from: Bofer on April 08, 2018, 10:17:01 pmQuote from: Blaazen on April 08, 2018, 09:55:38 pm Welcome to Free Pascal forum! Hah hah, yes, thank you (but you did not answer the question, heh heh heh).Actually he did. Quote from: Bofer on April 08, 2018, 10:17:01 pmI was just wondering if what I described is possible and how it all works. One reason for this is to learn FPC more and to possibly change some of the Pascal  syntax redundancies.Redundancies?  Pascal is one of the less redundant language ever! Or the Wirth's initial description was, right now thanks to operator orverloading and generics it is a bit more redundant but still less redundant than C and much less than C++. Except you mean "redundant -> superfluous stuff".  Pascal has so much superfluous stuff as many other high level language (and C is not a high level language).  May be more than Python, but who would use a language that uses indentation to define code blocks?  That's crazy! Quote from: Bofer on April 08, 2018, 10:17:01 pmOne thing I want to do is to remove the begin keyword wherever it is used outside of the main program entry point. Is this at all possible in FPC by simply using {$define} and the necessary code, and, if yes, how would it work? Why? Quote from: Bofer on April 08, 2018, 10:17:01 pmCan one also, for example, change the <> operator? Just wondering. Use operator overloading. ---------------------------------------------------------------------- rvk · 2018-04-10 11:43 Quote from: Thaddy on April 09, 2018, 05:28:11 pm I demo'd a crude "Dutch Pascal: here on the forum using macro's... works like a charm... See this: http://forum.lazarus.freepascal.org/index.php/topic,36887.ms g246265.html#msg246265 Yes, that was a really lovely example What keywords can't be redefined? Because even begin and end can be redefined. The only thing is that you can't redefined it TO { and } (as OP wanted). But this works. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$macro on}{$define main := program}{$define al := begin}{$define la := end}main someRandomProgram;var   s : string;al   s := 'Some random string.';   writeln(s);   readlnla. OP just mixed up the defines (before the := and after) and you can't use { and } obviously. But yeah, I agree with the others... this is a fun exercise but don't go programming like this. ---------------------------------------------------------------------- PascalDragon · 2018-04-10 14:53 Quote from: Bofer on April 08, 2018, 09:51:21 pmIs it possible to use {$define} in FPC to redefine existing reserved symbols? Quick trivial example: No, you can't and the compiler even tells you that (once you add {$macro on} at the beginning): Code: [Select]Free Pascal Compiler version 3.0.4 [2017/12/03] for i386 Copyright (c) 1993-2017 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling .\fpctests\tdefine.pas tdefine.pas(3,3) Error: Keyword redefined as macro has no effect tdefine.pas(14,2) Fatal: Unexpected end of file tdefine.pas(14,2) Fatal: Compilation aborted ---------------------------------------------------------------------- Thaddy · 2018-04-10 15:04 @PascalDragon Indeed, no reserved symbols, but keywords? Yes. As I demo'd... If it is an operator you can overload it in many cases. So yes, but... (I can make up a "Sven" language if you like  )