Statement
27 February 2019 OSU CSE 1
Statement 27 February 2019 OSU CSE 1 BL Compiler Structure Code - - PowerPoint PPT Presentation
Statement 27 February 2019 OSU CSE 1 BL Compiler Structure Code Tokenizer Parser Generator string of string of abstract string of characters tokens program integers (source code) (words) (object code) A BL program consists
27 February 2019 OSU CSE 1
27 February 2019 OSU CSE 2
27 February 2019 OSU CSE 3
27 February 2019 OSU CSE 4
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 5
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 6
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 7
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 8
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 9
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 10
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 11
27 February 2019 OSU CSE 12
27 February 2019 OSU CSE 13
27 February 2019 OSU CSE 14
27 February 2019 OSU CSE 15
27 February 2019 OSU CSE 16
/** * The possible conditions for IF, IF_ELSE, * and WHILE statements. */ enum Condition { NEXT_IS_EMPTY, NEXT_IS_NOT_EMPTY, NEXT_IS_WALL, NEXT_IS_NOT_WALL, NEXT_IS_FRIEND, NEXT_IS_NOT_FRIEND, NEXT_IS_ENEMY, NEXT_IS_NOT_ENEMY, RANDOM, TRUE }
27 February 2019 OSU CSE 17
27 February 2019 OSU CSE 18
STATEMENT_LABEL is ( kind: Kind, test: Condition, call: IDENTIFIER) exemplar sl constraint [if sl.kind = BLOCK then sl.test and sl.call are irrelevant] and [if sl.kind = IF or sl.kind = IF_ELSE or sl.kind = WHILE then sl.call is irrelevant] and [if sl.kind = CALL then sl.test is irrelevant]
27 February 2019 OSU CSE 19
STATEMENT_LABEL is ( kind: Kind, test: Condition, call: IDENTIFIER) exemplar sl constraint [if sl.kind = BLOCK then sl.test and sl.call are irrelevant] and [if sl.kind = IF or sl.kind = IF_ELSE or sl.kind = WHILE then sl.call is irrelevant] and [if sl.kind = CALL then sl.test is irrelevant]
27 February 2019 OSU CSE 20
STATEMENT_MODEL is tree of STATEMENT_LABEL exemplar s constraint |s| > 0 and [BLOCK can have 0 or more children, but not another BLOCK as a child] and [IF must have exactly one BLOCK child] and [IF_ELSE must have exactly two BLOCK children] and [WHILE must have exactly one BLOCK child] and [CALL must have no children (must be a leaf)]
27 February 2019 OSU CSE 21
27 February 2019 OSU CSE 22
27 February 2019 OSU CSE 23
27 February 2019 OSU CSE 24
27 February 2019 OSU CSE 25
Statement s = new Statement1();
27 February 2019 OSU CSE 26
Statement s = new Statement1();
BLOCK
27 February 2019 OSU CSE 27
27 February 2019 OSU CSE 28
s =
BLOCK
27 February 2019 OSU CSE 29
s =
s = k = BLOCK
BLOCK BLOCK
[this is a BLOCK statement] and [s is not a BLOCK statement] and 0 <= pos <= [length of this BLOCK]
this = [#this with child #s inserted at position pos]
27 February 2019 OSU CSE 30
27 February 2019 OSU CSE 31
s = ns =
s.addToBlock(1, ns);
BLOCK
27 February 2019 OSU CSE 32
s = ns =
s.addToBlock(1, ns);
s = ns =
BLOCK BLOCK BLOCK
27 February 2019 OSU CSE 33
27 February 2019 OSU CSE 34
s = Statement ns = s.removeFromBlock(1);
BLOCK
27 February 2019 OSU CSE 35
s = Statement ns = s.removeFromBlock(1); s = ns =
BLOCK BLOCK
27 February 2019 OSU CSE 36
and only subtree the BLOCK s; the declaration notwithstanding, the dynamic type of s must be the same as the dynamic type of this.
[s is a BLOCK statement]
this = compose((IF, c, ?), <#s>)
27 February 2019 OSU CSE 37
27 February 2019 OSU CSE 38
s = ? ns =
s.assembleIf( RANDOM, ns);
27 February 2019 OSU CSE 39
s = ? ns =
s.assembleIf( RANDOM, ns);
s = ns =
IF RANDOM
BLOCK
returned as the value of the function, and its only subtree, the BLOCK statement s; the declaration notwithstanding, the dynamic type of s must be the same as the dynamic type of this.
[this is an IF statement]
#this = compose((IF, disassembleIf, ?), <s>)
27 February 2019 OSU CSE 40
27 February 2019 OSU CSE 41
s = ns = ? Condition c = s.disassembleIf(ns);
IF TRUE
27 February 2019 OSU CSE 42
s = ns = ? Condition c = s.disassembleIf(ns); ns = s = c = TRUE
IF TRUE
BLOCK
27 February 2019 OSU CSE 43
27 February 2019 OSU CSE 44
BLOCK IF condition WHILE condition CALL instruction
IF_ELSE condition
27 February 2019 OSU CSE 45
27 February 2019 OSU CSE 46
27 February 2019 OSU CSE 47
27 February 2019 OSU CSE 48
27 February 2019 OSU CSE 49
27 February 2019 OSU CSE 50