Re: newbie: making a BASIC comiler (Vij Kal VijayaRaghavan Kalyanapasupathy)
21 Feb 2003 01:24:20 -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: (Vij Kal VijayaRaghavan Kalyanapasupathy)
Newsgroups: comp.compilers
Date: 21 Feb 2003 01:24:20 -0500
References: 03-02-029 03-02-074
Keywords: Basic
Posted-Date: 21 Feb 2003 01:24:20 EST

Robert Dimond <> wrote in message news:03-02-074...
> 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?
> [snip]
> 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.
> > STRUCT Car
> > 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.

I don't use YACC and LEX that much except that I am writing a LEX-like
program to generate JAVA code(i want a builtin lexanal and parser for
a netmgmt tool that can load mib files on the fly) (of course there is
one called JLex somewhere, probably Princeton).

In any case as far as I know(correct me if I am wrong) Win ports are

Look in

Flex source and binaries are certainly available here.


> > - 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.

You probably are looking to map commands to standard code. Its only
then you will be able to add extensions(via new commands) by erading a
file. Something similar to how you load modules into the kernel from
/etc/modules.conf. Maybe you want to desing a basic compiler and let
extensions be handled as modules(similar to Perl ?? I dont know.)

hope this helps.

And if anything wrong, holler and tell me, but dont blame me.


> >
> > 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).

Also, "Compiler Design in C by Allen I Holub" and Parsing by Dick


Post a followup to this message

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