Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: glen herrmannsfeldt Newsgroups: comp.compilers Subject: Re: specifying semantics, was Formatting of Language LRMs Date: Fri, 4 Jul 2014 06:08:04 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 41 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-07-010@comp.compilers> References: <14-06-010@comp.compilers> <14-06-023@comp.compilers> <14-06-025@comp.compilers> <14-06-027@comp.compilers> <14-06-030@comp.compilers> <14-06-031@comp.compilers> <14-07-003@comp.compilers> <14-07-006@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1404483803 71884 2001:470:1f07:1126:0:676f:7373:6970 (4 Jul 2014 14:23:23 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Fri, 4 Jul 2014 14:23:23 +0000 (UTC) Keywords: syntax, semantics, comment Posted-Date: 04 Jul 2014 10:23:23 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1300 Stefan Monnier wrote: >> What is conventionally called "syntax" is an artifact of the compiler >> technology (or maybe of specification technology, see below): > I disagree here. It is no accident. Doesn't seem to me that it says it is an accident. > Same as the split between > lexical and syntactic analysis, the division between syntax and > (static) semantics is an engineering issue: specifying a language is a > fairly large amount of work, so you want to split it into simpler > parts. And for that reason, both specification and compiler want to divide up the problem. There aren't so many convenient places to divide the work. Also, I have always thought that BNF didn't distinguish lexical and syntactical sides of the problem. When I first learned about BNF, and without any actual compiler books, I started to figure out how a recursive descent algorithm would work, but hadn't thought about a separate lexical analyzer. But I think many languages are designed to separate syntax and semantics, not only to make the description easier, but intentionally to make compilers easier to write. -- glen [The split makes the code easier to write and easier to read. You could since LALR or LL(1) are more powerful than the regex that lex and its ilk use, you could glom everything in the lexer into the BNF of the grammar, but it would be huge and unreadable, since every token definition would be encrusted with all of the optional whitespace and comments that a lexer has already thrown away. In the other direction, you could write many semantic rules in the BNF like what types can combine with what operators, but ugh. In practice, even operator precedence BNF rules are ugly enough that we use hacks in yacc/bison to fake them. -John]