def filter(input, filename = '<internal>', state = 'INITIAL'): ''' Filter the input string thought the preprocessor. result is appended to OUTPUT global str ''' CURRENT_FILE.append(filename) LEXER.input(input, filename) LEXER.lex.begin(state) parser.parse(lexer = LEXER, debug = OPTIONS.Debug.value > 2) CURRENT_FILE.pop()
def main(argv): global OUTPUT, ID_TABLE, ENABLED ENABLED = True OUTPUT = '' if argv: CURRENT_FILE.append(argv[0]) else: CURRENT_FILE.append('<stdout>') if OPTIONS.Sinclair.value: OUTPUT += include_once(search_filename('sinclair.bas', 0), 0) if len(OUTPUT) and OUTPUT[-1] != '\n': OUTPUT += '\n' parser.parse(lexer = LEXER, debug = OPTIONS.Debug.value > 2) CURRENT_FILE.pop() OUTPUT += LEXER.include(CURRENT_FILE[-1]) if len(OUTPUT) and OUTPUT[-1] != '\n': OUTPUT += '\n' parser.parse(lexer = LEXER, debug = OPTIONS.Debug.value > 2) CURRENT_FILE.pop()
def include_file(filename, lineno): ''' Writes down that "filename" was included at the current file, at line <lineno> ''' if filename not in INCLUDED.keys(): INCLUDED[filename] = [] if len(CURRENT_FILE) > 0: INCLUDED[filename].append((CURRENT_FILE[-1], lineno)) # Added from wich file, line CURRENT_FILE.append(filename) return LEXER.include(filename)
def p_include_once_ok(p): ''' include_file : include_once NEWLINE program _ENDFILE_ ''' p[0] = [p[1]] + p[3] + [p[4]] CURRENT_FILE.pop() # Remove top of the stack