Re: Supporting multiple input syntaxes

"ltc...@gmail.com" <ltcmelo@gmail.com>
Sun, 14 Mar 2021 21:08:33 -0400 (EDT)

          From comp.compilers

Related articles
[10 earlier articles]
Re: Supporting multiple input syntaxes gah4@u.washington.edu (gah4) (2020-08-23)
Re: Supporting multiple input syntaxes mijoryx@yahoo.com.dmarc.email (luser droog) (2020-08-23)
Re: Supporting multiple input syntaxes mijoryx@yahoo.com.dmarc.email (luser droog) (2020-08-23)
Re: Supporting multiple input syntaxes antispam@math.uni.wroc.pl (2021-02-11)
Re: Supporting multiple input syntaxes elronnd@elronnd.net (Elijah Stone) (2021-02-17)
Re: Supporting multiple input syntaxes antispam@math.uni.wroc.pl (2021-02-23)
Re: Supporting multiple input syntaxes ltcmelo@gmail.com (ltc...@gmail.com) (2021-03-14)
Re: Supporting multiple input syntaxes rockbrentwood@gmail.com (Rock Brentwood) (2021-03-14)
| List of all articles for this month |

From: "ltc...@gmail.com" <ltcmelo@gmail.com>
Newsgroups: comp.compilers
Date: Sun, 14 Mar 2021 21:08:33 -0400 (EDT)
Organization: Compilers Central
References: 20-08-002 21-02-004 21-02-005 21-02-008
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
In-Reply-To: 21-02-008

> Elijah Stone <elr...@elronnd.net> 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


Post a followup to this message

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