Automatic Synthesis of State Machines from Trace Diagrams