我正在从Stephen Kochan 的“Programming in C”中学习C。
虽然作者从一开始就很小心,只是不让学生用行话来混淆视听,但偶尔他会使用一些术语而不解释它们的含义。在互联网的帮助下,我已经弄清楚了许多此类术语的含义。
但是,我无法理解“语言结构”这个短语的确切含义,不幸的是,网络没有提供很好的解释。
考虑到我是初学者,“语言结构”是什么意思?
我正在从Stephen Kochan 的“Programming in C”中学习C。
虽然作者从一开始就很小心,只是不让学生用行话来混淆视听,但偶尔他会使用一些术语而不解释它们的含义。在互联网的帮助下,我已经弄清楚了许多此类术语的含义。
但是,我无法理解“语言结构”这个短语的确切含义,不幸的是,网络没有提供很好的解释。
考虑到我是初学者,“语言结构”是什么意思?
First, you need to understand what a constructed language is. All programming languages are constructed languages (read the reference). You may then read a little bit about compiler construction, including this reference as well.
Going back to your question, consider this: The English language (a natural language) has tokens 'A-Z/0-9/,;"...' which we use to build "words" and we use languages rules to build sentences out of words. So, in the English language, a construct is what we build out of tokens.
Consider this brick-and-mortar example: Imagine if you set out to build a house, the basic materials you might use are: sand, iron, wood, cement, water (just five for simplicity). Anything you build out of these 4 or 5+ items would be a "construct", which in turn helps you build your house.
I have intentionally omitted details to further simplify the answer; hope this is helpful.
语言结构是一段语言语法。例如,以下是 C 中的一种语言结构,可让您控制程序的流程:
if ( condition ) {
/* when condition is true */
} else {
/* when condition is false */
}
它们通常使用术语语言结构,因为它们是大多数编程语言的一部分,但可能会因语言而异。例如,bourne shell中类似的语言结构是:
if COMMAND; then
# when command returns 0
else
# when command returns anything else
fi
这个结构的功能是相同的,但是它的编写方式有点不同。
Hope this helps. If you need more detail, you may want to do a bit more research. As one of the comments suggests, Wikipedia may be helpful.
They are the base units from which the language is built up. They can't be used as a function rollback. They are directly called by the parser. It includes all the syntax, semantics and coding styles of a language. For more clarification you may refer to this question.
Wikipedia definition:
A language construct is a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language. The term Language Constructs is often used as a synonym for control structure, and should not be confused with a function.
在没有看到使用该短语的上下文的情况下,我无法确定,但通常“语言结构”这个短语仅表示关键字、语法和编码语言结构的组合。基本上,如何格式化/编写/构造一段代码。
Let say you want to create a class containing methods and properties, so:
Construct is an architecture of a class you are about to create. The architecture of the class consists of methods and properties created by you by using predefined utilities (such as: 'if', 'else', 'switch', 'break', etc)
That's my take on construct.
In reference to a programming language
Language Constructs mean the basic constructs of a programming languge e.g
1. Conditions (if, else, switch)
2. Loops (For, While, Do-while) etc
C is a structural language so while compiling your code everything thing goes statement by statement. Thus it becomes necessary to place your statement properly. This placing i.e. putting your statement correctly is your language construct else there may be syntax error or logical error.
Language constructs according to the GCSE book are basic building block of a programming language. that are
1. Sequential,
2. Selection, if, if/else
3. Iteration, while, for
Language construct is a piece of language syntax.
Example:
A declaration of a variable is a language construct:
{
int a; // declaration of a variable "a"
}
A language construct is a piece of syntax that the compiler has intimate knowledge about, usually because it needs to handle it specially. Typical examples of language constructs are the short-circuiting operators found in many imperative languages. Because these operators require lazy evaluation in an otherwise eager language, they must be handled specially by the compiler.
So, a stricter definition of a language construct may be: a syntactical form that is handled specially by the compiler, having functionality that cannot be implemented by a user.