Table of Contents
Syntax and Semantic in Programming Language
This tutorial covers the basic introduction of syntax and semantic with example. Difference between syntax and semantic errors is also explained.
Some basic definition types questions are generally asked in Technical Interview.
Here in this post we have answer these questions are explained properly. Students are kindly requested to read the tutorial till the end.
Syntax and semantic these are related terms in context of a programming language.
Syntax and semantic both have equal importance for any language to make a program in that programming language more user friendly and understandable.
So let’s first understand the meaning of syntax and semantic.
Frequently Asked Questions
By the end of this tutorial students will be able to answer the following questions
- What is syntax ?
- What is semantic ?
- What is difference between syntax and semantic ?
- What is concrete syntax?
- What is abstract syntax ?
- What is difference between logical error and run time error ?
- What is difference between compiler and interpreter?
So let’s start with introduction with syntax.
What is Syntax?
In context of a programming language Syntax refers to the structure of the program without concerning about it’s meaning.
Syntax gives the emphasis on design or layout of the program. How the program looks?
Syntax also involves the validation of sequence of symbols and the instruction used in the program.
When compiler compiles a program the it perform syntax analysis tasks. Compiler perform
Lexical analysis of syntax is performed to define the rules for identifiers, literals, punctuators and operator
Concrete syntax specifies the representation of the programs with the help of lexical symbols such as it’s alphabets.
Abstract syntax is used by compiler just for the important program information.
What is Semantic ?
Semantics term in a programming language is used to figure out the relationship among the syntax and the model of computation used in the program
Semantic gives the emphasis on the interpretation of and make it easy for the programmer to understand the program and predict the output.
In any any language Semantics deals with the meaning of a sentence.
In programming let us understand syntax and semantic with the help of an example.
Consider a function abc() as shown below. If call a function that can only work on two values of a ‘char’ variable.
abc(char d){
if(d == ‘y’){
//DO SOMETHING
}
else if(d == ‘n’){
//DO ANOTHERTHING
}
}
And we call this function with some other value:
abc(‘a’);
Difference Between Run Time Error and Logical Error
Difference Between Compiler and Interpreter
Conclusion and Summary
In this tutorial we have discussed several basic questions related to syntax and semantic.
I hope that after reading this tutorial students will be able to answer the questions discussed in the tutorial.
I kindly request to readers please give your feedback and suggestion. If you find any mistake in this tutorial then comment.
All the Best !!