teach-ict.com logo

THE education site for computer science and ICT

2. Syntax

All programming languages have a set of rules on what is, and is not allowed when forming a line of code. In other words, all programming languages have a 'grammar'.

Syntax is the word used to describe the grammatical rules of a programming language.

Typical syntax rules

Every language is different but here are some typical syntax rules

End of statement marker: Many languages insist on a semi-colon ';' to indicate an end-of-statement, like this (other languages do not)

print z;

Rules about forming a function: High level languages set out rules about the general layout of a function, like this

    function this_is_a_function () {
      ..... (code in here)
    }

The rule above shows that in this programming language, every function must start with the word 'function'

followed by a valid name for the function (this_is_a_function).

And all the code for the function is enclosed by curly brackets { }

Rules about recognised keywords: A computer language is made up of a limited set of recognised words that do something in the language, like this

print
if
then
for

These must be spelt properly.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Programming language syntax rules