Language construct: Difference between revisions

Content deleted Content added
Covert23 (talk | contribs)
m basic grammar clarification
Tags: Visual edit Mobile edit Mobile web edit
 
(18 intermediate revisions by 17 users not shown)
Line 1:
{{Short description|Syntactically valid part of a program formed from lexical tokens}}
{{Unreferenced stub|auto=yes|date=December 2009}}
{{More sources|date=January 2021}}
 
AIn [[computer programming]], a '''language construct''' is "a [[syntaxSyntax (programming languages)|syntactically]] allowable part of a [[Computer program|program]] that may be formed from one or more [[lexical token]]s in accordance with the rules of athe [[programming language]]", as defined by in the [[ISO/IEC 2382]] standard ([[ISO/IEC JTC 1]]).<ref name="ISO/IEC 2382">{{cite web |title=ISO/IEC 2382, Information technology — Vocabulary |url=https://www.iso.org/obp/ui/#iso:std:iso-iec:2382:ed-1:v1:en}}</ref>
A '''term''' is defined as a "linguistic construct in a [[conceptual schema]] language that refers to an entity".<ref name="ISO/IEC 2382"/>
 
While the terms "language construct" and "control structure" are often used synonymously, there are additional types of logical constructs within a computer program, including [[variable (computer science)|variables]], [[expression (computer science)|expressions]], [[function (computer science)|functions]], or [[modular programming|modules]].
The term Language Constructs is often used as a synonym for [[Control flow|control structure]], and should not be confused with a [[Subroutine|function]].
 
[[Control flow]] statements (such as [[Conditional (computer programming)|conditionals]], [[foreach loop]]s, [[while loop]]s, etc) are language constructs, not [[Subroutine|function]]s. So <code>while (true)</code> is a language construct, while <code>add(10)</code> is a function call.
 
==Examples of language constructs==
In [[PHP]] <code>print</code> is a language construct.<ref>{{Cite [httpweb |title=PHP: print - Manual |url=https://www.php.net/manual/en/function.print.php] |access-date=2022-11-18 |website=www.php.net}}</ref>
<sourcesyntaxhighlight lang="php">
<?php
print 'Hello world';
?>
</syntaxhighlight>
</source>
 
is the same as:
 
<sourcesyntaxhighlight lang="php">
<?php
print('Hello world');
?>
</syntaxhighlight>
</source>
 
{{DEFAULTSORT:Language Construct}}
[[Category:Programming constructs]]
 
In Java a [[class (computer programming)|class]] is written in this format:<syntaxhighlight lang="java">
public class MyClass {
//Code . . . . . .
}
</syntaxhighlight>
 
In C++ a class is written in this format:<syntaxhighlight lang="c++">
{{Compu-lang-stub}}
class MyCPlusPlusClass {
bmnhhj
//Code . . . .
 
};
 
</syntaxhighlight>
 
==References==
PHP has a huge collection of built-in functions that you can call directly within your PHP files. While going through built-in functions, you might have faced the term language construct.
{{reflist}}{{Compu-lang-stub}}
 
For an example you might have seen that echo() is not a function but a language construct. In addition to echo() following are some other language constructs.
 
1.
print()
2.
unset()
3.
isset()
4.
empty()
5.
include()
6.
require()
7.
die()
In coding, language constructs are used and behave almost similar to built-in functions. The real difference lies in how PHP engine interprets a language construct and a built-in function.
 
Any computer language is made up of basic elements and these elements are known by their respective language parsers. For an example if is a basic element in PHP and PHP parser is aware of it.
 
So when a PHP file is going through PHP parser, if it sees an if then it knows that there should be a left parenthesis next to that. If not, PHP parser would throw an error. Here we can call if a language construct because PHP parser knows what it is without further analyzing.
 
In a similar way we can think that PHP parser recognize and know what to do when it sees echo() or any other language construct. When PHP parser finds a built-in function, first it needs to check the language definitions and convert the function into set of known language constructs.
 
Language Constructs Are Relatively Faster
 
If you research on language constructs vs built-in functions, you might have seen that it says language constructs are relatively faster over built-in functions since they are basic elements of the language.
 
However you shouldn’t think about the difference in anything more than microseconds. And also final execution time depends on the parameters that are passed into language constructs or built-in functions.
 
Language Constructs Don’t Need Parenthesis
 
1.
echo ('Today is a beautiful day');
2.
echo 'Today is a beautiful day';
3.
$today = 'Today is a beautiful day';
4.
echo $today;
5.
6.
die('You are not authorized to access this content');
7.
die;
All above coding lines are correct and processed as expected. Note that echo() and die() both are language constructs and they can be used with or without parenthesis. However you can’t use built-in functions without parenthesis.
 
view sourceprint?
1.
count($namesArray); // This is correct assuming that $namesArray is defined.
2.
count $namesArray; // This is incorrect. It's identified as a syntax error.