You are on page 1of 6

PUNJAB UNIVERSITY OF INFORMATION

AND TECHNOLOGY

Name: Marriam Nisar


Roll no: BCSF17M529
Subject: Compiler Construction
Submitted to: Sir Imran Javed
Topic:
Expression Statement
It refers to anything that can be evaluated In contrast, statements do not return
to produce a value. Naturally, we can anything. Instead, they perform an action
think of any data by itself as an which introduces some form of state
expression because data always
evaluates to itself.
Expressions don’t depend on state The interesting thing about statements is that
they depend on order.
Example : Example :
4+2 1. x=5
"Hi!" 2. if (y) { ... }
3. while (true) { ... }
4. return s

Website 1:
https://therenegadecoder.com/code/the-difference-between-statements-and-
expressions/

Expression Statement
It refers to anything that can be evaluated In contrast, statements do not
to produce a value. Naturally, we can return anything. Instead, they
think of any data by itself as an
perform an action which introduces
expression because data always
evaluates to itself. some form of state
Expressions don’t depend on state The interesting thing about statements is
that they depend on order.
Example : Example :
4+2 1. x=5
"Hi!" 2. if (y) { ... }
3. while (true) { ... }
4. return s

Website 2:
https://blog.kotlin-academy.com/kotlin-programmer-dictionary-statement-vs-
expression
Expression Statement
An expression in a programming In computer programming, a
language is a combination of one statement is the smallest
or more explicit values, constants, standalone element of an
variables, operators and functions
that the programming language
imperative programming
interprets and computes to language that expresses some
produce another value. action to be carried out.
Example : Example :
sumOf(1, 2*3) val bestUser = users.filter
{ it.passing }
.maxBy { it.meanScore }
println("${bestUser.name} $
{bestUser.surname}")

Expression Statement
An expression evaluates to some A statement performs some action
value
An expression can be part of a A statement is never part of an
statement: expression.
Example : Example :
"Hello World" print("Hello World")

1000 sleep(1000)

5 + 3 return 55

a * 5 > b if (done) exit()

x_flag & mask throw SomeError()

Website 1:
http According to Noam Chomosky, there are four types of grammars − Type 0, Type 1,
Types of grammar:
According to Noam Chomosky, there are four types of grammars − Type 0,
Type 1, Type 2, and Type 3.
Type - 0 Grammar :
Type-0 grammars generate recursively enumerable languages.
The productions have no restrictions. They are any phase
structure grammar including all formal grammars.

Example
S → ACaB
Bc → acB
CB → DB
aD → Db
Type - 1 Grammar
Type-1 grammars generate context-sensitive languages. The
productions must be in the form
αAβ→αγβ
where A ∈ N (Non-terminal)
and α, β, γ ∈ (Strings of terminals and non-terminals)
The strings α and β may be empty, but γ must be non-empty.
The rule S → ε is allowed if S does not appear on the right side
of any rule

Example
AB → AbBc
A → bcA
B → b
Type - 2 Grammar
Type-2 grammars generate context-free languages.
The productions must be in the form A → γ
where A ∈ (Non terminal)
and γ ∈ (String of terminals and non-terminals).

Example
S → X a
X → a
X → aX
X → abc
X → ε

Type - 3 Grammar
Type-3 grammars generate regular languages. Type-3
grammars must have a single non-terminal on the left-hand side
and a right-hand side consisting of a single terminal or single
terminal followed by a single non-terminal.
The productions must be in the form X → a or X → aY
where X, Y ∈ N (Non terminal)
and a ∈ T (Terminal)
The rule S → ε is allowed if S does not appear on the right side
of any rule.

Example
X → ε
X → a | aY
Y → b

You might also like