C semantic specification

Wikipidea says Perl has a dominant implementation, which is used as a reference for its specification, and C is the standard ANSI ISO.

I learned the C language without reading a single line of the standard, is that normal ...?

I would like to know how a standard (i.e. a natural language document) is able to describe a programming language without reference to any dominant implementation.

+4
source share
4 answers

It is very rare to find people who learn the programming language from the specification. The specification is mainly aimed at the compiler authors (who must adhere to this literal word to guarantee correctness) and as the final arbiter of what is legal in the language. Most language specifications are extremely tight and technical, and this will not be a good way to learn how to program in a language. Often only very advanced language users really read the specification.

In addition, very few languages ​​are defined using a reference implementation. Most languages ​​are defined relative to some abstract runtime. For example, the C ++ specification says that

The semantic descriptions in this International Standard define a parameterized non-deterministic abstract machine. There are no requirements for the structure of the corresponding implementations in this International Standard. In particular, they do not need to copy or emulate the structure of an abstract machine. Rather, appropriate implementations are needed to emulate (only) the observed behavior of an abstract machine, as described below.

In other words, the C ++ specification describes how C ++ programs should behave in a purely theoretical sense. This gives the play's authors greater freedom in how they define the language. For example, they can talk about “objects” and “pointers”, not to mention how they should be implemented. They don’t even need to tell how the physical machine that C ++ works on, as they can simply determine that the machine will behave no matter how they want, and then leave it to the real authors of the compiler to translate this abstract machine into physical machine.

Some languages ​​are defined relative to a virtual machine (Java is an example of this). They can talk about the behavior of Java programs in relation to this virtual machine, saying how Java programs interact with the virtual machine and then leave the details of the virtual machine implementation to the VM implementers.

Some other languages, such as ML, have purely mathematical definitions. The semantics of the language are described as abstract mathematical transformations between states, which means that one can prove the properties of ML, which are not easy to show if the language was defined with respect to the reference compiler.

To summarize - language specifications are complex documents that programmers actually read little. They are mainly intended for authors of compilers and usually define a program in some abstract expression that does not take into account the machine. Thus, the language can be defined in a portable way, since you can perform a consistent implementation on any computer by simply translating the formal description into machine operations.

Hope this helps!

+7
source

Most programming languages ​​are learned without reading a standard or language reference / project document (if one exists).

The standard can be specified formally - in a very strict way, which can be mathematically proven Turing completed .

+5
source

Learning C (and similarly defined languages ​​such as C ++) without reading the standard is completely normal.

The standard document language is often described as intentionally pedantic, oriented more toward compilers than programmers, and is intended to be more authoritative than accessible.

It is much easier to learn a language from a one-step source, such as a book intended for programmers. The author had to verify that what he describes was correctly in line with the standard, of course.

Some argue that it is useful to have a standard to address certain issues. I have not tried this, except for some freely available "language report" documents, which were usually not through the official standardization system (and probably a little more accessible and a little less pedantic).

In most cases, if you have a question related to standards, it is probably best to look for an answer (and if that fails, ask) here.

+3
source

I would like to know how a standard (i.e. a natural language document) is able to describe a programming language without reference to any dominant implementation.

This is how I learned SQL. I learned the standard. The bad side is that whenever I use another DBMS, I have to study the differences in its SQL taste. Fortunately, the most common part of SQL seems to be the same everywhere.

I would like to know how a standard (i.e. a natural language document) is able to describe a programming language without reference to any dominant implementation.

A good standard is not a completely different natural language document - it is a fairly formal document. Don't you think the law is just a natural language document?

I learned the C language without reading a single line of the standard, is that normal ...?

Yes. Well ... yes, if you really want to encode something.

+1
source

Source: https://habr.com/ru/post/1342407/


All Articles