PL Lec 2 Syntax and Semantics
PL Lec 2 Syntax and Semantics
The coding language first has to translate its source code into assembly
language, a super low-level language that uses words and numbers to
represent binary patterns. Depending on the language, this may be done with
an interpreter (where the program is translated line-by-line), or with a compiler
(where the program is translated as a whole).
The coding language then sends off the assembly code to the computer’s
assembler, which converts it into the machine language that the computer can
understand and execute directly as binary code.
Lexical Analysis
Alphabets
Any finite set of symbols {0,1} is a set of
binary alphabets,
{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} is a set of
Hexadecimal alphabets, {a-z, A-Z} is a set of
English language alphabets.
Strings
Any finite sequence of alphabets is called a
string. Length of the string is the total
number of occurrence of alphabets, e.g., the
length of the string tutorialspoint is 14 and is
denoted by |tutorialspoint| = 14. A string
having no alphabets, i.e. a string of zero
length is known as an empty string and is
denoted by ε (epsilon).
Special Symbol
A typical high-level language contains the following
symbols:-
Arithmetic Symbols Addition(+), Subtraction(-), Modulo(%),
Multiplication(*), Division(/)
Punctuation Comma(,), Semicolon(;), Dot(.), Arrow(-
>)
Assignment =
Special Assignment +=, /=, *=, -=
N , T , P ,S
E->E+E
-> id + E
-> id + E * E
-> id + id * E
-> id + id * id
Input = id + id * id
Right Most Derivation
E -> E + E
E -> E * E
E -> id
E->E+E
-> E + E * E
-> E + E * id
-> E + id * id
-> id + id * id
Input 1: id + id * id / id
Left Most Derivation: