Пример #1
0
def translate(data, outfile=sys.stdout):
    """Entry point to the OMPC translator.
    This function functions as a preprocessor. There are aspect of M-language
    that are difficult (cause conflicts) to be solved by a parser. It is also 
    much faster to implement some of the syntax by very simple checks.
    The preprocessor
     - combines continuations '...' (single line is submitted to the compiler)
     - removes comments, but makes it possible to add them later
     -
    """
    global _lineno, _last_line
    from re import sub, finditer
    com = ''
    d = []
    _lineno = 1
    for x in data.split('\n'):
        # preprocess, the returned values are strip of whitespace, and
        # the optional coment is returned
        s, com = _ompc_preprocess(x)
        # if s is None a continuation was requested, submit the next line
        if s is None:
            continue

        _last_line = s
        yacc.myparse(s + '\n', outfile)

        # FIXME do something about the comments
        if s.strip():
            _print3000(_gettabs()[:-4] + com.strip(), file=outfile)
        else:
            _print3000(com, file=outfile)
        com = ''
        _lineno += 1
Пример #2
0
def translate(data, outfile=sys.stdout):
    """Entry point to the OMPC translator.
    This function functions as a preprocessor. There are aspect of M-language
    that are difficult (cause conflicts) to be solved by a parser. It is also 
    much faster to implement some of the syntax by very simple checks.
    The preprocessor
     - combines continuations '...' (single line is submitted to the compiler)
     - removes comments, but makes it possible to add them later
     -
    """
    global _lineno, _last_line
    from re import sub, finditer

    com = ""
    d = []
    _lineno = 1
    for x in data.split("\n"):
        # preprocess, the returned values are strip of whitespace, and
        # the optional coment is returned
        s, com = _ompc_preprocess(x)
        # if s is None a continuation was requested, submit the next line
        if s is None:
            continue

        _last_line = s
        yacc.myparse(s + "\n", outfile)

        # FIXME do something about the comments
        if s.strip():
            _print3000(_gettabs()[:-4] + com.strip(), file=outfile)
        else:
            _print3000(com, file=outfile)
        com = ""
        _lineno += 1
Пример #3
0
    _lineno = 1
    while 1:
        try:
            s = raw_input('ompc> ') + '\n'
        except EOFError:
            break

        # preprocess, the returned values are strip of whitespace, and
        # the optional coment is returned
        s, com = _ompc_preprocess(s)
        # if s is None a continuation was requested, submit the next line
        if s is None:
            continue

        # if s is empty don't do anything
        if not s:
            continue

        if LEXDEBUG:
            # Tokenize
            lex.input(s)
            while 1:
                tok = lex.token()
                if not tok: break  # No more input
                print tok
                print _errors
                _errors = []

        yacc.myparse(s)
        print
Пример #4
0
    while 1:
        try:
            s = raw_input("ompc> ") + "\n"
        except EOFError:
            break

        # preprocess, the returned values are strip of whitespace, and
        # the optional coment is returned
        s, com = _ompc_preprocess(s)
        # if s is None a continuation was requested, submit the next line
        if s is None:
            continue

        # if s is empty don't do anything
        if not s:
            continue

        if LEXDEBUG:
            # Tokenize
            lex.input(s)
            while 1:
                tok = lex.token()
                if not tok:
                    break  # No more input
                print tok
                print _errors
                _errors = []

        yacc.myparse(s)
        print