Path: csiph.com!1.us.feeder.erje.net!feeder.erje.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Christopher F Clark Newsgroups: comp.compilers Subject: Wrestling with phase 1 of a C compiler Date: Mon, 12 Sep 2022 21:45:54 +0300 Organization: Compilers Central Lines: 46 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-09-004@comp.compilers> References: <22-09-001@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="99560"; mail-complaints-to="abuse@iecc.com" Keywords: design Posted-Date: 12 Sep 2022 15:46:44 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3156 While I hate being extremely pessimistic, you are going in absolutely the wrong direction. If you want a functional language, use one. Don't try to turn C into a functional language. Even if you succeed, you will have made a mess that no one (probably not even you) will actually understand. I say that from experience. Early on in writing Yacc++, we did macros that allowed us to write object-oriented C, which had C++-like semantics (ala 1986, pre-templates, pre STL, etc.) with nice ABC (abstract base classes, plus some inheritance and polymorphism). It worked. However, it was a challenge to understand. Our wisest move was at 2.0 rewriting everything in C++ and not trying to have a "C" layer with similar functionality. The code was an order-of-magnitude simpler and even making a translation that did C# was relatively trivial from that code. C is a nice small imperative language. It's fine for expressing those kinds of semantics. The C preprocessor is both simple and powerful, but it doesn't change the nature of C. You cannot really do "compilation" in the C preprocessor. And, if you really want a parser combinator library, you want it to do some compilation. Otherwise, you have just masked the fact that you are doing hand-written recursive descent. And, if you want to do hand-written recursive descent, do it. Don't put lipstick on a pig and take it to the opera. There is a reason your attempts are failing. You don't have good closures or co-routines in C. You cannot get them easily. You cannot really interact well with the function stack in C. And, your efforts to put the state behind pointers, while necessary only get you part of the way there. So, if you are lucky, you will have something that looks like a parser combinator language, but which actually has either - broken semantics (i.e. cases that don't work properly and don't warn you that they don't) or - is very complicated. -- ****************************************************************************** Chris Clark email: christopher.f.clark@compiler-resources.com Compiler Resources, Inc. Web Site: http://world.std.com/~compres 23 Bailey Rd voice: (508) 435-5016 Berlin, MA 01503 USA twitter: @intel_chris