Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #3156
| From | Christopher F Clark <christopher.f.clark@compiler-resources.com> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Wrestling with phase 1 of a C compiler |
| Date | 2022-09-12 21:45 +0300 |
| Organization | Compilers Central |
| Message-ID | <22-09-004@comp.compilers> (permalink) |
| References | <22-09-001@comp.compilers> |
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
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
Wrestling with phase 1 of a C compiler luser droog <luser.droog@gmail.com> - 2022-09-07 09:47 -0700
Re: Wrestling with phase 1 of a C compiler luser droog <luser.droog@gmail.com> - 2022-09-09 20:47 -0700
Re: Wrestling with phase 1 of a C compiler luser droog <luser.droog@gmail.com> - 2022-09-11 20:15 -0700
Wrestling with phase 1 of a C compiler Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-09-12 21:45 +0300
Re: Wrestling with phase 1 of a C compiler gah4 <gah4@u.washington.edu> - 2022-09-12 13:01 -0700
Re: Wrestling with phase 1 of a C compiler Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-09-13 14:55 +0300
Re: Wrestling with phase 1 of a C compiler gah4 <gah4@u.washington.edu> - 2022-09-14 15:40 -0700
Re: source languages, was Wrestling with phase 1 of a C compiler George Neuner <gneuner2@comcast.net> - 2022-09-14 16:03 -0400
Re: Wrestling with phase 1 of a C compiler luser droog <luser.droog@gmail.com> - 2022-09-14 14:31 -0700
Re: Wrestling with phase 1 of a C compiler luser droog <luser.droog@gmail.com> - 2022-09-15 20:11 -0700
csiph-web