160 likes | 300 Views
Update Meeting August 7 th , 2013. Agenda. Overview of technical progress Grammar-based implementation. Overview of Technical Progress. Reviewed methods of parsing grammars in C++ Open source frameworks Stream parsing Etc. Grammar Parser. Preferred Flex and Bison
E N D
Agenda • Overview of technical progress • Grammar-based implementation
Overview of Technical Progress • Reviewed methods of parsing grammars in C++ • Open source frameworks • Stream parsing • Etc.
Grammar Parser • Preferred Flex and Bison • Flex for interpreting the incoming grammar • Bison for generating tokens • Both are open-source and have available Windows ports • Both are standalone executables that can be built into Visual Studio’s custom build rules
Framework • Began primitive implementation within OpenBEAGLE • Continually had issues with run-time errors in customizing examples • Simple conversion of Even Parity example from Boolean to String
Framework • Looked back to EpochX for inspiration in designing a set of primitives for a grammar • Rolled back to version 1.33.3 • Custom grammar rules implemented completely differently • Most of all, it “works” • Nodal evaluation easily triggered
Framework • To continue to make progress, I moved ahead with the EpochX implementation • Customized C BNF grammar • Composition strategies • High-level role assignments to sub-trees
Grammar Output • Sample output • CODE_INJECTION( CHAR0() bubbleSort LPARAN RPARAN) • Inject the following code: • char bubbleSort(); • BUFFER( FUNCTION_POINTER( CHAR(bubbleSort), numbers, int*)) • Create a function pointer under the ‘Buffer’ role: • char (*sort)(int*) = bubbleSort; • Buffer = sort(numbers);
Grammar-Based Implementation public static final String GRAMMAR_FRAGMENT = "<program> ::= <node>\n" + "<node> ::= <strategy> | <role> | <terminal>\n“ + "<role> ::= BUFFER ( <node> )\n + "<strategy> ::= WRAPPER( <type> , <node> , <terminal> ) " + "| FUNCTION_POINTER( <type> , <node> , <terminal> )" + "| CODE_INJECTION( <code> )\n" + "<type> ::= INT( <terminal> ) | DOUBLE( <terminal> ) " + "| FLOAT( <terminal> ) | CHAR( <terminal> )\n" + "<type0> ::= INT0() | DOUBLE0() | FLOAT0() | CHAR0()\n" + "<code> ::= <method>\n" + "<method> ::= <type0> <terminal> LPARAN RPARAN\n" + "<terminal> ::= ";
Grammar-Based Implementation public static final String GRAMMAR_FRAGMENT = "<program> ::= <node>\n" + "<node> ::= <strategy> | <role> | <terminal>\n“ + "<role> ::= BUFFER ( <node> )\n + "<strategy> ::= WRAPPER( <type> , <node> , <terminal> ) " + "| FUNCTION_POINTER( <type> , <node> , <terminal> )" + "| CODE_INJECTION( <code> )\n" + "<type> ::= INT( <terminal> ) | DOUBLE( <terminal> ) " + "| FLOAT( <terminal> ) | CHAR( <terminal> )\n" + "<type0> ::= INT0() | DOUBLE0() | FLOAT0() | CHAR0()\n" + "<code> ::= <method>\n" + "<method> ::= <type0> <terminal> LPARAN RPARAN\n" + "<terminal> ::= "; High level roles
Grammar-Based Implementation public static final String GRAMMAR_FRAGMENT = "<program> ::= <node>\n" + "<node> ::= <strategy> | <role> | <terminal>\n“ + "<role> ::= BUFFER ( <node> )\n + "<strategy> ::= WRAPPER( <type> , <node> , <terminal> ) " + "| FUNCTION_POINTER( <type> , <node> , <terminal> )" + "| CODE_INJECTION( <code> )\n" + "<type> ::= INT( <terminal> ) | DOUBLE( <terminal> ) " + "| FLOAT( <terminal> ) | CHAR( <terminal> )\n" + "<type0> ::= INT0() | DOUBLE0() | FLOAT0() | CHAR0()\n" + "<code> ::= <method>\n" + "<method> ::= <type0> <terminal> LPARAN RPARAN\n" + "<terminal> ::= "; Strategy definitions
Grammar-Based Implementation public static final String GRAMMAR_FRAGMENT = "<program> ::= <node>\n" + "<node> ::= <strategy> | <role> | <terminal>\n“ + "<role> ::= BUFFER ( <node> )\n + "<strategy> ::= WRAPPER( <type> , <node> , <terminal> ) " + "| FUNCTION_POINTER( <type> , <node> , <terminal> )" + "| CODE_INJECTION( <code> )\n" + "<type> ::= INT( <terminal> ) | DOUBLE( <terminal> ) " + "| FLOAT( <terminal> ) | CHAR( <terminal> )\n" + "<type0> ::= INT0() | DOUBLE0() | FLOAT0() | CHAR0()\n" + "<code> ::= <method>\n" + "<method> ::= <type0> <terminal> LPARAN RPARAN\n" + "<terminal> ::= "; C types (with and without subtree)
Grammar-Based Implementation public static final String GRAMMAR_FRAGMENT = "<program> ::= <node>\n" + "<node> ::= <strategy> | <role> | <terminal>\n“ + "<role> ::= BUFFER ( <node> )\n + "<strategy> ::= WRAPPER( <type> , <node> , <terminal> ) " + "| FUNCTION_POINTER( <type> , <node> , <terminal> )" + "| CODE_INJECTION( <code> )\n" + "<type> ::= INT( <terminal> ) | DOUBLE( <terminal> ) " + "| FLOAT( <terminal> ) | CHAR( <terminal> )\n" + "<type0> ::= INT0() | DOUBLE0() | FLOAT0() | CHAR0()\n" + "<code> ::= <method>\n" + "<method> ::= <type0> <terminal> LPARAN RPARAN\n" + "<terminal> ::= "; Start of C BNF grammar
Grammar-Based Implementation public static final String GRAMMAR_FRAGMENT = "<program> ::= <node>\n" + "<node> ::= <strategy> | <role> | <terminal>\n“ + "<role> ::= BUFFER ( <node> )\n + "<strategy> ::= WRAPPER( <type> , <node> , <terminal> ) " + "| FUNCTION_POINTER( <type> , <node> , <terminal> )" + "| CODE_INJECTION( <code> )\n" + "<type> ::= INT( <terminal> ) | DOUBLE( <terminal> ) " + "| FLOAT( <terminal> ) | CHAR( <terminal> )\n" + "<type0> ::= INT0() | DOUBLE0() | FLOAT0() | CHAR0()\n" + "<code> ::= <method>\n" + "<method> ::= <type0> <terminal> LPARAN RPARAN\n" + "<terminal> ::= "; Terminal nodes (target method, parameters, etc.)
Grammar-Based Implementation • Implementation • Java classes provided for each non-terminal node that requires evaluation • Strategies • Types • Etc. • Tree shape determined by grammar constraints • Fitness to be determined by SW-engineering metrics • (e.g. Lines of code, complexity, number of transformations, etc.)
Next Steps • Continue grammar implementation • C BNF, identify ‘canned transformations’ • Int.toString() could be represented by a known set of C statements • Define fitness function • Impact of code • Fan-in / fan-out • Others…