简体   繁体   中英

C language semantic specification

Wikipidea says that Perl has a dominant implementation that is used as a reference for its specification ,while C language is specified by the standard ANSI ISO.

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

I would like to know how the standard (ie a natural language document) is capable of describing a programming language without referring to any dominant implementation.

It's extremely rare to find people who learn a programming language from the specification. The spec is mostly targeted at compiler authors (who need to adhere to it word-for-word to guarantee correctness) and as a final arbiter of what's legal in the language. Most language specs are extremely dense and technical, and would not be a good way to learn to program in a language. Often, only very advanced users of a language actually read the spec.

Also, very few languages are defined in terms of a reference implementation. Most languages are defined relative to some abstract execution environment. For example, the C++ specification says that

The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine. This International Standard places no requirement on the structure of conforming implementations. In particular, they need not copy or emulate the structure of the abstract machine. Rather, conforming implementations are required to emulate (only) the observable behavior of the abstract machine as explained below.

In other words, the C++ specification describes how C++ programs need to behave in a purely theoretical sense. This gives the spec authors great leeway with how they define the language. They can talk about "objects" and "pointers", for example, without saying how they actually have to be implemented. They don't even need to say how the physical machine on which C++ works, since they can just define the machine to behave however they want and then leave it up to actual compiler writers to translate that abstract machine onto the physical machine.

Some languages are defined with respect to a virtual machine (a great example of this is Java). They can talk about the behavior of Java programs with respect to that virtual machine by saying how Java programs interact with the virtual machine, and then leave the details of the VM implementation up to the VM implementers.

Some other languages, such as ML, have definitions that are purely mathematical. The semantics of the language are described as abstract mathematical transformations between states, meaning that it's possible to prove properties of ML that couldn't easily be shown if the language were defined relative to a reference compiler.

To summarize - language specifications are complex documents that few programmers actually go about reading. They're mostly for compiler authors and define the program usually in some abstract term that doesn't take the machine into account. That way, the language can be defined in a portable way, since you can make a conformant implementation on any machine by just translating the formal description into machine operations.

Hope this helps!

Most programming languages are learnt without reading the standard or language reference/design document (if one exists).

A standard can be specified formally - in a very strict manner that can be mathematically proven to be Turing complete .

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

The language of standards documents is often described as intentionally pedantic, aimed at compiler writers rather than programmers, and designed to be authoritative rather than accessible.

It's far easier to learn the language from a one-step-removed source, such as a book aimed at programmers. The author should have checked that what he is describing is correct according to the standard, of course.

Some claim that it's useful to have the standard available to resolve some questions. I've not tried it, beyond some of the freely available "language report" documents that usually haven't been through a formal standardization system (and so are probably a bit more accessible and a bit less pedantic).

Most of the time, if you have a standards-related question, it's probably better to search for an answer (and if that fails, ask) here.

I would like to know how the standard (ie a natural language document) is capable of describing a programming language without referring to any dominant implementation.

This is how I learned SQL. I learned the standard one. The bad side of it is that whenever I use a different DBMS I have to learn the differences of its SQL flavor. Luckily, the most common part of SQL seems to be the same everywhere.

I would like to know how the standard (ie a natural language document) is capable of describing a programming language without referring to any dominant implementation.

A good standard is not really a just another natural language document - it's quite a formal document. Would you consider a law just a natural language document?

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

Yes. Well... yes, if you actually want to code anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM