留学生考试辅导 Computer and Information Science Engineering

Computer and Information Science Engineering

::= program begin end (1)
::= | (2)

Copyright By PowCoder代写 加微信 powcoder

::= | (3)
::= int ; (4)
::= | , (5)
::= |||| (6)
::= = ; (7)
::= if then end; (8)
|if then else end;
::= while loop end; (9)
::= read ; (10)
::= write ; (11)

BNF for Core

::= |! (12)
| [ && ] | [ or ]
::= ( ) (13)
::= |+| (14)
::= | * (15)
::= | | () (16)
::= != | == | < | > | <= | >= (17)
::= … as defined by RE … (18)
::= … as defined by RE … (19)

-5 is not a legal ; fix?
Knowledge check:
Problem with the semantics of : What is the problem?
How do you fix it?
BNF for Core (contd.)

PT for a simple program
program int X;
begin X = 25; write X; end
Knowledge check:
Some of these nodes do not contain any useful information
Which ones and why?


Concrete vs. Abstract Parse Trees


program int x; begin X = 25; output X; end

program int X;
begin X = 25; write X; end
Abstract Parse Tree
Knowledge Check:
What if we had declared Y instead of X?
What if we had exchanged the two statements?


BNF is Context-Free: Cannot specify such things as:
Only id’s declared in the may appear in
The type of the , as declared in the , must match its usage in the
Such context-sensitive conditions are still syntactic conditions and can and must be checked before execution
BNF cannot specify run-time requirements:
These must be checked during execution
Knowledge Check:
In languages such as Python, even type-checking has got to be done during execution. Why?

Limitations of BNF

Slide 16 notes
How to do this in pure BNF? Using ε it is easy.
Without it, the number of productions increases quite a bit.
But using ε can cause problems for compilers. In homeworks, exams, etc. you may use it unless I say otherwise.

Relation to book: So far, mostly chapter 1; and 3.1., 3.2, 3.3; rest of chapter 3 not inclded.
We will move to chapter 4; that will lead us to the project.

A lot of this should be familiar from 321 and 625. But going over it again should make it easier to see how it relates to PLs and lang. implementations. The project also has some relation to 560.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com