help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loops using flex/bison..


From: Matthew Tedder
Subject: Re: Loops using flex/bison..
Date: Tue, 5 Feb 2002 22:55:13 +0100

On Tuesday 05 February 2002 09:24 am, you wrote:

> The Bison generated parser does not back-track (ever), and in addition may
> apply reductions before an error is detected, so if your idea is to step
> through the text one token at a time and interpret it as you go along,
> Bison is not at all suitable for that approach. -- But this is not a very
> efficient approach:

But flex/bison must have some idealized way of doing this.  If an
intermediate code was invisioned, why did they design lex and yacc to tie
directly together?  There must be some intended manner of implementing loops
and labels..

> >  It's a little BASIC interpreter.
>
> A more efficient approach for Basic is to scan through the whole code, and
> translate it into some intermediate binary representation that can be
> interpreted.

You might be intirely right, since it's not intended to be a compiler.  The
idea of making this an interpreter was to enable certain things a compiler
cannot do--such as executing code assembled at run-time in a string variable.
 This has applications where users need to assemble data processing logic,
such as for contract management and other uses..  This is a critical
capability of the Mumps language using in medical facilities.  Unfortunately,
Mumps is not very lay-person friendly.

For my purposes, the main benefit of BASIC is in making it very easy to code
in for professionals in other fields, not programmers.  Context independent
languages make for much tighter code, but that kind of logic is difficult for
such people to grasp or read.  BASIC is more of a kindergarden approach for
them--even though not as efficient.  My point is in using this language to
bring such rapidly learned and RAD capabilities to a much broader scope of
professionals so they can implement ideas relevent to their professions they
programmers would most likely not have any understanding of.

>
> Then you might keep track of the lines changed, and only re-compile those.
> I recall a HP compiler that worked like this. -- But computers are so fast
> nowadays, it may not be worth it.

Hmmm... I'm thinking..

>
> >  I have some great ideas for enhancing it.
> > I also thought about using flex to translate BASIC to C.
>
> But this seems like a simple approach if you want to produce efficient
> output code.

Yeah... I might want to do this as a second project..  The interpreter has
different benefits.  I think translation to C++ might be good for RAD game
making...  I could make BASIC commands for QT's qcanvas class and other
related goodies..  At the very least, it could make great skeleton code.

>
> >  Would it be
> >possible to turn such a thing easily into a gcc front-end?
>
> I am not sure what you mean by "gcc front-end" here: Note however, that the
> Haskell compiler GHC <http://haskell.org/> produces C as output. I write on
> a compiler of my own OOPL that produces C++ as output.
>
> The GHC compiler is tied to GCC only because it uses special GCC compiler
> features. If you produce standard C/C++ as output, which I figure would be
> possible with Basic, then that would not be needed.

Maybe I was thinking of something very similar then.  I hear GNU's C++ was
originally just a tool that converted C++ code to C code.  It was then
accepted into the gcc family, I believe.  Therefore, would such as approach
be viable to adopting BASIC into the gcc family.

>
> I am not sure why you are doing this: Do you want to learn writing it, or
> do want to have a Basic compiler? -- For the latter, I think it might be
> already available.

Both... I am learning and having a lot of fun at it..  But I think its the
vision and possibilities that make it fun..  It's realizing that maybe I
could do this or that great thing that keeps inspiring me..  That is, the
idea that it could be meaningful, not just educational.

>
> You could post to the Usenet newsgroup comp.compilers, or check its FAQ (in
> its monthly message). It says about Basic:
>
>   * Where can I get a Basic grammar in yacc?

I will check all of these out.  The Chipmunk Basic homepage lists a large set
of links to various BASIC intepreters/compilers, and I have reviewed the
source code to each and every single one of them.  Most use very limited
approaches (even non-recursive) to expression evaluation and have very
nonstandard syntax trees..  YaBasic uses flex/bison, but is too much of a
deviation from a BASIC programmer's idea of what BASIC is.

Also, I thought that perhaps once a get an extensible BASIC done, I could
offer regex-based preprocessing capabilities to enable the inclusion of
syntax compatibility modules.  This could enable one version of BASIC to
interpret a broad variety of other versions or even perhaps other context
dependent languages.

>
>   Take a look at ftp://ftp.uu.net:/usenet/comp.sources.unix/volume2/basic/
>   which contains a Basic interpreter with yacc parser.
>
>   * Where can I get a QBasic compiler?
>
>   Probably nowhere.  The "official" QBasic compilers were QuickBasic 4.5
>   and the Microsoft Professional Development System, sometims called "QBX".
>   You might still find copies at the big mail-order houses, but Microsoft
>   has discontinued them.
>
>   A shareware compiler ASIC is available from simtel mirrors such as
>   ftp://ftp.simtel.net/pub/simtelnet/msdos/basic/asic500.zip, which
>   handles a large subset of Qbasic.  Also see
>   http://www.users.uswest.net/~sdiggins/basm.html for another freeware
>   Basic compiler.
>
>   PowerBasic and FirstBasic, commercial and shareware, respectively, from
>   http://www.powerbasic.com resembles an extended QBasic.
>
>   There's a Qbasic mailing list; send "info qbasic" to
>   address@hidden for details.
>
>   Hans Aberg


Thanks for the post.

--Matthew





reply via email to

[Prev in Thread] Current Thread [Next in Thread]