Path: csiph.com!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: "ltc...@gmail.com" Newsgroups: comp.compilers Subject: Re: Supporting multiple input syntaxes Date: Sun, 14 Mar 2021 21:08:33 -0400 (EDT) Organization: Compilers Central Lines: 32 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <21-03-001@comp.compilers> References: <20-08-002@comp.compilers> <21-02-004@comp.compilers> <21-02-005@comp.compilers> <21-02-008@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="45283"; mail-complaints-to="abuse@iecc.com" Keywords: parse Posted-Date: 14 Mar 2021 21:08:33 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: <21-02-008@comp.compilers> Xref: csiph.com comp.compilers:2634 > Elijah Stone wrote: > I did a C parser, it was not hard at all. I in C (like in standard > Pascal) there are conflicts, but that conflicts can be resolved > easily using semantic info. Alternativly, for C one can use 2 > token lookahead. I'm not sure whether I captured the full context of your statement, but, if I did, I don't think it's 100% correct: - In regards to lookahead of 2: This isn't enough to disambiguate, e.g., between a cast-expression in 6.5.4, `( type-name ) cast-expression`, and a compound literal in 6.5.2, `( type-name ) { initializer-list }`. - In regards to using semantic info: Yes, with semantic info you can disambiguate things like `x * y;`, so I'd say that, from a pragmatic/practical standpoint, this affirmation is right. However, from a more theoretical perspective, a parser (thinking of it a program that "simply" validates a sentence based on a grammar), isn't expected — arguably — to rely on anything else other than syntax. Whether or not the theoretical aspect of it is relevant, depends on the application of the parser, I guess. For instance, for the implementation of static analysis tool, not depending, as much as possible, on semantic information to guide parsing is an advantage. This is a table (only for expressions) that I recently put up when rewriting the C parser of my project: https://docs.google.com/spreadsheets/d/1oGjtFaqLzSoBEp2aGNgHrbEHxSi4Ijv57mXMP ymZEcQ/edit?usp=sharing -- Leandro T. C. Melo