[MUD-Dev] Storing tokens with flex & bison
Christer Enfors
enfors at swipnet.se
Sat Jan 1 20:52:39 CET 2000
On Sat, 1 Jan 2000, Per Vognsen wrote:
> Christer Enfors spake thusly:
> > When flex reads a file, would it be a good idea to store the tokens
> > returned from yylex() in a list? I was thinking one list for each function
> > definition, and then having bison read from that list when executing that
> > function, instead of reading directly from the file using flex?
>
> What I think you'd rather want to do here is to use some intermediate
> form for storage - it would be completely irrational to scan, parse and
> interpret the code each time you want to execute it. For this task you
> can use an AST (abtract syntax syntax), byte-code (usually generated
> from some other form, like ASTs), or other even more exotic options.
Oh. I was under the impression that my stored linked list of tokes was
enough to be considered an "intermediate format", and that simply
interpreting that list at runtime was ok?
> > If so, how would I get yylex() to return tokens from my list instead of
> > tokens from the file? Or would that be going about it the wrong way?
>
> You could do it by writing your own yylex() function which in turn
> interfaced to the 'real' lexer function generated by lex (you can
> specify and alternate name for the generated yylex() - see the man
> files).
You can specify an alternate name? Yes, that should work, thanks.
> > Maybe someone could point me to a lex & yacc tutorial that includes
> > writing an interpreted language that allowes user defined functions
> > written in that language, since that is basically what I'm trying to do
> > myself.
>
> If you're interested in writing languages in general, I think the Dragon
> book is still the classic (although a bit dated in some areas).
> "Compilers: Principles, Techniques, and Tools" by Aho, Sethi, and Ullman
> from Addison-Wesley.
Got it within arm's reach on my desk at all times. I'm about one third on
my way through it (skipping the low level stuff, like how to implement
what lex implements for me).
> If you want to learn more about lex and yacc (flex
> and bison are the GNU versions) try checking out "lex & yacc" by Levine,
> Mason, and Brown from O'Reilly
Read it. It's right here next to the Dragon book. The problem with that
book IMHO is that it doesn't show how to do what I want to do - a language
that supports user defined functions.
--
-=-=- Christer Enfors -=-=-
"I do my music in pure machine code using an assembler."
- Rob Hubbard
_______________________________________________
MUD-Dev maillist - MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev
More information about the mud-dev-archive
mailing list