Re: Wrestling with phase 1 of a C compiler

luser droog <luser.droog@gmail.com>
Sun, 11 Sep 2022 20:15:46 -0700 (PDT)

          From comp.compilers

Related articles
Wrestling with phase 1 of a C compiler luser.droog@gmail.com (luser droog) (2022-09-07)
Re: Wrestling with phase 1 of a C compiler luser.droog@gmail.com (luser droog) (2022-09-09)
Re: Wrestling with phase 1 of a C compiler luser.droog@gmail.com (luser droog) (2022-09-11)
Wrestling with phase 1 of a C compiler christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-09-12)
Re: Wrestling with phase 1 of a C compiler gah4@u.washington.edu (gah4) (2022-09-12)
Re: Wrestling with phase 1 of a C compiler christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-09-13)
Re: Wrestling with phase 1 of a C compiler luser.droog@gmail.com (luser droog) (2022-09-14)
Re: Wrestling with phase 1 of a C compiler gah4@u.washington.edu (gah4) (2022-09-14)
Re: Wrestling with phase 1 of a C compiler luser.droog@gmail.com (luser droog) (2022-09-15)
| List of all articles for this month |
From: luser droog <luser.droog@gmail.com>
Newsgroups: comp.compilers
Date: Sun, 11 Sep 2022 20:15:46 -0700 (PDT)
Organization: Compilers Central
References: 22-09-001 22-09-002
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
In-Reply-To: 22-09-002

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....


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.