예제 #1
0
파일: Parser.py 프로젝트: kpsmith/Compiler
 def function_declaration(self):
     """
     Expanding Rule 16:
     FunctionDeclaration -> FunctionHeading ";" Block ";"
     """
     if self.t_type() == 'MP_FUNCTION':
         old_func_name = self.cur_func_name
         func_sym_table = SymbolTable(self.cur_symbol_table)
         func_sym_table.create()
         self.cur_symbol_table = func_sym_table
         self.sem_analyzer.sym_table = self.cur_symbol_table
         Parser.print_tree('16')
         self.function_heading()
         func_sym_table.name = self.cur_func_name
         self.match(';')
         self.block()
         self.match(';')
         self.print_symbol_table("Function",func_sym_table)
         self.cur_func_name = old_func_name
         self.cur_symbol_table = self.cur_symbol_table.parent_table
         func_sym_table.destroy()
     else:
         self.error('MP_FUNCTION')
예제 #2
0
파일: Parser.py 프로젝트: kpsmith/Compiler
 def procedure_declaration(self):
     """
     Expanding Rule 15:
     ProcedureDeclaration -> ProcedureHeading ";" Block ";"
     """
     if self.t_type() == 'MP_PROCEDURE':
         old_proc_name = self.cur_proc_name
         proc_sym_table = SymbolTable(self.cur_symbol_table)
         proc_sym_table.create()
         self.cur_symbol_table = proc_sym_table
         self.sem_analyzer.sym_table = self.cur_symbol_table
         Parser.print_tree('15')
         self.procedure_heading()
         proc_sym_table.name = self.cur_proc_name
         self.match(';')
         self.block()
         self.match(';')
         self.print_symbol_table("Procedure", proc_sym_table)
         self.cur_symbol_table = self.cur_symbol_table.parent_table
         self.cur_proc_name = old_proc_name
         proc_sym_table.destroy()
     else:
         self.error('MP_PROCEDURE')