0% found this document useful (0 votes)
56 views7 pages

CS 430 Assignment#1-First-22-23

The document contains an assignment for a programming languages concepts course. It includes a parse tree and leftmost derivation for an example program, questions about parse trees, an explanation of operational semantics and weakest preconditions, and a final answer involving variables and expressions.

Uploaded by

Muhannad Bedaiwi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views7 pages

CS 430 Assignment#1-First-22-23

The document contains an assignment for a programming languages concepts course. It includes a parse tree and leftmost derivation for an example program, questions about parse trees, an explanation of operational semantics and weakest preconditions, and a final answer involving variables and expressions.

Uploaded by

Muhannad Bedaiwi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Princess Nourah Bint Abdul Rahman University

College of Computer and Information Sciences

Department of Computer Science

1443 - 1444 (First semester)

CS 430 – Programming Languages Concepts

Assignment 1 “individually”

Deadline Monday 12-9-2022

Student ID: 441004567


-----------------------------------------, Section: 10C3
------------------------------

Student Name:
MAX Grade
01min
-------------------------------------------------------------------------------------------------

Obtained grade Comments

Q1 2

Q2 2

Q3 2

Q4 2

Q5 2

Total 10

Question #1:

Using the following grammar:

assign> → <id> = <expr>

<id> → A | B | C
<expr> → <expr> + <term>

| <term>

<term> → <term> * <factor>

| <factor>

<factor> → ( <expr> )

| <id>

Show a parse tree and a leftmost derivation for the following statement:

A = B * (C * (A + B))

CS430

Parse free

assigns

id expr

A term

term factors

factor expr

id term

B term factors

factor expr

id expr t terms

g term factors

factor id

id B

Leftmost derivations

aids exprs

assign

A expr

A term

A term factor

A factor factor

A id factor

A B factor

A B expr

A B term

A B term factor

A B factor factor

A B Kids factory

A B C factor

A B C expr

A B c expr term D

A B c term term D

A B C factor term D

A B C kid term D

A B C At term D

A B C At factor D

A B C At id D

A B C At BD
3

(i) 2 parse trees, because there are tow derivations that lead
to the same sentence.


S S


Sts S s

a s s sts a

a a a a

(ii) 5 parse trees, because there are three derivations that lead
to the same sentence.

S S S S

Sts Sts s s sis sis

a sis

s s a sis sis s s a sts a

as s s sa a aa a Sts a

s s a

a a a a a a a a
(iii) Just 1 parse tree, because there is just one operation.

Sts

S a

Sts

a s

Sts
4

a a

program begin semi list end

same list esque simp

c id exp r

sqmy

Lid CA I BI C

exp r id t I id

Operational semantics

t 1
oop f f

n n 1

if n 0 goto loop

OUT3 so sooooo

Weakest precondition

a 3 O

a 3

2 6 1 3

2 b 2

b I

Finale Answer

bet a 2 6 1 a 3

a 3 b a 3 bro

You might also like