Recent

Author Topic: Can FreePascal be used to create an internal or embedded DSL?  (Read 4841 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 4577
  • Compiler Developer
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #75 on: August 19, 2022, 09:52:03 am »
There are certain places where our error reporting could be better though whether they're due to the recursive descent parser or not I can't say right now. And recovery needs to be taken into account at each location and so depending on the error it's a bit hit and miss. Don't know whether a non-RD parser would really fare better there however...

Thanks for that and please note that I definitely wasn't complaining. Noting that I'm only repeating suggestions I've read, my /suspicion/ is that it relates to a compiler's ability to report more than the first syntax error it encounters.

Well, we do try to develop the compiler in a way that more than one error is reported (e.g. if you compare with pas2js which more often than not does stop after the first error it finds), but some times recovery either isn't easy (especially when it's really the syntax that is off and not simply a missing identifier) or was not implemented correctly or at all.

Quote
what do you mean with “lock-down at the OS level”?

Set a file read-only to less-privileged users.

And what would be the advantage here to only set the implementation to read-only, but not the interface as well? And if you don't want users to manipulate that why not simply provide it binary only? If it's to allow the user to compile for a different platform then what stops them from simply copying all files to a location where it isn't read-only, do their intended changes and go their merry way?

MarkMLl

  • Hero Member
  • *****
  • Posts: 5236
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #76 on: August 19, 2022, 10:47:23 am »
Quote
And what would be the advantage here to only set the implementation to read-only, but not the interface as well?

I was assuming they were: I /did/ say "lock-down at the OS level files containing definitions or complex hacks".

Quote
why not simply provide it binary only?

Depends on how the separate compilation works... /if/ it's done at all. Noting that my comments are in the general case rather than pertaining to any particular Pascal compiler or derivative, I suspect that never carrying around baggage relating to exception handling etc. implies that separate compilation would be to the AST level with actual code generation only after all calls into or out of a block had been resolved.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4577
  • Compiler Developer
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #77 on: August 19, 2022, 02:09:36 pm »
Quote
And what would be the advantage here to only set the implementation to read-only, but not the interface as well?

I was assuming they were: I /did/ say "lock-down at the OS level files containing definitions or complex hacks".

And then why the separation if both are locked down anyway?

Quote
why not simply provide it binary only?

Depends on how the separate compilation works... /if/ it's done at all. Noting that my comments are in the general case rather than pertaining to any particular Pascal compiler or derivative, I suspect that never carrying around baggage relating to exception handling etc. implies that separate compilation would be to the AST level with actual code generation only after all calls into or out of a block had been resolved.

What has how the separate compilation is done to do with whether or not you'd provide a binary only module?

MarkMLl

  • Hero Member
  • *****
  • Posts: 5236
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #78 on: August 19, 2022, 02:32:48 pm »
And then why the separation if both are locked down anyway?

Because in different contexts you might want to lock different files against unauthorised modification.

For example, interface descriptions once finalised should probably be locked down. For anotherexample, an implementation which contains code which should not be modified by a junior team member should probably be locked down.

In addition, taking into account Google vs Oracle, we're heading for a situation where it might be desirable to hold factual definitions and detailed implementations in different files, because different standards of copyright apply. I don't think anybody's yet tried to apply different copyrights or licenses to different portions of the same file: the situation's bad enough as it is.

Quote
What has how the separate compilation is done to do with whether or not you'd provide a binary only module?

Because if separate compilation targetting assembler cannot express the semantics of the language, then you need to look at a higher-level representation: emitting a unit coded at the AST level, or not compiling to binary at all.

For example, the way that Stallman found that the Pastel language assumed the host was big enough to hold the entire AST in memory until every reference (e.g. to parameterised types) could be resolved. And I suspect that parameterised types are a distant ancestor of generics.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Wysardry

  • Jr. Member
  • **
  • Posts: 53
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #79 on: August 20, 2022, 08:08:57 am »
Due to a crash, I had to run chkdsk on my laptop which took over 12 hours (not sure how long as I stopped checking after that). I have only managed to get halfway through the first sample chapter because of this.

I did start to read the first "Writing an Interpreter in Object Pascal" book though.

It isn't as detailed as it could be, as whenever the author chooses a particular option he doesn't always say what the alternatives are, just why he chose it. I suspect that those more experienced with Pascal wouldn't need this explained.

He does intend to describe how to include a REPL interactive shell for the BASIC-like language though, allowing programs to be stopped, edited and then continued as many of the 8-bit machines did.

So far, the language syntax seems more like a mix of BASIC and Pascal. Maybe that will change in version 2, which is described in book 3 (not yet published).

Everything is being created from scratch using Delphi or FreePascal, without the use of Yacc or ANTLR. I'm not sure if that's a good thing.

I get the feeling that the entire process will stretch to four books (it was originally only supposed to have been two).

MarkMLl

  • Hero Member
  • *****
  • Posts: 5236
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #80 on: August 20, 2022, 09:14:14 am »
So far, the language syntax seems more like a mix of BASIC and Pascal. Maybe that will change in version 2, which is described in book 3 (not yet published).

Yes, because the objective is to illustrate a book rather than write a decent software tool.

But you must understand that tools like YACC weren't available to Wirth or (realistically) Borland in the early days, and you must understand that the compilation technique they use is not necessarily the best for a Pascal-like language. Wirth's early compilers predated recursive descent, and you /really/ don't want to try to make sense of them.

And I'm unconvinced that you can do a REPL for Pascal, since blocks have to be closed before they are meaningful.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Wysardry

  • Jr. Member
  • **
  • Posts: 53
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #81 on: August 20, 2022, 06:12:49 pm »
I haven't reached the point where he explains the REPL in detail, but the source code for all three books is available in his Rhodus Interpreter Repositories if you're curious.

The language is named after his dog Rhody.

I imagine it works along the lines of the old BASIC interpreters in that it only does a cursory syntax check when entering each line of code then does a more thorough check at runtime.

BASIC included blocks with opening and closing keywords, but many interpreters would allow you to run an incomplete program and only complain when/if they reached the part with the missing code.

This was a blessing and a curse if you had a program with many conditional branches as you might not find an error (such as having next x and next y in the wrong order) until days after you thought you'd finished a section of code in a long program.

If your version of BASIC didn't support procedures, you often had to add a temporary GOTO or GOSUB to test new code near the end of a program. In the 80s there wasn't much support for separating code into multiple files either.

MarkMLl

  • Hero Member
  • *****
  • Posts: 5236
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #82 on: August 20, 2022, 06:25:32 pm »
I haven't reached the point where he explains the REPL in detail, but the source code for all three books is available in his Rhodus Interpreter Repositories if you're curious.

I'm not. I've got enough problems of my own, have already seen more than my share of dodgy language implementations, and have already said that my knowledge of the art leads me to believe that a half-decent compiler (or compiler/interpreter etc.) can be more easily written for an ALGOL-derivative than for a BASIC- or FORTRAN-derivative.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

y.ivanov

  • Hero Member
  • *****
  • Posts: 521
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #83 on: August 21, 2022, 12:41:24 pm »
I haven't reached the point where he explains the REPL in detail, but the source code for all three books is available in his Rhodus Interpreter Repositories if you're curious.
*snip*
And what REPL has to do in you multi-target bulder idea?

Later BASICs (e.g. QBasic) are structured and much closer to Pascal. Home micro BASICs aren't and thus suitable for being REPL-ed.

Just learn how to use Plex and Pyacc. They're off the shelf solutions. It will take much less time.   

 
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Wysardry

  • Jr. Member
  • **
  • Posts: 53
Re: Can FreePascal be used to create an internal or embedded DSL?
« Reply #84 on: August 21, 2022, 07:52:44 pm »
A REPL would be useful for testing programs on the modern front end. The next best thing would be a modern interpreter.

Second generation structured BASIC dialects were available with a REPL on some machines. BBC BASIC is probably the most well known, but IS-BASIC on the Enterprise was an implementation of ANSI Full BASIC.

The books I have so far on writing an interpreter include a REPL as part of the language construction. I doubt it would be a good idea to just skip those parts.

I've never created a language before, so I would need a guide for at least the first attempt. These were the only recent books I could find aimed at using Pascal.

I would much rather modify an existing language if possible. I'm not aiming for anything totally new after all.

 

TinyPortal © 2005-2018