From 175c07781a970035eb6b74ebd175e892faac8a7a Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Tue, 22 Oct 2019 12:54:04 +0100 Subject: [PATCH] First cut at include files. --- bin/sixtypical | 6 ++---- src/sixtypical/parser.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bin/sixtypical b/bin/sixtypical index c22f0b0..2a3f20d 100755 --- a/bin/sixtypical +++ b/bin/sixtypical @@ -17,7 +17,7 @@ from tempfile import NamedTemporaryFile import traceback from sixtypical.symtab import SymbolTable -from sixtypical.parser import Parser, merge_programs +from sixtypical.parser import Parser, load_program, merge_programs from sixtypical.analyzer import Analyzer from sixtypical.callgraph import construct_callgraph, prune_unreachable_routines from sixtypical.outputter import outputter_class_for @@ -30,11 +30,9 @@ def process_input_files(filenames, options): programs = [] for filename in options.filenames: - text = open(filename).read() - parser = Parser(symtab, text, filename) + program = load_program(filename, symtab) if options.debug: print(symtab) - program = parser.program() programs.append(program) if options.parse_only: diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index 64b6631..8be9c46 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -96,6 +96,12 @@ class Parser(object): def program(self): defns = [] routines = [] + includes = [] + while self.scanner.consume('include'): + filename = self.scanner.token + self.scanner.scan() + program = load_program(filename, self.symtab) + includes.append(program) while self.scanner.on('typedef', 'const'): if self.scanner.on('typedef'): self.typedef() @@ -470,6 +476,13 @@ class Parser(object): # - - - - +def load_program(filename, symtab): + text = open(filename).read() + parser = Parser(symtab, text, filename) + program = parser.program() + return program + + def merge_programs(programs): """Assumes that the programs do not have any conflicts."""