Syntax and semantics of programming languages

Source: Internet
Author: User
The syntax and semantics of programming languages are taken from formal syntax and semantics of programming languages by kenth slonneger/Barry L. kurtz.
Liu Jianwen translated (http://blog.csdn.net/keminlau) Chapter 1
Specifying 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 Education ages-the forms and meanings of different ages are subjected to a more rigorous examination. this science can also be applied to the subject of this text, programming ages. in contrast to the natural versions, with which we communicate our thoughts and feelings, programming versions can be viewed as Artificial versions defined by men and women initially for the purpose of communicating with computers,, as importantly, for communicating algorithms among people.

The language provides communication channels in the form of sound and text symbols. Humans generally learn language through the experience of life. However, in a scientific linguistics, the form and meaning of language must be strictly studied (rigorous examination ). The same scientific treatment is certainly applied to the topic of this book-programming language. Unlike natural languages, which are used to communicate ideas and feelings, a programming language can be regarded as a human language. It is initially defined as a human-computer communication, but now it is more important to exchange program algorithms between programmers.

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

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

1. syntax refers to the ways symbols may be combined to create well-formed sentences (or programs) in the language. syntax defines the formal relations between the constituents elements of a language, thereby providing a structural description of 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.

SyntaxIt refers to the rule set that combines characters into French sentences (Kemin: A character is first formed by a lexical group word or string, and then by a phrase that represents different sentence components ). Syntax defines the formal relationship between various elements of a language (Kemin: What elements and what relationships ?), Therefore, the structure descriptions of various legal statements in the language are given. Syntax only focuses on the syntax structure, regardless of its meaning, it is a semantic thing.

2. Semantics reveals revealed the meaning of syntactically valid strings in a language. For natural ages, this means correlating sentences and
Phrases with the objects, thoughts, and feelings of our experiences. for programming versions, semantics describes the behavior that a computer follows when executing a program in the language. we might disclose exposes 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 will execute on a real or an abstract machine.

SemanticsSpecifies the meaning of a valid statement. For a natural language, the meanings of phrases and statements refer to the objects, thoughts, and experience. For a programming language, semantics describes the behaviors that a computer performs when executing a program. Revealing the semantic behavior includes describing the relationship between input and output of a program, and gradually explaining how the program runs in a real or abstract machine. (Kemin: semantics requires some implementation. The actual computer behavior, such as logical operations and data storage in the memory, implements the abstract semantics of the programming language. (Kemin: here, the existence and importance of semantics are beyond reproach, the problem is unclear about its relationship with the algorithm process .)

3. pragmatics alludes to those aspects of language that involve the users of the language, namely psychological and sociological phenomena such as utility, scope of application, and effects on the users. for programming syntax ages, pragmatics includes issues such as parameter of implementation, efficiency in application, and programming methodology.

PragmaticIt involves various aspects of the language user, including psychological and social phenomena, such as the practicality of the language, the scope of application and the role of the user. For programming languages, pragmatic issues refer to the simplicity of implementation, application efficiency, and programming methodology.

Syntax must be specified prior to semantics since meaning can be given only to correctly formed expressions in a language. similarly, semantics needs to be formulated before considering the issues of pragmatics, since interaction with human users can be considered only for expressions whose meaning is understood. in the current text, we are primarily concerned with syntax and semantics, leaving the subject of pragmatics to those who design and implement programming languages, chiefly compiler writers. our paramount goal is to explain methods for furnishing equipped with a precise definition of the syntax and semantics of a programming language.

Syntax must be given prior to semantics, because only definitions can be specified for expressions in the correct form. Likewise, semantics must be clarified before consideration of the pragmatic problem, because the user can use the language to communicate only after understanding the meaning of the expression. This book mainly describes the syntax and semantics. the pragmatic part is left to the designers and implementers of the language, generally compiler developers. Our first goal is to explain how furnishing accurately defines the syntax and semantics of a programming language.

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

First, we will introduce BNF, A metalanguage that describes syntax specifications ). We use it to define the syntax of the language Wren used in this book. Wren is a very small imperative language. After reviewing the BNF variants, We will summarize the abstract syntax of the programming language.

At the simplest level, ages are sets of sentences, each consisting of a finite sequence of symbols from some finite alphabet. any really interesting language has an infinite number of sentences. this does not mean that it has an infinitely long sentence but that there is no maximum length for all the finite length sentences. the initial concern in describing versions is how to specify an infinite set with notation that is finite. we will see that a BNF grammar is a finite specification of a language that may be infinite.

Reference

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.