Transcript for:
Understanding Syntax in Programming Languages

in this video we'll discover what syntax means in the world of computer programming languages in the last module we established the fact that a computer needs to be instructed using a computer program which acts like a recipe instructing the computer to perform a task we also discussed the fact that computer languages allow you to express these instructions in a human friendly manner known as source code which ultimately gets converted to machine code which is what the computer's processor understands and executes we also saw various ways which computer languages employ to convert this source code to machine code now every computer language is made up of building blocks that are put together to form a computer program and we'll discuss these components or constructs later using a language agnostic way called pseudocode but first let's discuss syntax in simple words programming languages Implement a set of rules that must be followed when writing a computer program these rules are critically important to follow for the program to work correctly and differ from language to language let's talk about some of these rules however it is not important for you to remember language specific rules at this time the objective is to introduce you to some of these rules so you can recognize them later when you start writing your computer programs now programming languages are made up of keywords these are special Words which form part of the grammar of the programming language and they act like tokens of instruction that you can put together to form the logic of your program for instance in C plus plus Java JavaScript and python the keywords if and else are used to build a conditional statement which allows your program to take a decision based on a given set of parameters and possible values such keywords are reserved which means that you cannot use them for expressing your own data in a program we'll understand what this means later in the course but for now it is important to understand that a language is made up of several reserved keywords that act like building blocks of the language and defines its grammar in a similar way in JavaScript function is a keyword that is used to build reusable blocks of code and here's a list of reserved keywords in the JavaScript language now most computer languages are also case sensitive this means that out of these three variations of the keyword if only the first one is correct while the other two would produce an error case sensitivity is also one of the first few things where beginners tend to make mistakes as with other rules languages aren't forgiving and will raise an error if you get the case wrong [Music] now computer programs are like recipes which means that like a recipe you have multiple instructions and it is important for the programming language to know where a statement begins where it ends and where the next one begins many languages like Java C plus plus or even JavaScript Implement a pair of curly braces to indicate start and end of blocks of code here you can see a Java program with curly braces in place an opening curly brace indicates the start of a code block while the closing curly brace indicates the end of the block anything inside is part of that block as you can also see blocks can be nested this helps Define relationship and hierarchy of statements another feature in many programming languages is the use of a semicolon as the last character to indicate the end of a statement this means that this code can be written like the one on the left or even like the one on the right and it will work because we have semicolons to indicate the end of statements however as you can see code readability is Paramount which is why you would never write code the way it is shown on the right hand side but the key takeaway being that the language in this case does not enforce formatting to create separation between statements because it recognizes start and end of code blocks and individual statements using curly braces and semicolons this however may not be the case for every language languages like python for instance do not Implement curly braces or semicolons but enforce strict line breaks and indentation as a way to structure code blocks and indicate end of statements this is why python code looks clean and readable not because developers love writing it this way but because the language enforces this style or else will throw an error now the reason why these rules are place is because programming languages include Elixir a component which analyzes the code in a process known as lexical analysis and converts it into tokens that can be processed further that is why lectures are also known as tokenizers the lecture ignores white space during this process and categorizes tokens into various headers as per the grammar of the programming language these tokens are then fed into another component known as a parser which tries to make sense out of this sequence of tokens as it constructs a tree of these tokens as per the flow of the program the parser performs syntax analysis as per the rules of the language to ensure the program makes sense to the compiler this is why when writing a computer program attention to detail is as important as knowing the language up close and personal as we Traverse through the course pay attention to how code is written the specific case indentation sequence and Order of statements and the keywords used this is the grammar that you will be using to write your programs as you go along you will easily spot recognizable patterns that you will see across many languages learning syntax for any language can seem daunting with so many little details to keep in mind but don't give up look into opportunities like those offered at knowledgehut powered by our signature immersive learning with our outcome based immersive learning approach we are fundamentally disrupting the way New Age Technologies are learned you'll get to learn practice assess gain insights on your learning and personalize your Learning Journey on our easy to navigate AI powered skill building platform prism stay tuned for more such videos and explore more about how you can equip yourself with immediately demonstratable in-demand skills that will help you get job ready and don't forget to subscribe and press the Bell icon to get notified so you don't miss out on our upcoming videos