People might be confused as to what do we mean by programming grammar. Might seem to be a new term but it has been learnt unintentionally by all the programmers.
When we talk about any Computer Language Programming, we need to know the grammar of it. This is similar to the grammar that we have learnt in our school for English, Hindi, Bengali, Urdu, Marathi or any other language. This basically tells us the way we write the lines in our language. For Example, in English language, every sentence must end with a full stop (.) same as every command in C or Java language must end in a semi-colon (;).
The two major terminologies of Programming Language which we need to comply with while writing a successful bug-free and defect free code are Syntax and Semantics.
- Syntax – This basically checks whether each sentence in the code is correctly written or not. It also checks whether the entire code is correctly written and the sequence of the sentences is also correct. For Example, each programming sentence should end with a semi-colon, all variables are on the left side of comparison operators (<,>,=,!=) etc.
- Semantics – This check is done after the syntax check is complete. It verifies whether all terms in the sentence have some meaning and the code as a whole has some meaning or not. In programming terms, it checks whether all the variables, functions, procedures, packages used in the code are valid and ready to use.
Only if your code has passed the grammatical test, you can move ahead with compiling the code and using it for any purpose. Its similar to your essay test in school. Only if each sentence was grammatically correct and the entire passage contained some meaning, the teacher is able to give good marks to the student. That’s the importance of grammar in any language.