Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Compiler > Re: BASIC gramm...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 14 Topic 75 of 149
Post > Topic >>

Re: BASIC grammar

by "Stephen J. Rush" <steverush1@[EMAIL PROTECTED] > Mar 8, 2004 at 01:58 PM

On Mon, 08 Mar 2004 14:51:57 +0000, J French wrote:

> On Tue, 09 Mar 2004 01:35:52 +1100, Johnathan
> <zork_666@[EMAIL PROTECTED]
> wrote:
> 
>>Hi,
>>
>>I'm looking for a BASIC grammar.  Not necessarily the original BASIC 
>>language - I'd be happy with a more modern dialect like QBasic.  I can 
>>infer a lot from Microsoft's QBASIC help file, but I'd really like to 
>>get my hands on a LL(1) grammar.  I could probably try to write my own, 
>>but I don't know enough about compiler theory to do it.  I'd like to 
>>take a stab at writing a recursive descent parser.  So bearing this in 
>>mind, small is beautiful at this stage. :)
> 
> And in what language would you write the recursive parser ?

If you've never tried it before, start with the smallest subset of BASIC
that you can write nontrivial programs in.  I've never tried to analyze
it, but I suspect that QBasic's grammar isn't LL1.  You can write a
recursive-descent parser in any language. It helps if the language
supports recursive functions, so you don't have to maintain your own
stack, but you could theoretically do it on a Turing machine, given a few
man-centuries of programming effort.

Seriously, it's been done in Pascal and QuickBasic.  I worked through most
of Jack Crenshaw's "Let's Build A Compiler!" tutorial (see
http://compilers.iecc.com/crenshaw/),
translating his Pascal code into
QuickBasic as I went along.  It wasn't that hard, given QB's Pascal - like
control structures and the trick of using strings to represent sets, so
that INSTR() can serve as the membership function.  Crenshaw's "Tiny"
language is far smaller than any BASIC, but I wound up with a compiler
that actually worked (under real-mode DOS; *don't* try this in a
Windows environment).

Some caveats: Crenshaw never finished the series; it peters out after
introducing procedures. The target processor is the Motorola 68000 (a
much nicer architecture than the 8086; WHY did IBM have to bless Intel's
kluge?). One of his fans published an assembly-language runtime package
for the 8086, and I grabbed that and wrote my own code generator routines
to emit 8086 assembler code.

It would be a _lot_ of work to go from the end of Crenshaw's series to a
practical compiler, even in a DOS environment, but it's a good exercise.
Dogpile still shows the original link, along with some others for
"Crenshaw compiler tutorial."




 14 Posts in Topic:
BASIC grammar
Johnathan <zork_666@[E  2004-03-09 01:35:52 
Re: BASIC grammar
erewhon@[EMAIL PROTECTED]  2004-03-08 14:51:57 
Re: BASIC grammar
Johnathan <zork_666@[E  2004-03-09 04:52:32 
Re: BASIC grammar
"Stephen J. Rush&quo  2004-03-08 13:58:24 
Re: BASIC grammar
Johnathan <zork_666@[E  2004-03-09 08:02:15 
Re: BASIC grammar
arargh403NOSPAM@[EMAIL PR  2004-03-08 16:01:11 
Re: BASIC grammar
Johnathan <zork_666@[E  2004-03-09 19:16:56 
Re: BASIC grammar
arargh403NOSPAM@[EMAIL PR  2004-03-09 14:29:56 
Re: BASIC grammar
arargh403NOSPAM@[EMAIL PR  2004-03-10 02:14:26 
Re: BASIC grammar
arargh403NOSPAM@[EMAIL PR  2004-03-08 15:47:38 
Re: BASIC grammar
"Markku Alén" &  2004-03-08 23:30:26 
Re: BASIC grammar
Johnathan <zork_666@[E  2004-03-09 19:22:03 
Re: BASIC grammar
"Markku Alén" &  2004-03-21 02:31:17 
Re: BASIC grammar
"Scott Moore" &  2004-03-10 08:22:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 22:27:07 CDT 2008.