[MUD-Dev] Storing tokens with flex & bison
Christer Enfors
enfors at swipnet.se
Sat Jan 1 20:58:17 CET 2000
On Sat, 1 Jan 2000, Chris Turner wrote:
> On Fri, 31 Dec 1999, Christer Enfors wrote:
>
> > I'm not sure if this is the proper forum for this kind of question, but I
> > can't find any mailing lists for lex & yacc, and it is a MUD I'm
> > developing...
> >
> > I want to write a MUD server, and for this I want to develop a LPC-like
> > interpreting programming (or call it scripting if you like) language with
> > flex and bison.
> >
> > 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?
> >
> > 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?
>
> To get yylex() to return the tokens from the list, you'd have replace the
> input routine it uses, with one that fakes input based upon the list of
> tokens. This is more hassle than it's worth *8).
>
> The correct/easiest way to do it, is to get bison to call a wrapper function
> that either calls yylex() or pops the next token off the list.
That's what I meant, I guess. I just didn't know you could get bison to
call a different function instead of yylex(). I'll check the man page,
thanks.
> > Or should I simply read the function definition from the file with flex
> > each time I want to execute the function?
>
> Well this would always work with what you have already. It might be a bit
> slower. If you want a real speed increase, you would be better off compiling
> the function into some form of byte-code, which could be run though without
> needing to parse anything.
I thought my supposed stored linked list of tokens was considered
"byte-code", but I guess it's not that simple. Looks like I better hit the
Dragon book some more, I bet this sort of stuff is explained in there
somewhere.
> > 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.
>
> The O'Reilly Lex & Yacc book is well written and contains many tutorials.
Right, but it doesn't have a tutorial that involves storing the source
code in any format for later execution, which is what I'm looking for in
this case.
--
-=-=- 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