3.3 CONCEPT OF PROGRAMMING LANGUAGE
In order to communicate with other human beings, one needs some language or a medium. In the same way for solving problems, a programming language is required in order to communicate with the computer. A Programming Language is used to design and describe a set of instructions/actions for the computation that we wish to be executed by the computer.
First an algorithm is designed which solves the problem in question. In the next step, the algorithm is expressed in the form of a program. For this one should have a sound knowledge of some programming language. A program written in a particular Programming Language can control the behavior of a computer and perform a designated task to generate the desired output for any given input.
Program and Programming Language : A Program is defined as a collection of statements/ instructions that enable the computer to solve a problem. The process of writing a program is called programming. Statements in a program should be well formed sentences. Each Programming Language has some basic building blocks called the primitive building blocks. These blocks are defined by basic components that have an associate Syntax and Semantics. Syntax provides structure and semantic provides meaning to it. Different computer programming languages have different advantages and disadvantages to their use. Hence different application domains based on their requirement and functionality may choose any one of the available programming languages suitable for the task.
Syntax provides the structure and how to formulate the phrase or sentence w.r.t grammar of the language. It tells us about which composition is allowed from the character set of the language. Each sentence must be a well formed sentence according to the grammar of the language. The grammar is expressed in a Number of rules that will be finite and these allow the formulation of any number of sentences. A language is defined in the form a quadruplet L(T,N,P,S) where T is set of terminals, N is a set of non terminals, P is set of productions or rules and S is the start symbol. For any language we must have an alphabet/character set, operators and rules. To form a grammar w.r.t a language rules need to be formed. The basic structure of rule is LHS and RHS with some set of terminal and non terminal symbol.
Syntax comprises grammar and vocabulary whereas syntactic analysis is known as parsing. Semantics provides the meaning for the formulated /composed phrase or word or sentence. Semantic function can be incorporated inside the logic of a compiler or interpreter which evaluates ordering of statements for execution.
S-> A
A->Ab | b i.e any word with sequence of any number of occurrence of character b
Start symbol:
Here S is start symbol. Any sentence will start with start symbol only.
In respect of BNF notation it is as follows:
L(T,N,P,S)
T={b}
N={A}
P={S->A,A->Ab}
S=Start sybmol
Example grammar:
Program: statement
Statement: stmt| stmt
Stmt: var=expression
Var:a|b
Expression: term +term | term-term
Term: var/const e.g x=y+2
Similarly
Sentence: subject,verb,object
Subject: noun/article
e.g Ram ate biscuits.
Here each symbol on the left is described in terms of its components. Thus a program consists of statements, which are of the form of an assignment of a variable to an expression, and so on.
Any number of sentences can be formed with the help of a grammar defined for a language. The grammar should be unambiguous. otherwise during syntactic analysis at some point of time it can have more than one meaning.
Comments
Post a Comment