def main(): for line in open('test.txt', 'r'): #line = "(a>b)||(c<d)&&(e!=f);\n" line = line[:len(line) - 1] #skip the /n print("Original lex:{line}".format(**locals())) statement = line lex = Lex(statement) parse = Parse(lex)
def __init__(self): lex = Lex() self.tokens = lex.tokens #Definição das precedencias self.precedence = ( ('left', 'COMPARACAO', 'MAIOR_IGUAL', 'MAIOR', 'MENOR_IGUAL', 'MENOR'), ('left', 'MAIS', 'MENOS'), ('left', 'MULT', 'DIVIDE'), ) arq = open(sys.argv[1], 'r', encoding='utf-8') data = arq.read() parser = yacc.yacc(debug=False, module=self, optimize=False) self.ps = parser.parse(data)
import os import RPi.GPIO as GPIO from lex import Lex from subprocess import run import hotword basedir = os.path.dirname(os.path.abspath(__file__)) pin = 18 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(pin, GPIO.OUT) lex = Lex() stop_recording = False def record_and_post(): GPIO.output(18, GPIO.HIGH) response = lex.post_content() GPIO.output(18, GPIO.LOW) state = lex.play_response(response) print('State:', state) if state == 'Fulfilled': detect() elif state != 'Failed': record_and_post() else: stop_recording = True detect()
from parse import Parser_LL1 from lex import Lex for line in open('test.txt','r'): #skip the \n statement = line[:len(line)-1] print("Original lex:{statement}".format(**locals())) statement += '%'#add the special end of line symbol lex = Lex(statement) print("Parsed lex:", end = "") parser = Parser_LL1(lex)
from lex import Lex as Lex import os as os lex_un = Lex() # Processes argument with extra carat char with no reason def process_in(in_file): if (in_file.startswith("^")): in_file_correct = in_file[1:] return in_file_correct else: return in_file # Creates the file name of the output file # Outputs are in Java def gen_name(in_file): base = os.path.basename(in_file) ind = base.index(".blsp") name = base[0:1].capitalize() + base[1:ind] + ".java" return name # High complexity Interpreter, someone help def parse_file(in_file): file_in = process_in(in_file) if (is_bsp(file_in) == False): return 1 genned_name = gen_name(file_in) with open(file_in, 'r') as file:
from lex import Lex from parser import Parser # take input mathematical equation from command line input = input("Enter the equation to calculate:") # passing the input expression to Lexer to convert into tokens lexer = Lex().get_lexer() tokens = lexer.lex(input) # Calling parser module to parse the expression and perform calculations parseGen = Parser() parseGen.parse() parser = parseGen.get_parser() parser.parse(tokens).eval()
import readline if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete") import crash_on_ipy crash_on_ipy.init() from lex import Lex from parser import LRParser from util import colorful from runtime import ParseHandler, Env LEX = Lex() LEX.keyword = ['lambda', '[', ']', 'let', 'define', 'if', 'cond', 'or', 'and', '(', ')', '$T', '$F'] LEX.read_lex('regular_lex.txt') LEX.compile(grammar_type="regular") # lex.read_lex('regex_lex.txt') # lex.compile() print(colorful('词法编译完成...', 'Yellow')) PARSER = LRParser() PARSER.read_grammar('schepy_grammar.txt') PARSER.compile() print(colorful('语法编译完成...', 'Yellow')) GLOBAL_ENV = Env.std_env() while True: try: HANDLER = ParseHandler()