EmbeddedRelated.com
Forums

ideas for a BASIC compiler

Started by Frank Buss June 1, 2008


AZ Nomad wrote:

>Read a book on yacc. It'll let you build compilers >for just any architecture and in any grammar.
Really? Ever tried to build a FORTH compiler using YACC? Hint: Forth has no syntax...
On Tue, 03 Jun 2008 00:53:56 +0000, invalid@example.com <invalid@example.com> wrote:



>AZ Nomad wrote:
>>Read a book on yacc. It'll let you build compilers >>for just any architecture and in any grammar.
>Really? Ever tried to build a FORTH compiler using YACC?
why?
>Hint: Forth has no syntax...
irrelevent If you have the computing facilities for a BASIC compiler, you can probably scrounge up a 60mhz machine and run a compiler for a real language, one that is defined by accepted standards and has a portable code base. FORTH became irrelevent when acquiring a 16mhz machine with 64K of ram became trivial. Also, FORTH is a write-only language. Few people like wading through pages of stuff like "OVER + SWAP DO". It was great for small minis during the 70's or small micros during the 80's, but it's usefulness has come and gone.
On Mon, 02 Jun 2008 04:42:13 -0500, AZ Nomad
<aznomad.3@PremoveOBthisOX.COM> wrote:

>On Mon, 2 Jun 2008 06:31:06 +0200, Frank Buss <fb@frank-buss.de> wrote: >>AZ Nomad wrote: > >>> Lovely. Pick a language that in it's 'standard' form is too much of a piece >>> of shit to do anything useful. Pick a language that has to be extended to >>> the point of being incompatible with the other thousand varients calling >>> themselves basic. Where can I sign up? I really want a language that won't >>> permit me to reuse any of of my code and which won't work with any previously >>> developed libraries. > >>Usually you don't need previously developed libraries for small embedded >>systems and products like this: >Oh, really? You never have to interface to any other devices? You write >all your interface code?
How much of that interface code is actually portable ? The higher level application code might benefit from portability, but anyway, if you have a good and tested code in any language in front of you, it shouldn't be too hard to rewrite the code in your favorite language. Paul
On Mon, 02 Jun 2008 20:13:29 -0500, AZ Nomad
<aznomad.3@PremoveOBthisOX.COM> wrote:

>FORTH became irrelevent when acquiring a 16mhz machine with 64K of ram became >trivial. Also, FORTH is a write-only language. Few people like wading through >pages of stuff like "OVER + SWAP DO". It was great for small minis during >the 70's or small micros during the 80's, but it's usefulness has come and >gone.
I suspect that you know little or nothing about modern Forth systems. Where Forth scores is in providing interactivity both for debugging and at run time, e.g. for CGI and web scripting. Modern Forth systems use the same compilation techniques as other languages such as C, and so you get both interactivity and performance. A side effect of Forth is that the anonymous parameter passing encourages factoring, and hence code reuse. A consequence of this is that good Forth code tends to be smaller than the equivalent C code. It is very rare to be able to write the same application in two languages, but on the one occasion I've seen it done, the Forth system fitted in 32k, and the C code exceeded the 64k limit of the CPU's code space. The application was a significant patment terminal system, and the programmers in both langauages were rated as good/guru by their peers. Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads


AZ Nomad wrote:
> >invalid@example.com wrote: > >>AZ Nomad wrote: > >>>Read a book on yacc. It'll let you build compilers >>>for just any architecture and in any grammar. > >>Really? Ever tried to build a FORTH compiler using YACC? > >why?
Because it shows a basic flaw in YACC -- there exists a simple language (an infinite number of them, actually) that YACC cannot create a compiler for. Because it shows that your "It'll let you build compilers for just any architecture and in any grammar" statement above is incorrect.
>>Hint: Forth has no syntax...
>irrelevent
Very much relevent. YACC cannot create compilers with no syntax.
>If you have the computing facilities for a BASIC compiler, you can probably >scrounge up a 60mhz machine and run a compiler for a real language, one that >is defined by accepted standards and has a portable code base. > >FORTH became irrelevent when acquiring a 16mhz machine with 64K of ram became >trivial. Also, FORTH is a write-only language. Few people like wading through >pages of stuff like "OVER + SWAP DO". It was great for small minis during >the 70's or small micros during the 80's, but it's usefulness has come and >gone.
WAAAAHHH!! That mean old man pointed out that I was wrong about YACC! Now I am going to cry and whine that only that limited subset of compilers that YACC can create are worth anything!! Boo Hoo!!!
invalid@example.com wrote:
> AZ Nomad wrote: >> invalid@example.com wrote: >>> Hint: Forth has no syntax... >> irrelevent > > Very much relevent. YACC cannot create compilers with no syntax.
Even though YACC stands for Yet Another Compiler Compiler, it cannot create compilers at all. It does help with the error prone task of creating a parser, but after that you are pretty much on your own. And the task of compiler implementation has only just begun. It is a long time since I played around with Forth, but surely there is some syntax. I don't remember if tokenization rules are hardwired, but if they are, then you can write a trivial syntax description in Yacc that recognizes tokens. Even if you can change the tokenization rules, it is always possible to write a Yacc grammar that recognizes single-character terminal symbols and lets the semantic action take care of tokenization. Not very practical, I admit, but I don't think that was a part of the spec to begin with. -- Pertti
In message <slrng496lp.qkv.aznomad.3@ip70-176-155-130.ph.ph.cox.net>, AZ 
Nomad <aznomad.3@PremoveOBthisOX.COM> writes
>FORTH became irrelevent when acquiring a 16mhz machine with 64K of ram became >trivial.
This is comp.arch.embedded?
> Also, FORTH is a write-only language.
The same can be said of any language. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

invalid@example.com wrote:

> AZ Nomad wrote: > > >Read a book on yacc. It'll let you build compilers > >for just any architecture and in any grammar. > > Really? Ever tried to build a FORTH compiler using YACC? > > Hint: Forth has no syntax...
Forth does have a syntax. YACC might not be my choice of implementation parsers but it probably could be used. w..
On 2008-06-03, invalid@example.com <invalid@example.com> wrote:
> > AZ Nomad wrote: > >>Read a book on yacc. It'll let you build compilers >>for just any architecture and in any grammar. > > Really? Ever tried to build a FORTH compiler using YACC? > > Hint: Forth has no syntax...
Forth certainly does have syntax, it is just very regular and there isn't much of it. A yacc parser for forth is fairly straightforward. Where yacc has problems is with grammars that are not context free, which is generally a Bad Thing any in programming language design. Try writing a yacc parser for e.g. troff source and/or output files, or even HTML, and you soon give up and decide to write the parser by hand. I'm always relutant to do this because hand written parsers invariably end up as messy bits of code in my experience but sometimes that can't be helped. -- Andrew Smallshaw andrews@sdf.lonestar.org
On Tue, 3 Jun 2008 12:06:37 +0100, Chris H <chris@phaedsys.org> wrote:
>In message <slrng496lp.qkv.aznomad.3@ip70-176-155-130.ph.ph.cox.net>, AZ >Nomad <aznomad.3@PremoveOBthisOX.COM> writes >>FORTH became irrelevent when acquiring a 16mhz machine with 64K of ram became >>trivial.
>This is comp.arch.embedded?
>> Also, FORTH is a write-only language.
>The same can be said of any language.
No. Most langauges are read-write languages in that you can actually read the code you've written. Forth, as a write-only language, gives you code that is nearly completely unreadable. Unless, of course, you like reading pages and pages of "OVER + SWAP DO"