Syntax Of Programming Languages

This article describes the syntax of programming languages.

Comment

See comment

Statements and blocks

The curly brace family of programming languages includes C, C++, D, Java, JavaScript, AWK, Perl, PHP, C#, Pico programming language and others. The name derives from the common syntax of the languages, where blocks of statements are enclosed in curly braces. For example (using BSD/Allman indent style, one of many stylistic ways to format a program):
  for (int i = 0; i < 10; i++)  {     printf("%d", i);     doTask(i);  } 
Languages in this family are sometimes referred to as C-style, because they tend to have syntax that is strongly influenced by C's syntax. Beside the curly braces, they often inherit other syntactic features, such as using the semicolon as a statement terminator (not as a separator), and the three-part "for" statement syntax as shown above. Generally, these languages are also considered "free-form languages", meaning that the compiler considers all whitespace to be the same as one blank space, much like HTML. Considering that, the above code could be written:
  for(int      i=0;i<10;i++){printf("%d",i);doTask(i);} 
but this is not recommended, as it becomes nearly impossible for a person to read after the program grows beyond a few statements. There are many other ways to identify statement blocks, such as ending keywords that may match beginning keywords (see Visual Basic, Pascal, Ada, and REXX), indentation (see Python), or other symbols such as parentheses (see LISP).

Loops

In Java, C and C++
  while (Boolean expression) {      statement(s)  } 
  do {      statement(s)  } while (Boolean expression); 
  for (initialisation ; termination condition ; incrementing expr) {      statement(s)  } 

Conditional statements

In Java, C and C++
  if (Boolean expression) {      statement(s)  } 
  if (Boolean expression) {      statement(s)  } else {      statement(s)  } 
  switch (integer expression) {      case constant integer expr:           statement(s)           break;      ...      default:           statement(s)           break;  } 
In Ruby,
  if expression then     statement(s)  end 

Exception handling

In Java:
  try {      statement(s)  } catch (exception type) {      statement(s)  } catch (exception type) {      statement(s)  } finally {      statement(s)  } 
C++ does not have finally, but otherwise looks similar. C has nothing like this, though some compilers vendors added the keywords __try and __finally to their implementation. *

 

<< PreviousWord BrowserNext >>
list of chess topics
marguerite steinheil
bob montana
hermann tilke
hyper x
crazy ivan
oceanic climate
cecil gordon lawson
william henry hunt
babylon (new testament)
hillbrow
george john pinwell
ara santa fe
kingstanding
jean ingelow
tengku intan zaharah
robert buchanan
wide xga
falkirk f.c.
keith floyd
henry somerset, 3rd duke of beaufort
display standard
fica tax
read my lips
adams farwell
shoot from the hip
variable fighter
august, graf von platen hallermnde
august kopisch
tuanku siti aishah
ken sugimori
atascii
charles noel somerset, 4th duke of beaufort
alpha veritech
low grade fever
chwi
doosra
ludwig adolf wilhelm von ltzow
shimoda
ferdinand von schill
donald shimoda
sillame
beta veritech
craig mcclanahan