What does 'Language Construct' mean?
Asked Answered
N

11

37

I am learning C from 'Programming in C' by Stephen Kochan.

Though the author is careful from the beginning only not to confuse the students with jargon, but occasionally he has used few terms without explaining their meaning. I have figured out the meaning of many such terms with the help of internet.

However, I could not understand the exactly meaning of the phrase 'language construct', and unfortunately the web doesn't provide a good explanation.

Considering I am a beginner, what does 'language construct' mean?

Nephron answered 7/4, 2012 at 19:15 Comment(3)
Did you try wikipedia?Jury
yeah, I tried.. couldn't grasp the concept. mind you, I am adult beginner, slow in learning.Nephron
Note that the term tends to be used fairly loosely, to refer to some subset of the language syntax/semantics.Harlequin
T
45

First, you must understand what a Formal Language is. All programming languages are formal 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.

Taillight answered 7/4, 2012 at 20:4 Comment(5)
@Taillight taking your analogy from English to CS, is it correct to say that anything that you can build using a particular grammar, such as EBNF for example, is a language construct? Wikipedia says that it's basically anything valid you can from from one or more lexical tokens. So I take it that from single symbols, such as digits (1, 2, ..) to operators (+, -, *,..) to combining those (1 + 2), everything here is a language construct? Logically it's something you can grammatically construct within that language.Pau
@Taillight so from individual tokens, to combining tokens and forming more complex statements, such as control structures (if - else blocks, fors, while, function definitions, class definitions) basically they're all constructs, correct? taking it semantically, to construct means to create/build, and language is a complex system of communication, i.e a language construct is anything you can construct within a language, so all of the above match the definition.Pau
@Taillight an absurd example just for educational purpose only: so definitely this x += y is a language construct. But would it be correct to say that that construct itself contains 4 language constructs? or do we draw the line at only what we build with more than 1 token? So I could say that from the grammatical rules of building an identifier I have constructed the one letter identifier y and the one letter identifier x respectively, yielding 2 constructs. Then I do the addition which is another construct and finally an assignment, which is another constructPau
@George I think before getting ourselves too much into "definition" complex we should find what is the purpose of programing languages ? Programing languages provide a context/model within which we communicate with computers , give "instructions" whatever those might be. So ultimate purpose is to generate "instructions". So anything that written in programing language which results into an instruction or set of instructions and hence ultimately computer performs some actions w.r.t given instruction(s).Taillight
@George I think what you are saying is correct and I ve simplified above in my commentTaillight
S
10

A language construct is a piece of language syntax. For example, the following is a language construct in C that lets you control the flow of a program:

if ( condition ) {
  /* when condition is true */
} else {
  /* when condition is false */
}

They usually use the term language construct because these are parts of most programming languages, but may be written differently, depending on the language. For example, a similar language construct in bourne shell would be:

if COMMAND; then
  # when command returns 0
else
  # when command returns anything else
fi

The function of this construct is the same, however, the way it's written is a bit different.

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.

Sommersommers answered 7/4, 2012 at 19:22 Comment(2)
Is your point that those two are the same construct or that they're the same concept achieved with two different constructs?Lawannalawbreaker
You make a good point. Yes, it is a "generic" language construct, a condition statement, represented in different languages i.e. different language, same construct, in this case. However, some languages have their own particular constructs. For example, Python has the "walrus operator" which is a construct which may or may not exist in other languages. I guess we could think of a construct as a capability of a language that we can implement using the language's syntax.Filiform
E
6

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.

Estelaestele answered 7/4, 2012 at 19:24 Comment(0)
S
5

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.

Sulphanilamide answered 7/4, 2012 at 19:25 Comment(0)
B
4

Without seeing the context that the phrase is used in, I cannot be sure, but generally the phrase 'language construct' just means the combination of keywords, grammar and structure of a coding language. Basically, how to format/write/construct a piece of code.

Brandebrandea answered 7/4, 2012 at 19:21 Comment(2)
"The proper use of indentation becomes even more critical when dealing with more sophisticated program constructs such as nested for statements". "naturally, the C language provides a special language construct to handle such a situation (talking about do statment)". "now that you are familiar with all the basic looping constructs provided by the C language".Nephron
Yes in this sentence it is used exactly as I thought. It is talking of 'more sophisticated' elements of the C coding language (in this case a nested 'for-statement'. 'for-statements' are just one of many coding language elements used to build a piece of code. Most common language constructs are for-loops, if-statements, while-loops etc.Brandebrandea
H
1

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.

Hacienda answered 25/8, 2014 at 16:26 Comment(0)
C
1

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
Carrew answered 20/8, 2015 at 10:12 Comment(0)
M
0

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  
Mercurial answered 4/7, 2019 at 15:18 Comment(0)
J
0

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"
}
Jackpot answered 3/4, 2021 at 12:56 Comment(0)
C
0

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.

Colis answered 16/10, 2021 at 3:16 Comment(0)
M
-1

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.

Meadow answered 20/8, 2015 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.