unit-1(Programming Language)
unit-1(Programming Language)
unit-1(Programming Language)
Programming Language
A brief history of Programming Language: Programming Languages
What is Programming language?
Programming language is a notation for describing Algorithm and data.
What is a Program:
A sentence of a programming language.
Let start from year "1954"
Fortran (FORmula TRANslator)
• It is Created in 1954 by John Backus.
• It is First high-level language.
• It was developed by using the first compiler ever developed
• It is Machine Independent Language.
FORTRAN 2nd:
• In 1958 introduces subroutines, functions, loops and primitive for loop
IAL(International Algebraic Logic)
• It started as a Project later renamed ALGOL58
• The theoretical definition of the language is published
• No compiler is required in this
LISP(LISt Processing) :
• It is created in 1958 and released in 1960 by John Mccarthy of MIT.
• LISP was intended for writing artificial intelligence programs.
Features
• It uses Atoms and List as data structure
• Functional programming style- all component computation is performed by applying functions
to arguments variable declaration are rarely used.
• A Reliance on recursion- a strong Reliance on recursion has allowed LISP to be successful in
many areas including artificial intelligence.
• Garbage collection: LISP has built in garbage collection so programmers do not need to
explicitly free dynamically allocated memory.
COBOL (Common Business Oriented Language)
• It was rated in May 1959 by the ShortRange committee of the us department of DOD.
• The CODASYL(COnference on Data SYstems Languages) Worked from May 1959 to April
1960.
• ANSI standard included(cobol-68(1968), Cobol-74(1974),COBOL-85(1985), and COBOL-
2002(2002)
• Object Oriented version of COBOL is introduced in 1997 i.e COBOL-97
Data object is usually represented as storage in Computer memory and a data value is
represented by a pattern of bits. So we can represent the relation between Data Object and
Data value.
A Data Object is elementary if it contains a data value that is always manipulated as a unit.
A Data Object is an Data Structure if it is an aggregate of the data object
Binding and Attributes of Data Object:
Binding is an association of data values and entity.
1) Type: This associates the data object with the set of data values that the object may take.
2) location: This associate the binding of a storage location in memory where the data
object is represented. Only storage management routines can only change add data object
in the virtual computer.
3) Value: This binding is usually the result of an assignment operation.
4) Name: The binding to one or more names by which the object maybe referenced during
program execution is usually set up by declaration and modified by subprogram calls the
returns.
5) Component: The binding of a data object to one or more data object of which it is a
component is often represented by a pointer value. And may be modified by a change in
pointer.
An elementary data object includes a single data value and a class of elementary data objects
with a set of operations for creating and manipulating them is represented as an elementary data
type. An example of elementary data types such as integer, real, character, Boolean, pointer, etc.
The basic components of elementary data types are as follows −
Attributes − Attributes refers to characteristics or group of characteristics that distinguish
one data object from others. The main attributes of a data object are its name, associated
address, and data type. The following declaration in C.
int a;
It specifies that a data object named ‘a’ is of type integer. The attributes of a data object can be
stored in a collection of memory cells, called descriptor (or dope vector). A descriptor is the
group of attributes of a variable. If the attributes are all fixed, descriptors are needed only at
compile time. They are developed by the compiler, generally as a part of the symbol table, and
are used during compilation.
Values − It refers to a set of all possible values that a data object can contain. The values
that a data object can assume are determined by the type of that data object. An
elementary data object contains a single value from the set of values at any point during
its lifetime. For example, the C declaration int a; specifies that the data object a can
assume a single integer value from a set of integer values. The value included in a data
object can change during the lifetime of the data object and is therefore represented
explicitly during the program execution.
Operations − An operation refers to a mathematical function for the manipulation of data
objects. An operation includes −
o Domain − It refers to a set of all possible input arguments on which the operation
is defined.
o Range − It refers to a set of all possible results that an operation can produce as an
output.
o Action − The action of the operation represents the result created for any given set
of arguments.
o Algorithm − It defines how to evaluate the results for any given set of arguments.
It is used for determining the action of an operation.
o Signature − A signature of an operator defines the number, order, and data types
of the arguments in the domain of an operation and the order and data type of the
producing order.
Elementary Data Types
Variables and Constants
Variables: A variable is it Quadruple which is composed of a name,a set of attributes, a
reference and a value.
A simple variable is an elementary data object with a name and binding of data object to
value may change during its lifetime. This data objects are basically defined and named
by programmer explicitly.
Attribute of a variable:
Lets take example of variable in "ALGOL Language"
y:=9;
We can say that it has four attributes
• 1) the name of the box:y
• 2) The name of description of a current contents.
i.e 9 we can also say that square of 3.
• 3) the box or storage location(s) which holds(s) the value.
• 4) the content of the box or 9.
The name of the box and its storage location are fixed, but the contents and it name may
vary over time.
Let's take another example in C language:
int N;- It declares a simple data object N of type integer.
N=27; beta value 27 is assigned to variable N.
• 1) declare the variable name N of type integer.
• 2) lifetime of N is execution end.
• 3) data object bound to N during end of execution time.
• 4) value 27 is assigned and may be changed during life of N.
• 5) hidden from the programmer are other binding made by virtual computer like
creating Activation Record, Storage for this activation record in Run-TimeStack etc.
Constant:
A data object with a name that is bound to a value (or values) permanently
during its lifetime. The constant value can only be a number, string or identifier
which denotes constant.
const PI=3.1415;
real root2=1.4142135;
That was much acceptable that time.
In Ada, provides a uniform notation for setting constants to initial values and for
initializing variables.
X: Constant INTEGER:=17;
In C, there is micro definition which is used for control the execution of program
In this 30 has two names, the programmer defined MAX and literal name
30. Both of which may be used to refer to a data object containing the
value 30.
# define MAX 30 is a command, which the translator used to
equate "MAX" with the value "30", where as the const attribute in C is a
translator directive starting that MAX will always contain the value 30.
Data Types In Programming Languages
Data type is a set of object and a set of operation on those object which
create, Build up, destroy, modify and pick apart instances of the objects.
or
A programming languages necessary deals more commonly with data types such
as the class of arrays, integers, or file and the operations provided for
In LISP major data type is the binary tree(called an S- expression) and basic
Fortran 77- integer, real, logical, character, double precision, complex
Attribute:-
• Numbers of dimensions
Value:
• It would be sets of numbers that form valid values for array components.
Operations-
• create arrays.
DATA TYPE
A data type is an attribute associated with a piece of data that tells a computer system how
to interpret its value. Understanding data types ensures that data is collected in the preferred
format and the value of each property is as expected.
For example, knowing the data type for “Ross, Bob” will help a computer know:
the data you collect is always in the right format (“Ross, Bob” vs. “Bob Ross”)
Integer (int) Numeric data type for numbers without fractions -707, 0, 707
Floating Point
Numeric data type for numbers with fractions 707.07, 0.7, 707.00
(float)
Single letter, digit, punctuation mark, symbol, or blank
Character (char) a, 1, !
space
List with a number of elements in a specific order— rock (0), jazz (1), blues
Array
typically of the same type (2), pop (3)
It is the most common numeric data type used to store numbers without a fractional component
(-707, 0, 707).
It is also a numeric data type used to store numbers that may have a fractional component like
monetary values do (707.07, 0.7, 707.00).
Please note that number is often used as a data type that includes both int and float types.
Character (char)
It is used to store a single letter, digit, punctuation mark, symbol, or blank space.
It is a sequence of characters and the most commonly used data type to store text. Additionally,
a string can also include digits and symbols, however, it is always treated as text.
A phone number is usually stored as a string (+1-999-666-3333) but can also be stored as an
integer (9996663333).
Boolean (bool)
It represents the values true and false. When working with the boolean data type, it is helpful to
keep in mind that sometimes a boolean value is also represented as 0 (for false) and 1 (for true).
It contains a small set of predefined unique values (also known as elements or enumerators) that
can be compared and assigned to a variable of enumerated data type.
The values of an enumerated type can be text-based or numerical. In fact, the boolean data type
is a pre-defined enumeration of the values true and false.
For example, if rock and jazz are the enumerators, an enumerated type variable genre can be
assigned either of the two values, but not both.
With enumerated type, values can be stored and retrieved as numeric indices (0, 1, 2) or strings.
Array
Also known as a list, an array is a data type that stores a number of elements in a specific order,
typically all of the same type.
Since an array stores multiple elements or values, the structure of data stored by an array is
referred to as an array data structure.
Each element of an array can be retrieved using an integer index (0, 1, 2,…), and the total number
of elements in an array represents the length of an array.
For example, an array variable genre can store one or more of the elements rock, jazz, and blues.
The indices of the three values are 0 (rock), 1 (jazz), and 2 (blues), and the length of the array is
3 (since it contains three elements).
Continuing on the example of the music app, if you are asked to choose one or more of the three
genres and you happen to like all three (cheers to that), the variable genre will store all three
elements (rock, jazz, blues).
Date
Needs no explanation; typically stores a date in the YYYY-MM-DD format (ISO 8601 syntax).
Time
Stores a time in the hh:mm:ss format. Besides the time of the day, it can also be used to store the
time elapsed or the time interval between two events which could be more than 24 hours. For
example, the time elapsed since an event took place could be 72+ hours (72:00:59).
Datetime
Stores a value containing both date and time together in the YYYY-MM-DD hh:mm:ss format.
Timestamp
Typically represented in Unix time, a timestamp represents the number of seconds that have
elapsed since midnight (00:00:00 UTC), 1st January 1970.
An elementary data object contains a single data values and class of such data objects over which
various operations are defined is termed as elementary data type.
Some elementary data types: Integer, real, character, Boolean, enumeration and pointer and
specification may differ significantly between two languages.
Attributes: Basic attributes of any data object, such as data type and name are usually invariant
during its lifetime.
Some attributes may be stored in a descriptor as a part of the data object daily program execution.
Others may be used only to determine the storage representation of the data object.
The value of an attribute of a data object is different from the value that the data object contains.
Values: The type of a data object determines the set of possible values that it may contain.
because most hardware implements multiple Precision integer arithmetic( example 16 bit and 32
bit integers or 32 bit and 64 integers) We can use' short' for shortest value of the integer word
length.
int uses the most efficient value that the hardware implements.
In C, Characters are stored as 8 bit integers in the type char, which is subtype of integer.
Operations:- The set of operations Defined by language is basically refers that how data object
of that data type may be manipulated.
Example
a) integer addition is an operation that take to integer data objects as an arguments and produces
an integer data object as a result.
(Port of operation)
An algorithm that specifies how to compute the results for any given set of arguments is a
common method for specifying the action of an operation.
• Set of algorithms or procedures that define the operations of the type in terms of
manipulations of the storage representation.
1) Hardware Influence: Computer hardware influence the storage of elementary data type.
In this case computer hardware executes the program. If the hardware storage representation are
used, then the basic operations on data of that data type not implemented using hardware
provided operations.
2) Software influenced: If we do not use hardware storage representation, then the operation
must be software simulated and some operation will execute much less efficient.
It has to be determined by the compiler and not stored in discriptors during execution or not
stored in runtime storage representation. It is usually a method in C language.
It is stored in a descriptor as part of the data object at runtime in LISP, Prolog language .
• Size of the block of memory required(the number of memory words bytes, ot bits needed)
Implementation of operations:
Each operation defined for data objects of a given type may be implemented in one of three main
ways:-
1) Directly as a hardware operation: If simple data types are stored using the hardware
representation, when the primitive operations are implemented using the arithmetic operations
built in to hardware.
2) As a Subprogram or procedure: A square root for an example, this operation is not provided
directly as a hardware operation. So it is software simulated implemented as a procedure or
function.
3) as an inline code sequence: It is software implementation of the code and its operation.
Instead of using a subprogram, operation in the subprogram are copied into the program at the
point where the subprogram would otherwise have been invoked.
For Example:
c) set x=-x
Declarations provide information about the name and type of data objects needed during program
execution.
- implicit declaration
- explicit declaration
They are those declaration which is done by compiler when no explicit declaration or user defined
declaration is mentioned.
Example
$abc='astring';
$abc=7;
Float A,B;
It is an example of Float A,B, of c language. In explicit we or user explicitly defined the variable
type. In this example it specifies that it is of float type of variable which has name A & B.
- compiler need the signature of a prototype of a subprogram Or function so it can determine the
type of argument is being used and what will be the result type.
* Before the calling of subprogram, Translator need to know all these information. *
Example in C language
Purpose of Declarations:
2) Storage Management: It make to us to use best storage management for data object by
providing its information and these information as tells the lifetime of a data object.
For Example:-
In C language we have many options for declaration for elementary data type.
It tells lifetime is only at the end of execution as lifetime of every data objects can be maximum
to end of execution time.
But simple declaration tells the single block of memory will be allocated.
2) Runtime Declaration: C language and many more language provide us the feature of
dynamic memory allocation by keywords "Malloc and Calloc."
So in this special block of memory is allocated in memory and their lifetime is also different.
3) Polymorphic operations: In most language, some special symbol like + to designate any one
of the several different operation which depends on type of data or argument is provided.
In this operation has some name like as we discussed + in this case operation symbol is said to
be overloaded because it does not designate one specific operation.
ML: Expands this concept with full polymorphism where function has one name but variety of
implementation depending on the types of arguments.
4) Type checking:- Declaration is basically for static type checking rather than dynamic.
Type checking means checking that each operation should receive proper number of arguments
and of proper data type.
Like
A=B*j+d;
* and - are basically int and float data types based operations and if any variable in
this A=B*j+d;Is of other than int and float then compiler will generate type error.
• It is done at runtime.
• It uses concept of type tag which is stored in each data objects that indicates the data type of
the object.
Example:
so Operation only be performed after type checking sequence in which type tag of each
argument is checked. If the types are not correct then error will be generated.
• Perl and Prolog follow basically dynamically type checking because data type of variables A+B
in this case may be changed during program execution.
• It is much flexible in designing programs or we ca say that the flexibility in program design.
• 1) difficult to debug: We need to check program execution paths for testing and in dynamic
type checking, program execution path for an operation is never checked.
• 2) extra storage: Dynamic type checking need extra storage to keep type information during
execution.
• 3) Seldom hardware support : As hardware seldom support the dynamic type checking so we
have to implement in software which reduces execution speed.
Type checking: Static Type Checking:
1) for each operation: The number, order, and data type, of its arguments.
Example-
A+B
In this data type, the value and name is specified and in further if checked value assigned
should match its data type.
1) compiler saves information:- if that type of data is according to the operation then compiler
saves that information for checking later operations which further no need of compilation.
2) checked execution paths: As static type checking includes all operations that appear in any
program statement, all possible execution paths are checked, and further testing for type error is
not needed. So no type tag on data objects at run-time are not required, and no dynamic checking
is needed.
Disadvantages of Static Type Checking
1) declarations
Strong Typing:
If we change detect all types of errors statically in a program, we can say that language is'
strongly typed'.
Example
f:s-> R
In this function f mail signature s generate output R and R is not outside the range of R
data type.
Type infer:- In this, like in ML, the language implementation will infer any missing type
information from other declared type.
Example:
Funarea(length,width)int= length*weight;
Funarea(length:int,width)= length*weight;
Funarea(length,width:int)= length*weight;
However:
Funarea(length,width)= length*weight;
Is invalid as it is now ambiguous as to that type of arguments. They could all be int or they
could be real.
Example:
Advantages of Coercion:
It basically free the programmer from the low level concerns upto some level. as Adding two
different data types i.e Real & int
Disadvantage of Coercion :
As programmer concerned to some level is reduced which may be that it hides some serious
errors which will not be easy to point out.
Assignment: A basic operation for changing the binding of a value to the data object. Languages
like C, LISP and many more
Assignment also returns a value, which is the data object containing a copy of the value
assigned.
In Pascal: dfont>
Assignment(=):integer1*integer2 ->integer3
With this action: Set the value contained in data object integer1 to be a copy of the value
contained in the data object integer2 and also create and return a new data object integer3,
containing a copy of a new value of integer2.
A=B
In this copying the value of variable B to variable A. i.e assign to the value L-Value of A the
R-Value of B.
In case of pointer
A=B:
In this A & B are pointers variables. If B is a pointer then B's R-value is the L- value of
some other data object. This assignment then means,
"Make the r-value of A refers to the same data object as the r-value of B"
Thus, the assignment A=B means " Assign a copy of the pointer stored in variable B
variable A".
Copy value:(pascal)
A:=B
Initialization is basically a step in which we just specify the name of variable and data object but
not yet assigned a value (i.e , an L-Value with no corresponding R-value).
• in this only block for storage is allocated.
• that block automatically may take some value in form of binary code.
• it is serious programming error to create an uninitialised error as it becomes difficult to
distinguish between original value or automatically filled value both of them are of bit patterns.
Numeric Data Types
but maximal and minimal values depends upon the what bit architecture of hardware is basically
and in some languages these values represented as defined constants.
1) Arithmetic operation:
It is of basically of two types:
A) Binary operation: BinOp: integer * integer-> integer
2) Relational Operations:
Signature is
Relop: Integer * integer-> Boolean
Where Relop maybe equal, not equal, less than, greater than,less-than-or-equal, greater-than-or-
equal Relational operation compare the value of a two arguments data value and return
Boolean (true or false value) data object as its result.
4) Bit operations:
In C, integers also plays the role of boolean values . Therefore additional bit operations are also
defined.
Signature: BinOp: Integer*integer-> integer
Operator (&) for and the bits together
Operator(|) for or the bits together
Operator(<<) for shift the bit among others.
Implementation of integer
Most often using the hardware-defined integer storage representation and a set of hardware
arithmetic and relational operations on integers.
Numeric Data Types : Sub Ranges of an Integer
A sub-range of an integer data type is a subtype of the integer data type and consists of a sequence
of integer values within some restricted range.
Declaration in Pascal
A:1....10
Declaration in Ada
1) smaller storage requirement :As a smaller range of values, a sub-range value can usually be
stored in fewer bits than a general integer value.
2) Better type checking: More precise type checking to be performed on the value assigned to
that variables.
Example if variable month is: Month: 1....12 then the assignment
Month:0 is invalid and can be detected at compile time.
If we use assignment Month: Month + 1
At runtime compiler check for range limit that should not be exceeded.
and
max:real*real->real
An Enumerated data type is a data type whose domain values are given in a list or ordered list
and who's only operations are equality and assignment.
or
An Enumeration is an ordered list of distinct values.
or
An Enumeration is a complete ordered listing of all items in a collection.
Pascal was first language which introduced enumeration. To make enumeration facility useful, a
programming language must provide a mechanism for declaring and defining the new data type
and for declaring variables whose value will come from the element of type.
It is assumed that this literals are distinct and does equality can be directly defined.
For example: A variable student class might have only 4 possible values representing fresher,
sophomore, junior and senior. Similarly, a variable StudentSex might have only two values
representing Male and Female.
Before the contact of enumeration the language like
Fortran or Cobol such variables is declared as integer type and distinct values are assigned. like
fresher=1 , sophomore=2, and so on
and male=0, female =1
Then translator manipulate values as integers.
That creates big problem like
Sophomore =1 and female=1
As both have some values can we apply integer based operation on it. As a point of view of
programmer it should not be but according to translator it can apply as they are of integer types.
Then languages such as C, article Pascal and Ada includes an Enumeration data type that allows
the programmer to define and manipulate such variables directly.
Specification of Enumeration
The programmers defined both the literal name to be used for the values and their ordering using
a declaration such as in pascal.
Type months=(jan,feb, mar, apr, june, jul, aug, sep, oct,nov,dec);
In C
enum studentclass{ fresh, soph, junior, senior};
enum studentsex {male, female};
In Pascal, C example can be written as
Here type definition introduces the type name class, which may be used wherever the primitive
type name such as integer might be used time.
It also introduces the literals of fresh, soph, junior, senior which may be used wherever a
language- defined literal such as "27" might be used. Thus we can write.
if studentclass= junior then.....
Instead of the less understandable
if studentclass= 3 then ...........
Which would be required if integer variables were used. Static compiler can find error such as
if student class= Male then
As Male is part of student class. Operations which we can perform-
• Relational operations(equal, less-than, greater-than,etc)
• Assignment
• Successor and Predecessor
Implementation of Enumeration
• Each value in the enumeration sequence is represented at run-time by one of the integers
0,1,2,..... as only a small set of values is involved and the values are never negative.
• In this integer representation is often shortened to omit the sign bit and use only enough bits for
the range of values required, as with the sub-range values.
• Only and maximum 2 bits are required to represent the senior=3 in memory because
3=11(binary)/ 2 bits only
In C, the programmer main override default and set any values desired for enumeration
values for example.
Enum class{ fresh=74, soph=89, junio=7, senior=28}
With this storage representation for enumeration types. Relational operations such as =,>, and
< may be implemented.
The Boolean data type is a data type, having two values(usually denoted true or false), intended
to represent the truth values of logic and Boolean algebra.
Specification: In Pascal and Ada, the Boolean data type is considered simply a language -
defined enumeration, viz;
Which both defines the names true and false for the values of the types and define ordering
false<true
and : Boolean*Boolean->Boolean(conjunction)
or : Boolean*Boolean->Boolean(inclusive disjunction )
• 1) a particular bit is used for the value(often the sign bit of the number representation), with '0=
false', '1=true', and the rest of the byte or word ignored, or
• 2) A zero value in the entire storage unit represent False, and any other non zero value
represents true
Scalar Data Types: Characters
Specification of Characters
A character data type provides data objects that have a single character as their value. Set of
values in character data type depends upon "Hardware and Operating System" like ASCII
character set. and ordering of the characters in this character set is called Collecting
Sequence And ordering given by the 'Relational Operations'.
• Relational operations
• Assignment and
• To test character for- Letter, Digit, Special Character.
Implementation of Character Data Type
Character data values are almost directly supported by the underlying hardware and operating
system because their use in input-output.
In C Character is declared
char a ; //declaration
a='A'; // initializing character data object with A
Where= A=65=1000001
Introduction to Syntax and Semantics
Syntax:
Like ordinary language English, programming languages have syntax. The Syntax of a
(programming) language is a set of rules that define what sequences of symbols are considered
to be valid expression (programs) in the language.
or
The Syntax of a programming language is what the program looks like.
Syntax provides significant information needed for understanding a program and provides much
needed information towards the translation of the source program into the object program.
X=Y+Z
XY+-
2+3*4 text will be interpreted this expression as having value 14 and not 20. That is,
expression is interpreted as if written (2+3)*4.
We can specify either interpretation, if we wish, by syntax and hence guide the translator into
generating the correct operations for evaluating this expression.
In a Statement
X=2.82 + 3.68
int v:{10};
In Pascal
v:array[0......9] of integer
Although both creates similar data objects at run time , their syntax is very different. To
Understand the meaning of declaration we need to know the semantics of both pascal and c for
such array declaration.
Another example
The semantics of this statement form is that when the current value of the Boolean exp. Is true,
the embedded statement is true.
A language, whether natural- like english, artificial like C, Java, is a set of strings of characters
from some alphabet. The strings of a language are called " Sentences or Statements". So Syntax
rules of a language specify which strings characters from the languages alphabet are in the
language.
Formal description of the syntax of programming languages, for simplicity sake , often do not
include descriptions of the lowest - 7 synthetic units. The small unit are called "LEXEMES".
Lexemes include numerical literals, operators and special words, among others. We can think of
program as strings of Lexemes rather than of characters.
Lexemes are partitioned into group - for example. The names of variables, methods, classes
and so forth in a programming language form a group called identifiers.
Each Lexemes group is represented by a name, or token. So, a token of a language is a category
of its Lexemes.
Lexemes Tokens
= equal-sign
index indentifier
2 int-literal
* mult-operator
count identifier
+ plus-operator
17 int-literals
; semicolon
Two distinct ways of defining a language
A) Language Recognizers:
• A recognition device reads input strings of the language and decide whether the input string
belong to the language.
Syntax Analyzers: Determine whether the given program or syntactically correct.
B) Language Generator:
English:
Alphabet: a,b,c,d,e,f,,,,z,A,B,C,....Z. Punctuations:,.''!""_/
Eat I. Chocolate*
correct He eat
Sentence:
Programming language
1. Alphabets: a,b,c,d,-----z,A,B.....Z
2. Digits: 0,1,2,3....9
3. Arithmetic symbol: *,-,/,+
4. Special symbols: ->.....#,@,!
Programming language in more technical way
header file: Math.h
statements : Tokens
Expression: Lexemes
Identifiers: Literals
These all need a grammar which can describe their syntax.
Grammar: Syntax and structure of a language. It is used in compiler creation. Describe the
syntax of a programming language.
Syntax: The rules governing the arrangement of words and phrases to create well formed
sentences .
Meta language:
• Language used to model the other language.
• Determine whether a series of characters is valid.
• Generate girlfriend statement.
• Breakdown a statement into constituent parts so it can be converted into Machine Language.
Token: Each and every smallest individuals units in programming language are known as token.
Type Example
Constants 10, 20
Operator +,*,-,/
Example
int main()
{
int x,y,total;
x=10,y=20;
total=x+y;
Where
main identifier
int keyword
x,y,total identifier
Man,{,},),(,int,x,y,total tokens
Parse Tree
The Hierarchical Syntactic Structure of Sentences of the Languages is called Parse Tree.
A=B*(A+C)
Ambiguity
A grammar that generates sentential form or which there are two or more distinct parse tree is
said to be ambiguous.
A=B+C*A it has a distinct parse Tree