/flowchart-to-code

A Toolkit for Converting Flowcharts to Pseudocode

Primary LanguageC++

Flowchart2Code

Convert Flowchart into Pseudo-Code.

This code:

  • Can generate code containing BREAK, CONTINUE, RETURN, WHILE, DOWHILE, IF, ELIF.
  • Support complex flowcharts, such as the Condition nodes with more than 2 outgoing edges.

Examples

output1

def twoSum(self, nums, target):
    Set n to the length of the array num. 
    Set i as the index of the array, the initial value is 0
    While (I is less than n?):
        Define j as the subscript of the array, and the initial value of j is i+1
        While (I is less than n?):
            if (The sum of nums[i] and nums[j] is equal to the target):
                output:  Return their array indices
                return
            Increment j
        Increment i
    output:  Returns an empty list
    return

output2

def function():
    while true:
        if (a):
            8
            break
        elif (b):
            9
            break
        elif (c):
            return
        2
        if (e):
            break
        if (d):
            4
            continue
        elif (g):
            5
        elif (f):
            6
        else:
        if (h):
            continue
        else:
            return
    10
    return

QuickStart

#include "AvtivityCodeGen.h"

int main()
{
    AvtivityCodeGen cg;
    cg.FC2Pseudocode("examples\\input1.txt", "examples\\output1.txt");
    return 0;
}

Method

We used the method propesed by Wang et al. to generate pseudo-code from the flowchart:

  • Step 1: Find out the loop and selection in the flowchart. Flowchart is a combination of two basic structures: selection and loop. Wang et al. found that the flowchart can be seen as a directed graph, in which each loop forms a strongly connected sub-graph. They used this method to find all the loop structures in the flowchart. Then, the structures led by the remaining Condition nodes are selection structures.

  • Step 2: Identify the nodes (e.g. while) and edges (e.g. continue, break, return) associated with the special structures in the loop. We identified these structures based on their characteristics. For example: 1) The True branch of the continue node will point to the while node. 2) The True branch of the break and return nodes will jump out of the loop.

  • Step 3: Identify the scoping of Selection. In the first step, we have found the Condition nodes related to selection. In this step, we need to find where the 2 branches of the selection meet.

  • Step 4: Generate pseudo-code. To generate the pseudo-code, the model will rereank the nodes according to the structure of the flowchart and convert it into the pseudo-code.

Acknowledgements

Work done under the guidance of Lin Li and Deyu Zhou during the internship in Nanjing Origin Information Technology Company and PAttern Learning and Mining(PALM) Lab of Southeast University.

References

The method was proposed in the paper "Research on and implementation of the algorithm from the program flowchart to the code", and implemented in the paper "Code Generation From Flowcharts with Texts: A Benchmark Dataset and An Approach". If you found this code useful, please cite the following papers: