.- HTMLPP source for Perl, Code Generation, and State Machines talk .- give at Wellington Perl Mongers meeting, 3 May 2000. .- .- By Ewen McNeill, iMatix Corporation (NZ) Limited. .- .define document Perl, Code Generation and State Machines .define iMatix http://www.imatix.com/ .define HTMLPP http://www.imatix.com/html/htmlpp/ .define Otto http://www.imatix.com/pub/tools/otto.zip .define SrcDoc http://www.imatix.com/pub/tools/srcdoc.zip .define Libero http://www.imatix.com/html/libero/ .define talkurl http://www.imatix.co.nz/talks/codegen/ .define BASE index .- .include prelude.def .page

Code Generation, State Machines, and Perl

Presented to the Wellington Perl Mongers Group

 

 

Ewen McNeill
3 May 2000 .page Overview .H1 This presentation covers . H2 Code generation . H2 State machines . H2 ... and even a little Perl .page What is code generation? .H1 Code generation . H2 Makes "common cases" a template . H2 Lets you concentrate on the details . H2 Write more with less effort . H2 A blessing for the Larry Wall "lazy programmer" . H2 You're soaking in it (more on that in a moment) .page How does code generation work?

.page Soaking in code generation .H1 This presentation was generated using $(*HTMLPP) . H2 A Perl based, Open Source, tool to generate HTML . H3 The document template . H3 Raw document information . H3 Example run of HTMLPP .page What are state machines? .H1 State machines . H2 A Computer Science formalism . H2 A model for problems with distinct stages and actions . H2 Useful for . H3 Parsing computer languages . H3 Writing communications systems . H3 Modelling business processes .page Implementing state machines .H1 Several ways to implement state machines . H2 Explicit tests of states in the code . H3 eg, a big case statement . H2 Manually written state tables . H2 Code generation .page State machines and code generation .H1 Code generation and state machines work well together . H2 Automates writing out the state logic . H2 Automates tracking and changing states . H2 Can include automatic exception processing . H2 Allows high level description of states .page Libero: a state machine code generator .H1 $(*Libero) by $(*iMatix) . H2 An Open Source state machine code generator . H2 Combines text description of states and template code . H3 eg, htmlpp.l . H2 Generates state machine code in many languages . H3 Perl (template) (generated code example) . H3 C/C++ (template) . H3 Java (template) .page Libero: Putting it all together .H1 Libero . H2 Generates Perl code to track and change states . H2 Each state contains (eg htmlpp.l) . H3 Details for a series of events . H3 Functions to call when receiving that event in that state . H3 A new state to move to after the event . H2 You fill code for the functions, and indicate next event . H2 Your code is basically event based . H2 The generated code does the rest .page Perl and Libero .H1 $(*iMatix) have a number of Perl programs built using Libero . H2 $(*HTMLPP): A HTML generator . H2 $(*Otto): A build script generator . H2 $(*SrcDoc): Generate documentation from your source files .page That's all folks .H1 Summary . H2 Code generation: write boring repetitive code once . H2 State machines: a useful abstraction . H2 State machines and code generation work well together . H2 You can use both with Perl with ease .H1 Questions?