What is “formal semantics”?

I am reading a very stupid document, and he continues to talk about how Giotto defines "formal semantics."

Giotto has a formal semantics that defines the meaning of mode switches, inter-tag communication and communication with the software environment.

I am on the verge, but I just can’t understand what this means, “formal semantics”.

+6
formal-semantics
source share
4 answers

Formal semantics describes semantics in - well, the formal way - using a notation that uniquely expresses the meaning of things.

This is the opposite of informal semantics, which essentially just describes everything in plain English. It may be easier to read and understand, but it creates the potential for misinterpretation, which can lead to errors because someone did not read the paragraph the way you read it.

A programming language can have both formal and informal semantics - then informal semantics will serve as an “understandable textual” explanation of formal semantics, and formal semantics will be a place to look if you are not sure what an informal explanation really means.

+9
source share

To talk a little about Michael Madsen, an example is the behavior of the ++ operator. Informally, we describe a statement using plain English. For example:

If x is an int variable, ++x causes x to increment by one.

(I do not accept any integer overflows and ++x returns nothing)

In formal semantics (and I will use operational semantics), we would work a little. First, we need to define the concept of types. In this case, I will assume that all variables are of type int . In this simple language, the current state of a program can be described by a repository, which is a mapping of variables into values. For example, at some point in the program, x might be 42, and y be -5351. The storage can be used as a function - for example, if the storage s has a variable x with a value of 42, then s(x) = 42 .

Also, the current state of the program includes the rest of the program instructions that we must execute. We can relate this as <C, s> , where C is the remaining program and s is the repository.

So, if we have the state <++x, {x -> 42, y -> -5351}> , this is unofficially the state where the only remaining command to execute is ++x , the variable x has the value 42, and the variable y has a value of -5351 .

Then we can determine the transitions from one state of the program to another - we describe what happens when we take the next step in the program. So, for ++ we could define the following semantics:

 <++x, s> --> <skip, s{x -> (s(x) + 1)> 

To some extent, unofficially, by running ++x , the next skip command, which has no effect, and the variables in the store remain unchanged, except for x , which now has a value that originally had a value plus one. Some work remains to be done, for example, to determine the notation that I used to update the repository (which I did not do so that this answer does not increase!). Thus, a specific instance of a general rule can be:

 <++x, {x -> 42, y -> -5351}> --> <skip, {x -> 43, y -> -5351}> 

Hope this gives you this idea. Note that this is just one example of formal semantics — along with operational semantics — axiomatic semantics (which often uses Hoar’s logic) and denotational semantics, and probably a lot more than I am not familiar with.

As I mentioned in a comment on another answer, the advantage of formal semantics is that you can use them to prove certain properties of your program, for example, that it ends. Besides the fact that your program does not exhibit bad behavior (for example, without interruption), you can also prove that your program behaves as needed, proving that your program meets the specified specification. Having said that, I never thought about pointing and checking the program for anything that is convincing, since I found a specification, usually just rewritten in logic by the program, so the specification is also wrong.

+11
source share

Just as the syntax of a language can be described by formal grammar (e.g., BNF ), various formalisms can be used to map this syntax to mathematical objects (i.e. the meaning of the syntax).

This page from a Practical Introduction to Denotational Semantics is a good introduction to how denotational semantics are related to syntax. The book’s beginning also gives a brief history of other, non-provocative approaches to formal semantics (although Michael’s wikipedia link is given in more detail, and probably more relevant).

From the author of the site :

Semantics models do not have at the same time that BNF and its descendants have syntax. This may be due to the fact that the semantics seem simply more difficult than the syntax. The most successful system is denotational semantics, which describes all the functions found in imperative programming languages ​​and sound mathematical basis. (Still active research in type systems and parallel programming.) Many denotational definitions can be made as translators or translated into “compilers”, but this has not yet led to the creation of efficient compilers, which may be another reason that denotational semantics are less popular than BNF.

+2
source share

In the context of a programming language such as Giotto, it is understood that a language with formal semantics has a mathematically rigorous interpretation of its individual language constructs.

Most programming languages ​​today are not strictly defined. They can stick to standard documents, which are detailed enough, but ultimately the compiler’s responsibility is to emit code that somehow adheres to these standard documents.

Formally, the specified language, on the other hand, is usually used when it is necessary to make discussions about the program code, using, for example, model verification or the proof of a theorem. Languages ​​that lend themselves to these methods are typically functional, such as ML or Haskell, because they are defined using mathematical functions and the transformations between them; those. fundamentals of mathematics.

C or C ++, on the other hand, is informally defined by technical descriptions, although there are academic documents that formalize aspects of these languages ​​(e.g. Michael Norrish: formal semantics for C ++, https://publications.csiro.au/rpr/ pub? pid = nicta: 1203 ), but often do not fit into official standards (possibly due to a lack of practicality, especially for maintenance).

0
source share

All Articles