The syntax and semantics of programming language

Source: Internet
Author: User

The syntax and semantics of the programming language are excerpted from the formal Syntax and semantics of programming Languages by Kenneth Slonneger/barry L. Kurtz
Liu Jianwenlio (Http://blog.csdn.net/keminlau) Chapter 1SPECIFYING SYNTAX

Language provides a means of communication by sound and written symbols. Human beings learn language as a consequence of their life experiences, but in linguistics-the science of languages-the fo RMS and meanings of languages is subjected to a more rigorous examination. This science can also is applied to the subject of this text, programming languages. In contrast to the natural languages, with which we communicate our thoughts and feelings, programming languages can be VI Ewed as artificial languages defined by men and women initially for the purpose of communicating with computers but, as IM portantly, for communicating algorithms among people.

Languages provide channels for communication in the form of sound and text symbols. Human beings generally acquire language through the experience of life, but in linguistics as a science, the form and meaning of language must be strictly studied (rigorous examination). The same scientific treatment is, of course, applied to the subject of the book, the programming language. Unlike natural language, which is used to communicate ideas and feelings, a programming language can be seen as an artificial language, initially defined for human-computer communication, but more important now is to communicate program algorithms between programmers.

Many of the methods and much of the terminology of linguistics apply to programming languages. For example, language definitions consist of three:

Many methods and terms of linguistics are applied to programming languages. For example, three parts of a language definition:

1. Syntax refers to the ways symbols is combined to create well-formed sentences (or programs) in the language. Syntax defines the formal relations between the constituents element of a language, thereby providing a structural description O f the various expressions that make up legal strings in the language. Syntax deals solely with the form and structure of symbols in a language without any consideration given to their meaning.

Grammar refers to the set of rules that combine characters into legitimate statements (Kemin: Word Mr. Foo through lexical group words or strings, and then by a phrase that represents different sentence components). Grammar defines the formal relationship between various elements of a language (kemin: What are the elements, what is the relationship?). ), so we give a description of the structure of the various legal statements in the language. Grammar only focuses on the syntactic structure, regardless of its meaning, which is semantic.

2. Semantics reveals disclosed the meaning of syntactically valid strings in a language. For natural languages, this means correlating sentences and phrases with the objects, thoughts, and feelings of our experi Ences. For programming languages, semantics describes the behavior of a computer follows when executing a program in the Langua Ge. We might disclose expose this behavior by describing the relationship between the input and output of a program or by a step-by -step explanation of how a program would execute on a real or an abstract machine.

semantics Specifies the meaning of a legitimate statement. In the case of natural language, the meanings of phrases and sentences refer to the related objects, thoughts and experiences, while for programming languages semantics describe the behavior of a computer as it executes a program. The behavior of revealing semantics includes describing the relationship between the input and output of the program, and gradually explaining how the program is executed in real or abstract machines. (Kemin: Semantics require some kind of implementation.) and the actual behavior of the computer, such as logical operation, memory to save the data and so on to realize the abstract semantics of the programming language (Kemin: here, the existence and importance of semantics is beyond reproach, the problem is unclear how it relates to the process of the algorithm. )

3. Pragmatics alludes to those aspects of language that involve the users of the language, namely psychological and sociol Ogical phenomena such as utility, scope of application, and effects on the users. For programming languages, Pragmatics includes issues such as ease of implementation, efficiency in application, and Progr Amming methodology.

pragmatics involves the content of various aspects of language users, including psychological, sociological phenomena, such as the practicality of language, the scope of application and the role of users. For programming language, pragmatic problem refers to the simplicity of realization, the efficiency of application and the methodology of programming.

Syntax must is specified prior to semantics since meaning can is given only to correctly formed expressions in a language. Similarly, semantics needs to being formulated before considering the issues of pragmatics, since interaction with human use RS can be considered-expressions whose meaning is understood. In the current text, we is primarily concerned with syntax and semantics, leaving the subject of pragmatics to those Design and implement programming languages, chiefly compiler writers. Our paramount goal are to explain methods for furnishing equip a precise definition of the syntax and semantics of a programmin G language.

The syntax must precede semantics, because only the correct form of the expression can be specified, and the semantics need to be clarified before the pragmatic problem is considered, because the user can communicate with the language only after they understand the meaning of the expression. This book is mainly about grammar and semantics, and the pragmatic part is left to the designer and the creator of the language, typically compiler developers. Our first goal is to explain the precise definition of the syntax and semantics of the equipment (furnishing) programming language.

We begin by describing a metalanguage for syntax specification called BNF. We then use it for define the syntax of the main programming language employed in this text, a small imperative language CA Lled Wren. After a brief look at variants of BNF, the chapter concludes with a discussion of the abstract syntax of a programming LAN Guage.

We first introduce a meta-language--BNF (the Basque-Noel Paradigm) that describes the syntax specification. We use it to define the grammar of the language Wren used in this book, and Wren is a very small command-style language. After an overview of the variant of BNF, we summarize the abstract syntax of the programming language.

At the simplest level, languages is sets of sentences, each consisting of a finite sequence of symbols from some finite a Lphabet. Any really interesting language have an infinite number of sentences. This does isn't mean the it has a infinitely long sentence but that there was no maximum length for all the finite length s Entences. The initial concern in describing languages is what to specify a infinite set with notation, is finite. We'll see that a BNF grammar are a finite specification of a language that could be infinite.

The syntax and semantics of programming language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.