Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Lexical Elements Date: Thu, 28 Sep 2017 18:39:59 -0700 Organization: None to speak of Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="61a8d29e3e3ce5c1ce3f75578cd619a7"; logging-data="8613"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PVk07hVOjffZq10CokI3W" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:7+TTb+hND57+S5uTDsNP+TwERdo= sha1:Sij9u/MwUEHB4xCS+grhSeqSDhI= Xref: csiph.com comp.lang.c:120515 David Kleinecke writes: > On Thursday, September 28, 2017 at 12:38:02 PM UTC-7, Keith Thompson wrote: >> >> A compiler typically treats syntax and semantics separately. Syntactic >> analysis, or parsing, is often semi-automated, with the parser generated >> programatically from a forma grammar -- or it might be written manually. >> If parsing fails, that's a syntax error. Other errors, like trying to >> apply a shift operator to a pointer value, have to be detected during >> semantic analysis. As far as typical compiler internals are concerned, >> they're fundamentally different kinds of errors. Tweaking the grammar >> to treat some syntax errors as semantic errors can enable better >> diagnostics in some csaes. > > My compilers also treat syntax and semantics separately. The > question is whether the constraints are part of syntax or part > of semantics. Semantics, I'd say. > You imply that some are and some aren't. Did I? > Quite possible > although I have no examples. I have concluded that what > I called the spirit of C expects them with the syntax but > I had them coded with the semantics. I have only begun > moving the constraints and haven't yet found any that > don't fit rather easily into the syntax. I suspect I really don't undrestand what you're saying. Here's an example. C11 6.8.4.2p1 specifies the following constraint: The controlling expression of a switch statement shall have integer type. Unless you extend the meaning of "syntax" beyond (my) recognition, you won't be able to enforce that constraint using only syntax information. Roughly, a syntax error is a failure to parse the source code in accordance with a grammar that can be defined, for example, in BNF (Backus-Naur Form). (C's treatment of typedefs punches a small hole in this model.) Any errors that are not syntax errors are what I think of as semantic errors. In C, this is more or less expressed as syntax rules vs. constraints. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"