Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!SUN.COM!wmb From: wmb@SUN.COM (Mitch Bradley) Newsgroups: comp.lang.forth Subject: Re: writing a C interpreter in Forth? Message-ID: <9001070938.AA07304@jade.berkeley.edu> Date: 7 Jan 90 06:30:25 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Forth Interest Group International List Organization: The Internet Lines: 20 I wrote a C lexical scanner in Forth. It was fairly easy and quite small. Scanning is easy; parsing is a bit harder. Probably the easiest way to do a C parser in Forth would be to take a yacc grammar of C and run it through yacc to get the state tables. Then duplicate the effect of the (quite small) yacc table walking machine in Forth. Then you have to decide what to do for code generation. That's where the real engineering skill comes into play. You have to worry about how to implement things like type promotion and storage allocation and switch statements (decent C compilers automatically generate jump tables if the cases are densely packed and if else if else ... chains if the cases are sparse). Doing a complete job will take a lot of work, so be prepared for it. By the way, Tayfun Kocaoglu, who works with me at Sun, did a subset C compiler in Forth for his master's thesis at University of Florida. Tayfun wrote a scanner and a code generator, and he used yacc for the parser. Mitch