Privacy Policy Cookie Policy Terms and Conditions Curly bracket programming language - Wikipedia, the free encyclopedia

Curly bracket programming language

From Wikipedia, the free encyclopedia

Curly brace or bracket programming languages are those which use balanced brackets ({ and }, also known as "brace brackets" or simply "braces") to make blocks in their syntax or formal grammar, mainly due to being C-influenced.

Contents

[edit] History

Curly-bracket style goes way back before C. BCPL was the first language to use a curly bracket style, for outlining multi-statement function bodies. Ken Thompson gave the feature more glory in B. Because C was initially designed after B, C has retained the bracket style of B. Many languages that came after C (C++, Java, JavaScript and its generalized standard ECMAScript, C#, D, etc.) keep the style. Pico is a non-C descendant that also uses this style.

One common part of curly bracket style is the common style of terminating a statement with a semicolon (;), which is one way for languages to ignore whitespace. BCPL and Pico, do not have this rule. Thus a newline is used as a statement terminator in such languages. The Pico indent style is then used, as below (BCPL):

LET FUNC foo(a) = VALOF
{ b := a + 1
  RESULTIS b }

[edit] Statements and blocks

The name derives from the common syntax of the languages, where blocks of statements are enclosed in curly brackets. 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 syntax. Beside the curly brackets, 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.

A popular way to work with curly braces is with the K&R style:

int i;
for(i = 0; i < 10; i++) {
   printf("%d", i);
   doTask(i);
}

There are many other ways to identify statement blocks, such as ending keywords that may match beginning keywords (in Ada, Pascal, REXX, and Visual Basic), the Off-side rule of indentation (in Python), or other symbols such as parentheses (in Lisp). These ways are not necessarily exclusive: whereas indentation is the default in Haskell, curly brackets can be used when desired.

[edit] Loops

In C, C++, C#, and Java:

while (boolean expression)
{
    statement(s)
}
do
{
    statement(s)
} while (boolean expression);
for (initialisation; termination condition; incrementing expr)
{
    statement(s)
}

[edit] Conditional statements

In C, C++, C#, and Java:

if (boolean expression)
{
    statement(s)
}
if (boolean expression)
{
    statement(s)
} 
else
{
    statement(s)
}
if (boolean expression)
{
    statement(s)
} 
else if (boolean expression)
{
    statement (s)
}
...
else
{
    statement(s)
}
switch (integer expression)
{
    case constant integer expr:
        statement(s)
        break;
    ...
    default:
        statement(s)
        break;
}

[edit] Exception handling

In C++, C# and Java:

try
{
    statement(s)
}
catch (exception type)
{
    statement(s)
}
catch (exception type)
{
    statement(s)
}
finally
{
    statement(s)
}

Objective-C has the same syntax starting with gcc 3.3 and Apple Mac OS X 10.3 , but with an at sign in front of the keywords (@try, @catch, @finally).

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.

[edit] Problems

Some 7 bit national ISO646 sets redefine curly brackets to characters that make programs hardly readable on such designed terminals. For example, the YUSCII set used in Yugoslavia redefines '{' as 'š', while '}' is redefined to 'ċ'. To address this problem, ANSI C introduced trigraphs that can be used instead of such problematic characters. All trigraphs consist of two question marks (“??”) followed by a character that is not redefined in the national 7 bit ASCII character sets. The trigraphs for ‘{’ and ‘}’, respectively, are “??<” and “??>”.

[edit] Languages

THIS WEB:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2006:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu