Syntax – Common Concepts in Programming Languages

Syntax in Programming Languages

Congratulations! We have covered three major concepts that every programming language owns and going to conquer the 4th concept which is SYNTAX.

  1. Variables
  2. Control Structures
  3. Data Structures
  4. Syntax
  5. Tools

What is syntax?

Syntax; in linguistics, is the set of rules and principles that take cares of arrangement and order of words and phrases, for perfect sentence structure. So, syntax shows you the way that you must follow to make or say a perfect and meaningful sentence.

Now, we have thousands of languages around the world and each have distinct rules and principles for their own. We need to follow their very own way of “putting words together” or syntax to be able to say a nice sentence, in each.

Syntax in Programming Languages

I explained syntax in linguistics (Humans’ communication system) to make it easier for to understand syntax in programming. As humans have languages for communicating with each other and the languages have syntaxes for themselves, Computers have programming languages and these languages also have syntaxes (set of rules and principle).

We literally can say that Syntax shows the way of writing correct code in any programming language.

Syntax in programming languages is set of rules which defines the structure of a programming language. It controls the combination of symbols and words in a statement of a programming language. If you write programs with incorrect syntax then it will end up to errors. So, this would be very important to learn the syntax of any programming language first that you wish to work on.

Syntax of every programming language is very special to itself so, most of the time these rules (syntax) differ from other programming languages. Let’s have a glance on syntax in PHP:

\"\"

PHP Syntax

  • The PHP script is executed on the server and the HTML result is sent to the browser.
  • PHP files are saved with the “.php” extension.
  • PHP scripts can be written anywhere in the document within PHP tags along with normal HTML. 
  • Writing the PHP code inside <?php ….?> (Canonical PHP Tags) which separates PHP code from HTML is called Escaping to PHP
<?php
    # Here echo command is used to print
   echo \"Hello, world!\";
?>

// Hello, world!
  • PHP support Single-Line and Multi-Line comment
  • PHP is insensitive to whitespace.
  • PHP is case-sensitive

Blocks in PHP:

In PHP, multiple statements can be executed simultaneously (under a single condition or loop) by using curly-braces ({}). This forms a block of statements that gets executed simultaneously. 

\"\"

The syntax of any programming language will likely be your biggest hurdle as a new developer, but as you see more and more examples of code and are introduced to more and more syntax in the language, you will become comfortable.  Some developers of the programming languages have also developed tools to make it easier to become familiar with the syntax of the language.  These tools are called IDEs, or, Integrated Development Environments, which you can download onto your computer and use to create programs.  These IDEs have built in syntax checkers (much like the grammar checker in MS Word) that will let you know if your syntax is incorrect, and will even give you hints with what it thinks you meant to put!

These tools will be covered in the next section.

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these