[转载] 语法和语义

本文转自steve的博客,探讨图形语言的语义与语法。图形语言有具体语法、抽象语法和语义三个主要方面。具体语法定义外观,抽象语法定义概念及有效性,语义则定义有效表达式的含义。还介绍了赋予语义的映射方式,如映射到编程语言、逻辑形式等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自steve的blog

其实说得也很简单,转载以备忘。
更详细的可以去看Keith Short的这本书:Adapted from Models, Frameworks and Tools,网上有下载。

Graphical languages – semantics vs syntax

Recent postings have talked about “semantics” of graphical languages. When I was involved in UML development this word caused a lot of argument and confusion. In my view, it goes like this.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

A graphical language has three primary aspects: concrete syntax, abstract syntax, and semantics. Concrete syntax (notation) defines what the language actually looks like on the screen or the paper: the shapes, connections, adornments and textual annotations that the user sees and manipulates, and the gestures used to manipulate them. Abstract syntax (grammar) gives names to the concepts that the notation depicts, and defines which configurations of these are valid. Often, the abstract syntax for a graphical language is defined using a model, itself expressed using a graphical language. Some people call this a “metamodel”; my colleagues and I usually call it a domain model. Usually such a model is insufficient on its own, and must be supplemented by an additional set of constraints, sometimes called “well-formedness rules”. A typical such rule would be the constraint that an inheritance graph must not form cycles.

Semantics is none of the above, although terms such as “static semantics” or “short-range semantics” have been used to refer to what I called abstract syntax. Semantics define what valid expressions in the language mean. (Aside: saying “expressions in the language” is very easy when talking about textual languages, whereas thinking of a diagram as an expression may feel a little uncomfortable. You have to get used to it.) The way to give meaning to an expression is to map it to one or more other interesting structures whose meaning is known. To define semantics objectively, the mapping and the meaning of the result must both be precisely defined.

A mapping of the graphical language to statements in a natural language does not give objective semantics, although it may be useful. A precise mapping of the graphical language to a programming language gives objective semantics to the extent that the programming language does: which is high, in the case of popular standardized languages. If such a mapping exists it probably means that the diagram is a visualization of some aspect of the structure of the program. Another useful target for semantic mappings is expressions in some logical formalism, such as set theory, predicate logic or abstract algebra. Examples of diagrams with this kind of semantics are Venn diagrams and Petri nets. A final useful target for semantic mappings is another graphical language, which itself has well-defined semantics.

You might observe that abstract syntax involves a mapping from expressions in the language to the structure {valid, invalid}, and therefore is a kind of degenerate semantics. I prefer to distinguish validity from meaning. You might also observe that it might be desirable to give some kind of meaning to invalid expressions. To do that, you’d have to introduce different kinds of validity.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值