Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PPL 223 ( QUIZ 2) Syntax and Semantics

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is syntax in programming languages?

a)

A) The meaning of code

b)

B) The structure and rules of code

c)

C) The execution of code

d)

D) The data types used in code

2.

What is the main difference between syntax and semantics?

a)

A) Syntax is the structure, and semantics is the meaning

b)

B) Syntax is the meaning, and semantics is the structure

c)

C) Syntax is the execution, and semantics is the data type

d)

D) Syntax and semantics are the same

3.

Which formal method is used to define the syntax of programming languages?

a)

A) Denotational semantics

b)

B) Context-free grammars

c)

C) Operational semantics

d)

D) Axiomatic semantics

4.

What is the role of Backus-Naur Form (BNF) in programming languages?

a)

A) To provide a formal way to define syntax

b)

B) To execute the code

c)

C) To define the semantics

d)

D) To manage memory

5.

In the expression 5 + (3 - 1) * 4, which operation is performed first according to syntax rules?

a)

A) Addition

b)

B) Subtraction

c)

C) Multiplication

d)

D) Parentheses

6.

What is parsing in the context of programming languages?

a)

A) Executing code

b)

B) Analyzing a sequence of tokens to determine its grammatical structure

c)

C) Defining variables

d)

D) Managing memory

7.

Which of the following is a type of parsing technique?

a)

A) Top-down parsing

b)

B) Bottom-up parsing

c)

C) Both A and B

d)

D) Neither A nor B

8.

What does operational semantics describe?

a)

A) How a program executes on a machine

b)

B) The mathematical meaning of code

c)

C) The logical assertions of code

d)

D) The syntax of code

9.

Which type of semantics maps programming constructs to mathematical objects?

a)

A) Operational semantics

b)

B) Denotational semantics

c)

C) Axiomatic semantics

d)

D) None of the above

10.

What is the purpose of axiomatic semantics?

a)

A) To describe how a program executes

b)

B) To map constructs to mathematical objects

c)

C) To use logical assertions to describe behavior

d)

D) To define syntax rules

11.

What is a parse tree?

a)

A) A structure representing the syntactic structure of code

b)

B) A tree that grows in a database

c)

C) A method to execute code

d)

D) A way to define variables

12.

Which parsing technique starts from the highest-level rule and works down to the tokens?

a)

A) Bottom-up parsing

b)

B) Top-down parsing

c)

C) Both A and B

d)

D) Neither A nor B

13.

What does a context-free grammar consist of?

a)

A) A set of variables and rules

b)

B) A set of tokens and memory locations

c)

C) A set of functions and procedures

d)

D) A set of objects and classes

14.

In the parse tree for 3 + (4 * 2), what is the root node?

a)

A) 3

b)

B) +

c)

C) *

d)

D) 4

15.

What is the purpose of Backus-Naur Form (BNF)?

a)

A) To define a formal grammar for the syntax of programming languages

b)

B) To write executable code

c)

C) To manage memory

d)

D) To define semantic rules

16.

Which semantic type would you use to prove the correctness of an algorithm?

a)

A) Operational semantics

b)

B) Denotational semantics

c)

C) Axiomatic semantics

d)

D) Context-free grammar

17.

Which of the following represents a valid statement about parsing?

a)

A) Parsing is the process of executing code.

b)

B) Parsing is used to break down code into its grammatical components.

c)

C) Parsing is the process of managing memory.

d)

D) Parsing is used to define variables.

18.

What is the purpose of semantics in programming languages?

a)

A) To define the structure of code

b)

B) To give meaning to syntactically correct code

c)

C) To execute code

d)

D) To manage memory

19.

In operational semantics, how is the execution of a loop construct described?

a)

A) By using logical assertions

b)

B) By mapping to mathematical objects

c)

C) By providing rules for the repeated execution of the loop body

d)

D) By defining syntax rules

20.

What is the main goal of denotational semantics?

a)

A) To provide a set of rules for executing code

b)

B) To map programming constructs to mathematical objects

c)

C) To use logical assertions to describe program behavior

d)

D) To manage memory