Path: csiph.com!1.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: luser droog Newsgroups: comp.compilers Subject: Re: Wrestling with phase 1 of a C compiler Date: Sun, 11 Sep 2022 20:15:46 -0700 (PDT) Organization: Compilers Central Lines: 39 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-09-003@comp.compilers> References: <22-09-001@comp.compilers> <22-09-002@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="15450"; mail-complaints-to="abuse@iecc.com" Keywords: design Posted-Date: 11 Sep 2022 23:43:37 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <22-09-002@comp.compilers> Xref: csiph.com comp.compilers:3155 On Saturday, September 10, 2022 at 1:36:57 PM UTC-5, luser droog wrote: > On Wednesday, September 7, 2022 at 4:01:04 PM UTC-5, luser droog wrote: > > At my tedious glacial pace, I have rewritten my parser library > > for the umpteen-plus-one'th time only to stall out at an earlier > > step than where I stalled out the last time around. > Sorry for the noise. I'm prematurely optimizing, aren't I? The function > that works just fine and is already reasonably short and readable is > just fine for now. Folding and iotas will probably be a fun idea to try -- > on the next rewrite. On to possibly important problems.... > [It occurred to me that if you want to write in a functional language style, > doing it in C is really painful. -John] That's an accurate assessment. But it's pain I invited upon myself. I'm hoping that a hot fire will forge some strong steel, or that it's worth doing because it is hard. But it all depends upon my ability to emulate or simulate the functional stuff as if it were the C runtime for a Lisp interpreter that happens not to have a read() or eval(), just print() and constructors and functions for the objects. The most recent review post links back to previous reviews all the way back to an "object oriented" implementation. https://codereview.stackexchange.com/questions/277769/commented-parser-combinators-in-lisp-style-c For the present task of pulling the state out of the function, the obvious solution was to rewrite it using pointers and handle the state variables externally, letting the calling function decide where they live. static list position( object item, int *row, int *col ){ if( valid( eq_int( '\n', item ) ) ) return cons( item, cons( Int( ++ *row ), Int( *col = 0 ) ) ); else return cons( item, cons( Int( *row ), Int( ++ *col ) ) ); } For the longer term, I know I want a Monad and maybe Monad Transformers, too. But I don't understand how they're implemented yet. Maybe I can do some kind of monadic comprehension or "do" notation with the C preprocessor....