def setUp(self): self.src = source.StringSource() self.lex = lexer.Lexer(self.src) self.environment = env.Environment() self.parser = pars.Parser(self.lex, self.environment) self.program = interpreter.Interpreter(self.environment, self.parser) self.output = io.StringIO() sys.stdout = self.output
def main(): src = source.StreamSource() fo = open("ThirdExample", "r", encoding='utf-8', newline='\n') environment = env.Environment() src.set_data(fo) lex = lexer.Lexer(src) parser = pars.Parser(lex, environment) inter = interpreter.Interpreter(environment, parser) inter.interpret()
def get_few_defects(defects_list=[]): parser = pars.Parser('data/controlling_ml.csv') counter = 0 for row in parser.data: defects = row[parser.FIRST_DEFECT:] comp_array = ['0'] * (parser.NUMBER_OF_COLUMNS - parser.FIRST_DEFECT) for defect in defects_list: comp_array[defect - parser.FIRST_DEFECT] = '1' if defects == comp_array: counter += 1 print('Деффекты:') for i in defects_list: print(f'{i}) {parser.DEFECTS_NAMES[i - 10]}') print(counter)
import pars import scanner input_string = ''' { "$id": "https://example.com/person.schema.json" , "$shema": "http://json-schema.org/draft-07/schema#" } ''' print(input_string) scanner = scanner.Scanner(input_string) # print scanner.tokens parser = pars.Parser(scanner) parser.start()
def main(): content = "" # This variable will hold the contents of the source code path = os.getcwd() # Holds path this script was executed from # Holds the name of the file the user wants to compile try: fileName = sys.argv[1] except: print(' +---------------------------------------------+') print(' | Y# - v1.0 |') print(' | Developed By Yehan Wasura |') print(' +---------------------------------------------+') print(" Operating System : " + platform.system()) print(" Release : " + platform.release()) print(" Y# Version : v1.2.0") print(' +---------------------------------------------+') print( "Please use this command for run a program on this compiler : python3 main.py filename.yshp" ) return # Check if the file extension is correct if fileName[len(fileName) - 5:len(fileName)] != ".yshp": print( "[ERROR] File extension not recognised please make sure extension is '.yshp'" ) return # quit programme # Check to make sure that only one argument is passed try: print('[ERROR] Expected 1 argument found 2 (' + sys.argv[1] + ", " + sys.argv[2] + ')') return # quit programme except: pass # Open source code file and get it's content and save it to the 'contents' var try: with open(path + "/" + fileName, "r") as file: content = file.read() except: print('Cannot find "' + fileName + '"') # -------------------------------------- # LEXER # -------------------------------------- # Create an instance of the lexer class lex = lexer.Lexer() # Call lexer method to perform lexical analysis on code tokens = lex.tokenize(content) # -------------------------------------- # PARSER # -------------------------------------- # Create an instance of the parser class Parser = pars.Parser(tokens) # Call the parser method and pass in the tokens as arguments source_ast = Parser.parse(tokens) # -------------------------------------- # Object Generation # -------------------------------------- # Create an instance of the Object Generator (objgen) class object_generator = objgen.ObjectGenerator(source_ast) # Call the object definer to get python exec() string exec_string = object_generator.object_definer(False) # Execute the Y# code that has been transpiled to python code to get output print(' +---------------------------------------------+') print(' | Y# - v1.0 |') print(' | Developed By Yehan Wasura |') print(' +---------------------------------------------+') print(" Operating System : " + platform.system()) print(" Release : " + platform.release()) print(" Y# Version : v1.2.0") print(' +---------------------------------------------+\n\n') print("Filename: " + fileName + '\n\n') print('||||||||||||||||||||||| OUTPUT ||||||||||||||||||||||| \n') exec(exec_string) print('\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')
def setUp(self): self.src = source.StringSource() self.lex = lexer.Lexer(self.src) self.environment = env.Environment() self.parser = pars.Parser(self.lex, self.environment)