Path: csiph.com!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Rock Brentwood Newsgroups: comp.compilers Subject: Re: Supporting multiple input syntaxes Date: Sun, 14 Mar 2021 17:36:01 -0700 (PDT) Organization: Compilers Central Lines: 31 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <21-03-003@comp.compilers> References: <20-08-002@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="45952"; mail-complaints-to="abuse@iecc.com" Keywords: parse, syntax, C Posted-Date: 14 Mar 2021 21:09:45 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: <20-08-002@comp.compilers> Xref: csiph.com comp.compilers:2636 On Wednesday, August 12, 2020 at 5:32:56 PM UTC-5, luser droog wrote: > I've got my project successfully parsing the circa-1975 C syntax > from that old manual. I'd like to add parsers for K&R1 and c90 > syntaxes. > > How separate should these be? Should they be complete > separate grammars, or more piecewise selection? I'm in a similar situation with a utility that I want to grandfather in the old syntax for, but write with a new and better syntax. My recommendation is this: stick to C99, since that's already in POSIX. Write a separate utility to convert legacy syntax to C99 (and to call out any irregularities/inconsistencies in the program being converted). That's, like, "lint" on steroids. The other syntaxes would be used in the other utilities, only - one per utility. It can also be hybridized with "indent" and a driver routine can control the conversion, so that all the conversion utilities can be combined to one. So, on input, the source syntax is selected, and on output the format is driven in much the same way that it is with indent. It's an excellent exercise in Text-To-AST-To-Text programming. Each program, upon upward conversion to C99, would replace the original, once it passes the consistency checks provided by the utility; so there isn't a question of cueing error messages to the format of the older program, because the older program would be replaced. Doing all of this is an example of "refactoring" used to pay off "code debt". And there's a lot of code debt out there that needs to be paid up. Technical Debt (Wikipedia): https://en.wikipedia.org/wiki/Technical_debt Code Refactoring (Wikipedia): https://en.wikipedia.org/wiki/Code_refactoring