Abstract Syntax Trees

Abstract Syntax Trees

27 February 2019

OSU CSE

1

Abstract Syntax Tree

? An abstract syntax tree (AST) is a tree model of an entire program or a certain "program structure" (e.g., a statement or an expression in a Java program)

? An AST is "abstract" in the sense that some of the actual characters used in the "concrete" program text do not appear in the AST

27 February 2019

OSU CSE

2

Example: A Java Statement

while (k < 7) {

foo(k);

k++;

cond

}

<

while

body

call

incr

k

7

foo

k

27 February 2019

k

OSU CSE

3

Example: A Java Statement

while (k < 7) {

while

foo(k);

k++;

cond

body

}

<

You should see the connections! (This may not be an actual Jakva AST,7

however; it is just an illustration of the idea.)

call

incr

foo

k

k

27 February 2019

OSU CSE

4

Example: A BL Statement

WHILE true DO move infect

END WHILE

WHILE TRUE BLOCK

CALL move

CALL infect

27 February 2019

OSU CSE

5

Example: A BL Statement

WHILE true DO move infect

END WHILE

You should see the connections! (This is CaAnLL actual AST for BL; noticmeoivte uses a different "design".)

WHILE TRUE BLOCK

CALL infect

27 February 2019

OSU CSE

6

BL Statement Kinds

instruction IF test THEN IF test THEN WHILE test DO

BLOCK

BLOCK

BLOCK

END IF

ELSE

END WHILE

BLOCK END IF

27 February 2019

OSU CSE

7

BL Statement Kinds

instruction IF test THEN IF test THEN WHILE test DO

BLOCK

BLOCK

BLOCK

END IF

ELSE

Any sequence of zero or more statements nested in BLOCK an IF or WHILE construct

is called a block. END IF

END WHILE

27 February 2019

OSU CSE

8

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download