Date: Mon, 13 May 1996 08:55:17 +0200 (MET DST) From: "Christoph P. Kukulies" Subject: Re: Bison, Yacc realted question In-reply-to: <4n5dor$d1h@freenet-news.carleton.ca> To: br516 AT FreeNet DOT Carleton DOT CA Cc: djgpp AT delorie DOT com Reply-to: Christoph Kukulies Message-id: <199605130655.IAA25022@gilberto.physik.rwth-aachen.de> MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit > I've been trying to use Bison to create a script language for an RPG. I > downloaded a little something about YACC off the net, it has helped a bit > (I don't remember what the file was called exactly) but I still have a > few questions. > > I want to encorporate subroutines in my language. So, I thought that I might > be able to do that like this: > > subroutine: sub_name '(' arguments ')' '{' expressions '}' > ; > > But I am lost as to how I would define arguments and expressions. For > arguments I need some way of passing muliple arguments, even no arguments, > with ',' characters separating each. Just to give an idea (off memory without a book at hand): arguments: /* empty */ | arguments identifier { ... } | identifier { ... } identifier: IDENTIFIER /* from lex tokenizer */ { install($1); or something } | expression expression: /* look at typical expression parser examples */ and so on. > > Something else that is starting to bother me, would I have to do a sweep > of my entire script looking for subroutines before I could run it? Because > I'ld have to know what subroutines are defined, where they are and the > arguments for each. You can do it in one pass if you leave placeholders for your subroutine calls and fill in the blanks at the end of parsing. You should get familiar with linked lists, hashtables and such. YACC/BISON doesn't relief you from this. It just easifies the parsing process once the syntax is clear and unambiguous. . > > I think this may be a bit tricky for a beginner :) > > << If there is a better newsgroup to take this to, please tell me, I feel > extremely off-topic >> Yeah, you sure are :-) There is a lot of literature on these issues. comp.compilers? > -- > O Nicholas Lynch > -|- br516 AT freenet DOT carleton DOT ca > / \ > --Chris Christoph P. U. Kukulies kuku AT gil DOT physik DOT rwth-aachen DOT de