Re: newbie: making a BASIC comiler

Robert Dimond <>
12 Feb 2003 13:44:26 -0500

          From comp.compilers

Related articles
newbie: making a BASIC comiler (Gernot) (2003-02-06)
Re: newbie: making a BASIC comiler (Robert Dimond) (2003-02-12)
Re: newbie: making a BASIC comiler (2003-02-21)
| List of all articles for this month |

From: Robert Dimond <>
Newsgroups: comp.compilers
Date: 12 Feb 2003 13:44:26 -0500
Organization: Ye 'Ol Disorganized NNTPCache groupie
References: 03-02-029
Keywords: Basic
Posted-Date: 12 Feb 2003 13:44:26 EST

Gernot wrote:
> I did a BASIC compiler on my own, but now, that files are getting
> bigger&bigger, it's too slow. (I used lot's of string replacements - pretty
> crappy, huh!?)
> I want to make a new version using LEX/YACC (at least I think I want to).
> - Can I do this with LEX/YACC, or what is best to use?
> - Can the BASIC contain user defined functions?
> - What about local variables?


You can certainly use lex and yacc for the lexing and parsing stages of
your compiler (as far as the AST), although you'll have to do all the
code generation yourself.

> - And process include files or multiple file input?
Again no problems...

> - Can I define structures? That would be cool, but neccessary.
> brand$
> color
> DIM veh AS Car
> veh.brand$ = "Fauxpas"
> veh.color = RGB(255,0,0)

I think there is some confusion here... lex and yacc don't actually do
that much for you... it's up to you to implement stuff like this.

> - On the other hand, I wish to have name and name$ automatically
> as global numbers and strings defined.
> - Has anybody some experience with BASIC and can give me
> some tips to avoid mistakes in the beginning?
> - Will the produced code be fast? My compiled code was
> (in contrary to the compiler) fast as heck. Will it be?

That's up to you. You'll have to try pretty hard to make it slower than
interpreted BASIC.

> - Will YACC create C-code or ASM?

C (or C++?)

> - What is a BNF?

A notation for describing a grammar.

> - Can I compile YACC with Visual Studio or only with GCC?

Never tried it but can't see why you'll have a problem.

> - When inserting new commands: Do I have to recompile the
> compiler, or can it read a file?

If you use yacc then yes unless you figure a way around it yourself.

> I'm sorry for the stupid beginners questions, and appreciate any help.

You really should read the dragon book (Aho, Sethi and Ullman) to get
you started. My gut feeling is that you'd be better off writing a
source to source translator (to C, for example) so you can benefit from
optimisations in the C compiler (which will be time consuming to
implement yourself).

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.