1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

11
1 Grammar Refactoring December 13 th , 2013 Erik Fredericks

Transcript of 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

Page 1: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

1

Grammar RefactoringDecember 13th, 2013Erik Fredericks

Page 2: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

2

Overview

• Nodal Recursion• Grammar refactoring

Page 3: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

3

Nodal Recursion

• Recall issue with standard BNF recursion in EpochX

• decl_list : decl • | decl_list decl

Page 4: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

4

Nodal Recursion

• Each node in EpochX has a set amount of allowable children

• Nodes with multiple arities handled with “SEQ2,” “SEQ3,” “SEQ4” …• No “SEQN”

SEQ3

Page 5: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

5

Nodal Recursion

• Extended EpochX framework to accept any number of child nodes at time of node creation

• On a node-by-node basis

• COMPOSITION root node can accept an n-amount of child nodes

• INT2CHAR can only accept a single child node

Page 6: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

6

Refactored Grammar

• New flexibility allows standard recursion as defined in BNF grammar

• E.g. <xform1>, <xform2>, <xform3>,…

• With this in mind, we re-examined the grammar

Page 7: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

7

Refactored Grammar

• New top-level approach• Instead of defining pre- and post-conditions in the

grammar…• WRAPPER : input_xform, input_xform, target, output_xform

• Pre- and post-conditions are now fully defined outside of the grammar

• Previously used outside as part of fitness evaluation

• Lessens burden on developer using this approach

Page 8: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

8

Refactored Grammar

composition : statements ;

statements : statements, statement | statement ;

statement : transform | operation | module_invocation ;…

Page 9: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

9

Condition Scanning

• Previously, available variables (pre-conditions) defined outside of grammar and dynamically inserted into a single <var> production• Prior to evolution

• var : numbers-in | bubbleSort … ;

Page 10: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

10

Condition Scanning

• Variables now given extra information in production rules• Removes ability for invalid transforms to form

var : int | float_array | void_array | target_method;int : size;float_array : numbers-in;void_array : numbers-out;target_method : bubbleSort;

• Other data types point to root of transforms

Page 11: 1 Grammar Refactoring December 13 th, 2013 Erik Fredericks.

11

New Intermediate Example

• Convert 2D to 1D array for passing into sorting method• Two possible methods

• FLATTEN array• Use FOREACH loop and COPY

• Current status• Rewarding invocation of target module with 2D array as

input parameter• Always converges to solution [baseline test]

• COMPOSITION(MODULE(bubble_sort,numbers_2D_array))