Simple definition of “semantics” as it is commonly used in relation to programming languages/APIs?

前端 未结 3 396
轻奢々
轻奢々 2021-02-04 14:18

It occurred to me today that although I\'ve adopted and don\'t infrequently use the term \"semantics\" when referring to language elements and naming conventions, I don\'t have

3条回答
  •  一生所求
    2021-02-04 14:44

    It's the meaning of the language elements in terms of what they formally mean in terms of computation (usually, and this is the operational semantics). This means that it expresses what a term of your language effectively does assuming an underlying kind of model that depends on which semantic we are talking about.

    As you can see from wikipedia page you mainly have 3 kinds of semantics:

    • operational semantics express the meaning of the language by specifying how an abstract virtual machine behaves whenever it executes a term. (eg: +: pops two elements from the stack and push the sum. This is NOT formal and it is NOT how you should really consider it, it's just to give you an idea). This is the most used one to describe semantics of "normal" programming languages. For example for Java you could have, for every possible term, a sequence of JVM instruction meant to be executed to model that term. Probably when you asked for the meaning of semantics this is the one you were looking for.
    • denotational semantics is a different approach: you give for every term of the language a meaning that is represented by a mathematical function. So for previous example you would have a function f associated with + that contains what is the semantic (effective meaning) of the term
    • axiomatic semantics is a way to annotate the terms of your language expressing how they alter the validity of some logical formulas you want to verify over your program. You should consider reading this just because the inference rules and axioms used are similar in how you develop this kind of semantics but it's explained in a practical way

    From this decription you understand that a semantic is something well defined inside a context, and you need a specified context otherwise you couldn't give you language a formal definition of what its terms do..

提交回复
热议问题