Re: specifying semantics, was Formatting of Language LRMs

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Fri, 4 Jul 2014 06:08:04 +0000 (UTC)

          From comp.compilers

Related articles
[9 earlier articles]
Re: specifying semantics, was Formatting of Language LRMs ivan@ootbcomp.com (Ivan Godard) (2014-06-29)
Re: specifying semantics, was Formatting of Language LRMs genew@telus.net (Gene Wirchenko) (2014-06-30)
Re: specifying semantics, was Formatting of Language LRMs ivan@ootbcomp.com (Ivan Godard) (2014-06-30)
Re: specifying semantics, was Formatting of Language LRMs anton@mips.complang.tuwien.ac.at (2014-07-02)
Re: specifying semantics, was Formatting of Language LRMs monnier@iro.umontreal.ca (Stefan Monnier) (2014-07-03)
Re: specifying semantics, was Formatting of Language LRMs genew@telus.net (Gene Wirchenko) (2014-07-03)
Re: specifying semantics, was Formatting of Language LRMs gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-07-04)
Re: specifying semantics, was Formatting of Language LRMs DrDiettrich1@aol.com (Hans-Peter Diettrich) (2014-07-04)
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Fri, 4 Jul 2014 06:08:04 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 14-06-010 14-06-023 14-06-025 14-06-027 14-06-030 14-06-031 14-07-003 14-07-006
Keywords: syntax, semantics, comment
Posted-Date: 04 Jul 2014 10:23:23 EDT

Stefan Monnier <monnier@iro.umontreal.ca> 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]


Post a followup to this message

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