Beispiel #1
0
def generate(input_str):
    ''' Parses an input string and returns another one
    containing the generated program skeleton.
    '''
    HEADER, L, ENDCODE = parser.parse(input_str)

    result = 'from skel import Grammar\n'

    if HEADER is not None:
        result += HEADER + '\n'

    result = result + """

def generate(self):
    
    """

    result = ''

    grammar = Grammar(Parser.START_SYMBOL)
    if L:
        for T in L:
            grammar.addRule(T)

    result += grammar.generate(Parser.START_SYMBOL)

    if ENDCODE is not None:
        result += ENDCODE + '\n'

    return result