Honest question, wouldn't you just write a lexer with yacc/bison for a DSL? How does a full programming language act as a base for a DSL, which is usually more limited than a programming language?
Well for a lot of devices I've worked with, you can shoehorn Forth places that most (if not all) other languages short of assembler can not go (Forth is _really_ lightweight). Forth was designed with DSL's in mind (Forth has "vocabulary" which is targeted specifically at this); the language usually comes with a basic syntax and some core primitives built in, but features a really profound ability to define new primitives, even things like "if" that most languages have built-in and have no facilities for constructing variants. You might liken it to macros in Lisp.
I guess the other huge nice thing abort Forth for DSLs is that it is (unlike assembler or C), an interactive language, even on the most stripped down platforms (like bare bones $0.50 8-bit MCU stripped down), and still encourages the sort of REPL experimentation typically only seen in much much higher level languages. All of this comes at a big price though, in that the caliber of developer required to wield Forth in a sane manner tends to be very high.
A typical use case for Forth to launch from bare metal (more like bare silicon) into the application on embedded systems or as the bootstrap mechanism/BIOS for a more advanced OS on a larger, perhaps desktop, system. A Forth console over a serial port can provide a user with tons of low and high level access to a system. I built a 12 processor "parallel" robotics controller back in the '80's using a bunch of Rockwell R65F11 Forth processors (6502's with Forth in ROM).
> Honest question, wouldn't you just write a lexer with yacc/bison for a DSL?
Perhaps this article[1] can help answer the question (BTW, the title of the page belies its applicability). Check out Figure-1 specifically.
> How does a full programming language act as a base for a DSL, which is usually more limited than a programming language?
IMHO, this is what makes Forth both beautiful and mind bending, as Forth is a "full programming language" in which programs/systems written in it are expressed as a DSL defining the system itself. If that sounded recursive, then you're well on your way to grokking Forth :-).
The kernel for FORTH is crazy small. IIRC it's not unusual to shoe horn it into 2K. When people talk about writing DSLs in FORTH, I think what they are really saying is writing an API based on the FORTH kernel. So the DSL is really FORTH, but just with your API. Granted changing how words are compiled and executed is pretty much standard fare for a FORTH programmer, so you can make it work however you want.
FORTH is a bit like smalltalk in that you usually work in an interactive environment and save images. FORTH code compiles down to essentially a jump table and so it is also really, really efficient, space wise. You can decompile code easily and modify it in your image.
If you were trying to write a control language for some small embedded device, it would be ideal. If you were trying to write a DSL for configuring a build system (or something like that) it would be less nice ;-)
My first few paying jobs (when I was in university) was writing FORTH code, but that's a very long time ago ;-) I'm still quite nostalgic about it even though I've forgotten almost everythng I once knew.
the avantage of using a full programming language as a base for your DSL is that you don't have to deal with some of the "simpler" things.
Your base language already has variable assignment, loops, recursion? Great, you don't have to deal with that. Type checking? Wonderful, don't have to go read up on type inference
rpcope1|10 years ago
A good place to learn more (if you have some familiarity with Lisp) is: http://stackoverflow.com/questions/24282153/comparison-of-co...
I guess the other huge nice thing abort Forth for DSLs is that it is (unlike assembler or C), an interactive language, even on the most stripped down platforms (like bare bones $0.50 8-bit MCU stripped down), and still encourages the sort of REPL experimentation typically only seen in much much higher level languages. All of this comes at a big price though, in that the caliber of developer required to wield Forth in a sane manner tends to be very high.
rebootthesystem|10 years ago
AdieuToLogic|10 years ago
Perhaps this article[1] can help answer the question (BTW, the title of the page belies its applicability). Check out Figure-1 specifically.
> How does a full programming language act as a base for a DSL, which is usually more limited than a programming language?
IMHO, this is what makes Forth both beautiful and mind bending, as Forth is a "full programming language" in which programs/systems written in it are expressed as a DSL defining the system itself. If that sounded recursive, then you're well on your way to grokking Forth :-).
1 - http://www.forth.org/lost-at-c.html
mikekchar|10 years ago
FORTH is a bit like smalltalk in that you usually work in an interactive environment and save images. FORTH code compiles down to essentially a jump table and so it is also really, really efficient, space wise. You can decompile code easily and modify it in your image.
If you were trying to write a control language for some small embedded device, it would be ideal. If you were trying to write a DSL for configuring a build system (or something like that) it would be less nice ;-)
My first few paying jobs (when I was in university) was writing FORTH code, but that's a very long time ago ;-) I'm still quite nostalgic about it even though I've forgotten almost everythng I once knew.
rtpg|10 years ago
Your base language already has variable assignment, loops, recursion? Great, you don't have to deal with that. Type checking? Wonderful, don't have to go read up on type inference