def create_scanner(self,fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # define some pattern constructs letter = plex.Range("AZaz") #letter digit = plex.Range("09") #digit identifier = letter+plex.Rep(letter|digit) #always starts with letter b_var = plex.Str('true','TRUE','True','t','T','false','FALSE','False','f','F','0','1') #t,T,f,F after full words for correct matching assign = plex.Str('=') parenthesis = plex.Str('(',')') keyword = plex.Str('print') operator = plex.Str('not','and','or') space=plex.Rep1(plex.Any(' \n\t')) # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples lexicon = plex.Lexicon([ (operator,plex.TEXT), (parenthesis,plex.TEXT), (assign,plex.TEXT), (space,plex.IGNORE), (keyword, plex.TEXT), #keywords and b_vars before identifiers for correct matching (b_var,'b_var'), (identifier,'id'), ]) # create and store the scanner object self.scanner = plex.Scanner(lexicon,fp) # get initial lookahead self.la,self.val = self.next_token()
def create_scanner(self, fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ self.run_values = [] self.vars = {} # define some pattern constructs letter = plex.Range('azAZ') digit = plex.Range('09') id = letter + plex.Rep(letter | digit) bool_values = plex.NoCase(plex.Str('true', 'false', 't', 'f', '0', '1')) operator = plex.Str('and', 'or', 'not', '(', ')', '=') space = plex.Any(' \t\n') print_keyword = plex.Str('print') # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples lexicon = plex.Lexicon([ (print_keyword, plex.TEXT), (operator, plex.TEXT), (bool_values, 'BOOL'), (id, 'IDENTIFIER'), (space, plex.IGNORE), ]) # create and store the scanner object self.scanner = plex.Scanner(lexicon, fp) # get initial lookahead self.la, self.val = self.next_token()
def create_scanner(self, fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # define some pattern constructs letter = plex.Range("AZaz") digit = plex.Range("09") binary = plex.Rep1(plex.Any("01")) id = letter + plex.Rep(letter | digit) operator = plex.Str("and", "or", "xor", "=") paren = plex.Any("()") space = plex.Any(" \t\n") comment = plex.Str("{") + plex.Rep(plex.AnyBut("}")) + plex.Str("}") keyword = plex.NoCase(plex.Str("print")) # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples lexicon = plex.Lexicon([(binary, "binary"), (operator, plex.TEXT), (keyword, plex.TEXT), (paren, plex.TEXT), (space | comment, plex.IGNORE), (id, 'id')]) # create and store the scanner object self.scanner = plex.Scanner(lexicon, fp) # get initial lookahead self.la, self.val = self.next_token()
def create_scanner(self,fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ letter = plex.Range("azAZ") digit = plex.Range("09") ops = plex.Str("not", "and", "or") kprint = plex.Str("print") true = plex.NoCase(plex.Str("true", "t", "1")) false = plex.NoCase(plex.Str("false", "f", "0")) identifier = letter + plex.Rep(letter | digit) assign = plex.Str("=") space = plex.Rep1(plex.Any(" \n\t")) par = plex.Any("()") lexicon = plex.Lexicon([ (kprint, "PRINT"), (ops, plex.TEXT), (true, "TRUE"), (false, "FALSE"), (identifier, "ID"), (assign, "="), (par, plex.TEXT), (space, plex.IGNORE) ]) self.scanner = plex.Scanner(lexicon, fp) self.la, self.val = self.next_token()
def create_scanner(self, fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # define some pattern constructs notop = plex.Str("not") andop = plex.Str("and") orop = plex.Str("or") true = plex.NoCase(plex.Str("true", "t", "1")) false = plex.NoCase(plex.Str("false", "f", "0")) equals = plex.Str("=") letter = plex.Range("AZaz") digit = plex.Range("09") variable = letter + plex.Rep(letter | digit) parenthesis = plex.Str("(", ")") keyword = plex.Str("print") space = plex.Any(" \t\n") # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples lexicon = plex.Lexicon([(notop, plex.TEXT), (andop, plex.TEXT), (orop, plex.TEXT), (true, 'TRUE'), (false, 'FALSE'), (equals, plex.TEXT), (parenthesis, plex.TEXT), (space, plex.IGNORE), (keyword, plex.TEXT), (variable, 'VAR')]) # create and store the scanner object self.scanner = plex.Scanner(lexicon, fp) # get initial lookahead self.la, self.val = self.next_token()
def __init__(self): space = plex.Any(" \n\t") schar = plex.Str('(', ')') letter = plex.Range('azAZ') digit = plex.Range('09') bit = plex.Range('01') bits = plex.Rep1(bit) name = letter + plex.Rep(letter | digit) keyword = plex.Str('print', 'PRINT') operator = plex.Str('AND', 'OR', 'XOR', '=') self.st = {} self.lexicon = plex.Lexicon([(operator, plex.TEXT), (keyword, 'PRINT'), (schar, plex.TEXT), (name, 'IDENTIFIER'), (bits, 'bit_token'), (space, plex.IGNORE)])
def create_scanner(self,fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # define some pattern constructs letter = plex.Range("AZaz") digit = plex.Range("09") keywords = plex.Str("print", "not", "and", "or") true_keyword = plex.NoCase(plex.Str("true", "t", "1")) false_keyword = plex.NoCase(plex.Str("false", "f", "0")) identifier = letter + plex.Rep(letter | digit) assign = plex.Str("=") parenthesis = plex.Str("(", ")") space = plex.Rep1(plex.Any(" \n\t"))
def __init__(self): YEET = plex.Any(" \n\t") Parentheseis = plex.Str('(', ')') letter = plex.Range('azAZ') digit = plex.Range('09') name = letter + plex.Rep(letter | digit) bitch = plex.Range('01') ban = plex.Rep1(bitch) keyword = plex.Str('print', 'PRINT') operator = plex.Str('AND', 'OR', 'XOR', '=') self.lexicon = plex.Lexicon([(operator, plex.TEXT), (ban, 'BIT_TOKEN'), (keyword, 'PRINT'), (Parentheseis, plex.TEXT), (name, 'IDENTIFIER'), (YEET, plex.IGNORE)])
def __init__(self): space = plex.Any(" \n\t") par = plex.Str('(', ')') letter = plex.Range('azAZ') digit = plex.Range('09') name = letter + plex.Rep(letter | digit) bit = plex.Range('01') bits = plex.Rep1(bit) keyword = plex.Str('print', 'PRINT') space = plex.Any(" \n\t") operator = plex.Str('^', '&', '|', '=') self.st = {} self.lexicon = plex.Lexicon([(operator, plex.TEXT), (bits, 'BIT_TOKEN'), (keyword, 'PRINT'), (par, plex.TEXT), (name, 'IDENTIFIER'), (space, plex.IGNORE)])
def __init__(self): letter = plex.Range('azAZ') and_operatorop = plex.Str('and') or_operatorop = plex.Str('or') xor_operatorop = plex.Str('xor') num = plex.Range('09') digit = plex.Range('01') IDsymbol = letter + plex.Rep(letter | num) space = plex.Any(' \n\t') Keyword = plex.Str('print', 'PRINT') binary = plex.Rep1(digit) equals = plex.Str('=') parethensys1 = plex.Str('(') parethensys2 = plex.Str(')') self.varList = {} self.lexicon = plex.Lexicon([ (Keyword, 'PRINT'), (and_operatorop, plex.TEXT), (or_operatorop, plex.TEXT), (xor_operatorop, plex.TEXT), (IDsymbol, 'IDENTIFIER'), #name = letter + plex.Rep(letter|digit) (binary, 'BIN_NUM'), (equals, '='), (parethensys1, '('), (parethensys2, ')'), (space, plex.IGNORE) ])
def create_scanner(self, fp): and_operator = plex.Str('and') or_operator = plex.Str('or') xor_operator = plex.Str('xor') assignment_operator = plex.Str('=') print_operator = plex.Str('print') space = plex.Any(' \t\n') parenthesis_opened = plex.Str('(') parenthesis_closed = plex.Str(')') binary = plex.Rep1(plex.Range('01')) digit = plex.Range('09') letter = plex.Range('AZaz') variable = letter + plex.Rep(letter|digit) lexicon = plex.Lexicon([ (and_operator, 'and'), (or_operator, 'or'), (xor_operator, 'xor'), (assignment_operator, '='), (print_operator, 'print'), (space, plex.IGNORE), (parenthesis_opened, '('), (parenthesis_closed, ')'), (binary, 'bin'), (variable, 'var') ]) self.scanner = plex.Scanner(lexicon, fp)
def __init__(self): AND_OP = plex.Str('and') OR_OP = plex.Str('or') XOR_OP = plex.Str('xor') ASSIGN_OP = plex.Str('=') OPEN_PAR = plex.Str('(') CLOSE_PAR = plex.Str(')') PRINT_TOKEN = plex.Str('print') DIGIT = plex.Range('09') BINARY = plex.Range('01') LETTER = plex.Range('AZaz') B_NUM = plex.Rep1(BINARY) SPACE = plex.Any(' \n\t') ID_TOKEN = LETTER + plex.Rep(LETTER|DIGIT) self.LEXICON = plex.Lexicon([ (AND_OP, 'and'), (OR_OP, 'or'), (XOR_OP, 'xor'), (SPACE, plex.IGNORE), (ASSIGN_OP, '='), (PRINT_TOKEN, 'print'), (OPEN_PAR, '('), (CLOSE_PAR, ')'), (ID_TOKEN, 'id'), (B_NUM, 'b_num') ]) self.ST = {}
def __init__(self): letter = plex.Range('azAz') digit = plex.Range('09') ID = letter + plex.Rep(letter | digit) BINARY = plex.Rep1(plex.Range('01')) AND = plex.Str('and') OR = plex.Str('or') XOR = plex.Str('xor') ASSIGN = plex.Str('=') LEFTPAR = plex.Str('(') RIGHTPAR = plex.Str(')') PRINT = plex.NoCase(plex.Str('PRINT')) self.lexicon = plex.Lexicon([(AND, 'AND'), (OR, 'OR'), (XOR, 'XOR'), (ASSIGN, 'ASSIGN'), (LEFTPAR, 'LEFTPAR'), (RIGHTPAR, 'RIGHTPAR'), (PRINT, 'PRINT'), (BINARY, 'BINARY'), (ID, 'ID'), (plex.Rep1(plex.Any(" \t\n")), plex.IGNORE)]) self.stack = {}
def __init__(self): letter = plex.Range('azAZ') digit = plex.Range('01') num = plex.Range('09') name = letter + plex.Rep(letter | num) space = plex.Any(' \n\t') Keyword = plex.Str('print', 'PRINT') bin = plex.Rep1(digit) ando = plex.Str('and') oro = plex.Str('or') xoro = plex.Str('xor') equals = plex.Str('=') parethensys1 = plex.Str('(') parethensys2 = plex.Str(')') self.st = {} self.lexicon = plex.Lexicon([ (Keyword, 'PRINT_TOKEN'), (ando, plex.TEXT), (oro, plex.TEXT), (xoro, plex.TEXT), (name, 'ID_TOKEN'), #name = letter + plex.Rep(letter|digit) (bin, 'BIN_NUM'), (equals, '='), (parethensys1, '('), (parethensys2, ')'), (space, plex.IGNORE) ])
def create_scanner(self, fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # define some pattern constructs letter = plex.Range("AZaz") demicalDigit = plex.Range("09") binaryDigit = plex.Range('01') equals = plex.Str('=') parentheniL = plex.Str('(') parentheniR = plex.Str(')') binaryNumber = plex.Rep1(binaryDigit) name = letter + plex.Rep(letter | demicalDigit) space = plex.Any(" \t\n") print_key = plex.Str('print') andOperator = plex.Str('and') orOperator = plex.Str('or') xorOperator = plex.Str('xor') self.variableList = {} # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples lexicon = plex.Lexicon([(space, plex.IGNORE), (parentheniL, plex.TEXT), (parentheniR, plex.TEXT), (equals, plex.TEXT), (print_key, 'print'), (binaryNumber, 'number'), (andOperator, plex.TEXT), (orOperator, plex.TEXT), (xorOperator, plex.TEXT), (name, 'id')]) # create and store the scanner object self.scanner = plex.Scanner(lexicon, fp) # get initial lookahead self.la, self.text = self.next_token()
def __init__(self): letter = plex.Range('azAZ') digit = plex.Range('01') digitvalue = plex.Rep1(digit) #oi times twn metavlitwn a kai b name = letter + plex.Rep(letter|digit) space = plex.Any(' \n\t') Keyword = plex.Str('print','PRINT') equals = plex.Str( '=') leftparen = plex.Str('(') rightparen = plex.Str(')') and_token = plex.Str('&') or_token = plex.Str('|') xor_token = plex.Str('^') self.lexicon = plex.Lexicon([ (Keyword, 'PRINT_TOKEN'), (name, 'ID_TOKEN'), (equals, 'EQUALS_TOKEN'), (leftparen, '('), (rightparen, ')'), (and_token, '&'), (or_token, '|'), (xor_token, '^'), (digitvalue, 'digitvalue'), (space, plex.IGNORE) ])
def __init__(self): DIGIT = plex.Range("09") LETTER = plex.Range('azAZ') NUMBER = plex.Rep1(plex.Any('01')) IDENTIFIER_TOKEN_OPERATOR = LETTER + plex.Rep(LETTER|DIGIT) XOR_OPERATOR = plex.Str("^") OR_OPERATOR = plex.Str("|") AND_OPERATOR = plex.Str("&") EQUALITY_OPERATOR = plex.Str("=") OPEN_PARENTHESES = plex.Str("(") CLOSE_PARENTHESES = plex.Str(")") PRINT_TOKEN = plex.Str("print") SPACE = plex.Any(" \n\t") self.LEXICON = plex.Lexicon([(SPACE, plex.IGNORE), (NUMBER, "NUMBER"), (XOR_OPERATOR, "^"), (OR_OPERATOR, "|"), (AND_OPERATOR, "&"), (EQUALITY_OPERATOR, "="), (PRINT_TOKEN, "PRINT"), (OPEN_PARENTHESES, "("), (IDENTIFIER_TOKEN_OPERATOR, "IDENTIFIER"), (CLOSE_PARENTHESES, ")")]) self.VARS = {}
def create_scanner(self, fp): # define some pattern constructs decimal = plex.Range('09') binary = plex.Range('01') letter = plex.Range('azAZ') equals = plex.Str('=') lPar = plex.Str('(') rPar = plex.Str(')') space = plex.Any(' \n\t') binary = plex.Rep1(binaryDigit) name = letter + plex.Rep(letter | decimalDigit) printOp = plex.Str('print') andOp = plex.Str('and') orOp = plex.Str('or') xorOp = plex.Str('xor') # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples self.lexicon = plex.Lexicon([(space, plex.IGNORE), (lPar, plex.TEXT), (rPar, plex.TEXT), (equals, plex.TEXT), (printOp, plex.TEXT), (binary, 'BINARY_NUM'), (andOp, plex.TEXT), (orOp, plex.TEXT), (xorOp, plex.TEXT), (name, 'id')]) # create and store the scanner object self.scanner = plex.Scanner(self.lexicon, fp) # get initial lookahead self.la, self.val = self.next_token()
def __init__(self): DIGIT = plex.Range("09") BINARY_DIGIT = plex.Range("01") LETTER = plex.Range('azAZ') BINARY_TOKEN = plex.Rep1(BINARY_DIGIT) IDENTIFIER_TOKEN_OPERATOR = LETTER + plex.Rep(LETTER | DIGIT) AND_TOKEN = plex.Str("and") OR_TOKEN = plex.Str("or") XOR_TOKEN = plex.Str("xor") EQUALITY_OPERATOR = plex.Str("=") OPEN_PARENTHESES = plex.Str("(") CLOSE_PARENTHESES = plex.Str(")") PRINT_TOKEN = plex.Str("print") SPACE = plex.Any(" \n\t") self.LEXICON = plex.Lexicon([(SPACE, plex.IGNORE), (BINARY_TOKEN, "binary"), (AND_TOKEN, "and"), (OR_TOKEN, "or"), (XOR_TOKEN, "xor"), (EQUALITY_OPERATOR, "="), (PRINT_TOKEN, "print"), (OPEN_PARENTHESES, "("), (CLOSE_PARENTHESES, ")"), (IDENTIFIER_TOKEN_OPERATOR, "id")]) self.ST = {}
def create_scanner(self, fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # Define some pattern constructs and_op = plex.Str('and') or_op = plex.Str('or') xor_op = plex.Str('xor') assignment_op = plex.Str('=') print_op = plex.Str('print') space = plex.Any(' \t\n') parenthesis_open = plex.Str('(') parenthesis_close = plex.Str(')') binary = plex.Rep1(plex.Range('01')) digit = plex.Range('09') letter = plex.Range('AZaz') variable = letter + plex.Rep(letter | digit) # The scanner lexicon - constructor argument is # a list of (pattern, action) tuples lexicon = plex.Lexicon([(and_op, 'and'), (or_op, 'or'), (xor_op, 'xor'), (assignment_op, '='), (print_op, 'print'), (space, plex.IGNORE), (parenthesis_open, '('), (parenthesis_close, ')'), (binary, 'bin'), (variable, 'id')]) # Create and store the scanner object, and get initial lookahead self.scanner = plex.Scanner(lexicon, fp) self.la, self.val = self.next_token() # Create a dictionary to store variables from file self.vars = {}
def __init__(self): keyword = plex.Str('print', 'PRINT') letter = plex.Range('azAZ') num = plex.Range('09') space = plex.Any(" \n\t") name = letter + plex.Rep(letter | num) digit = plex.Range('01') binary = plex.Rep1(digit) eq = plex.Str('=') paren1 = plex.Str('(') paren2 = plex.Str(')') and_op = plex.Str('and') or_op = plex.Str('or') xor_op = plex.Str('xor') self.st = {} self.lexicon = plex.Lexicon([ (binary, 'BINARY_TOKEN'), (keyword, 'PRINT'), (name, 'IDENTIFIER'), (space, plex.IGNORE), (and_op, plex.TEXT), (or_op, plex.TEXT), (xor_op, plex.TEXT), (eq, '='), (paren1, '('), (paren2, ')'), ])
def __init__(self): #ta pattern pou xreiazomaste string = plex.Range("azAZ") token_equals = plex.Str('=') token_leftParenthesis = plex.Str('(') token_rightParenthesis = plex.Str(')') number = plex.Range('01') space = plex.Any(' \n\t') token_xor = plex.Str('xor') token_or = plex.Str('or') token_and = plex.Str('and') identifier = string + plex.Rep(string | number) binary = plex.Rep1(number) token_print = plex.Str('print') #to scanner leksiko self.lexicon = plex.Lexicon([ (token_xor, 'xor'), (token_or, 'or'), (token_and, 'and'), (token_leftParenthesis, '('), (token_rightParenthesis, ')'), (token_equals, '='), (binary, 'binary'), (token_print, 'print'), (identifier, 'id'), (space, plex.IGNORE), ])
def __init__(self): letter = plex.Range("Azaz") digit = plex.Range("09") binary = plex.Range("01") id_token= letter + plex.Rep(letter|digit) and_token = plex.Str('and') or_token= plex.Str('or') xor = plex.Str('xor') equals = plex.Str('=') open_parenthesis= plex.Str('(') close_parenthesis= plex.Str(')') print_token = plex.Str('print') space = plex.Any(' \n\t') binary_num = Rep1(binary) # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples self.LEXICON = plex.Lexicon([(space, plex.IGNORE), (and_token, 'and'), (or_token, 'or'), (xor, 'xor'), (equals, '='), (print_token, 'print'), (open_parenthesis, '('), (close_parenthesis, ')'), (binary_num, 'binary_num'), (id_token, 'id')])
def create_scanner(self, fp): letter = plex.Range("azAZ") digit = plex.Range("09") name = letter + plex.Rep(letter | digit) space = plex.Rep1(plex.Any(" \n\t")) keyword = plex.Str("print") operator_and_or = plex.Str("and", "or") operator_not = plex.Str("not") operator_equal = plex.Str("=") operator_parenth = plex.Str("(", ")") operator_false = plex.NoCase(plex.Str( '0', 'f', 'false')) #den exei shmasia an einai kefalaia h mikra operator_true = plex.NoCase(plex.Str( '1', 't', 'true')) # den exei shmasia an einai kefalaia h mikra lexicon = plex.Lexicon([(keyword, plex.TEXT), (operator_and_or, plex.TEXT), (operator_not, plex.TEXT), (operator_false, "FALSE"), (operator_true, "TRUE"), (name, "IDENTIFIER"), (space, plex.IGNORE), (operator_parenth, plex.TEXT), (operator_equal, plex.TEXT)]) self.scanner = plex.Scanner(lexicon, fp) self.la, self.val = self.next_token()
def __init__(self): space = plex.Any(' \n\t') symbol_xor = plex.Str('xor') symbol_or = plex.Str('or') symbol_and = plex.Str('and') letter = plex.Range("azAZ") symbol_equals = plex.Str('=') symbol_leftParenthesis = plex.Str('(') symbol_rightParenthesis = plex.Str(')') digit = plex.Range('01') identifier = letter + plex.Rep(letter | digit) binary_number = plex.Rep1(digit) keyword_print = plex.Str('print') self.lexicon = plex.Lexicon([ (symbol_leftParenthesis, '('), (symbol_rightParenthesis, ')'), (symbol_xor, 'xor'), (symbol_or, 'or'), (symbol_and, 'and'), (symbol_equals, '='), (binary_number, 'binary'), (keyword_print, 'print'), (identifier, 'id'), (space, plex.IGNORE), ]) self.st = {}
def __init__(self): dong = plex.Str('(', ')') letter = plex.Range('azAZ') digit = plex.Range('09') digit1 = plex.Range('01') bit = plex.Rep1(digit1) name = letter + plex.Rep(letter | digit) keyword = plex.Str('print', 'PRINT') space = plex.Any(" \n\t") operator = plex.Str('XOR', 'AND', 'OR', '=') self.lexicon = plex.Lexicon([ (operator, plex.TEXT), (bit, 'BIT_TOKEN'), (keyword, 'PRINT'), (dong, plex.TEXT), (name, 'IDENTIFIER'), (space, plex.IGNORE), ])
def create_scanner(self, fp): letter = plex.Range("azAZ") digit = plex.Range("09") keywords = plex.Str("print", "not", "and", "or") true_keyword = plex.NoCase(plex.Str("true", "t", "1")) false_keyword = plex.NoCase(plex.Str("false", "f", "0")) identifier = letter + plex.Rep(letter | digit) assign = plex.Str("=") parenthesis = plex.Str("(", ")") space = plex.Rep1(plex.Any(" \n\t")) lexicon = plex.Lexicon([(keywords, plex.TEXT), (true_keyword, "True"), (false_keyword, "False"), (identifier, "IDENTIFIER"), (assign, "="), (parenthesis, plex.TEXT), (space, plex.IGNORE)]) self.scanner = plex.Scanner(lexicon, fp) self.la, self.val = self.next_token()
def create_scanner(self, fp): """ Creates a plex scanner for a particular grammar to operate on file object fp. """ # define some pattern constructs letter = plex.Range("AZaz") digit = plex.Range("09") identifier = letter + plex.Rep(letter | digit) telestes = plex.Str('=') parenthesi = plex.Any('()') keyword = plex.Str('print') AndOrOp = plex.Str('and', 'or') NotOp = plex.Str('not') BoolTrue = plex.NoCase(plex.Str('true', 't', '1')) BoolFalse = plex.NoCase(plex.Str('false', 'f', '0')) space = plex.Any(" \t\n") # the scanner lexicon - constructor argument is a list of (pattern,action ) tuples lexicon = plex.Lexicon([(keyword, plex.TEXT), (space, plex.IGNORE), (NotOp, plex.TEXT), (AndOrOp, plex.TEXT), (BoolTrue, 'TRUE'), (BoolFalse, 'FALSE'), (parenthesi, plex.TEXT), (identifier, 'IDENTIFIER'), (telestes, plex.TEXT)]) # create and store the scanner object self.scanner = plex.Scanner(lexicon, fp) # get initial lookahead self.la, self.val = self.next_token()
def create_scanner(self, fp): logvalTrue = plex.NoCase(plex.Str('true', 't', '1')) logvalFalse = plex.NoCase(plex.Str('false', 'f', '0')) digit = plex.Range('09') letter = plex.Range('azAZ') identifier = letter + plex.Rep(letter | digit) keyword = plex.Str('print') Moperator = plex.Str('and', 'or') Soperator = plex.Str('not') equals = plex.Str("=") parenthesis = plex.Any("()") space = plex.Rep1(plex.Any(' \n\t')) lexicon = plex.Lexicon([(keyword, plex.TEXT), (Moperator, plex.TEXT), (Soperator, plex.TEXT), (logvalTrue, 'LOGVALTRUE'), (logvalFalse, 'LOGVALFALSE'), (identifier, 'IDENTIFIER'), (space, plex.IGNORE), (Moperator, plex.TEXT), (Soperator, plex.TEXT), (parenthesis, plex.TEXT), (equals, plex.TEXT)]) self.scanner = plex.Scanner(lexicon, fp) self.la, self.val = self.next_token()
def create_scanner(self, fp): letter = plex.Range('azAZ') #ena gramma digit = plex.Range('09') #ena pshfio telesths3 = plex.Str('=') parenthesis = plex.Str('(', ')') name = letter + plex.Rep( letter | digit) #gramma kai perissotera pshfia h grammata boolFalse = plex.NoCase(plex.Str('false', 'f', '0')) boolTrue = plex.NoCase(plex.Str('true', 't', '1')) space = plex.Rep1(plex.Any(' \n\t')) keyword = plex.Str('print', 'not', 'or', 'and') simple_comment = plex.Str('//') + plex.Rep( plex.AnyBut('\n')) #sbhnei ta sxolia kati pou den einai new line lexicon = plex.Lexicon([ (keyword, plex.TEXT), (boolTrue, 'true'), (boolFalse, 'false'), (name, 'IDENTIFIER'), (space, plex.IGNORE), (telesths3, '='), (parenthesis, plex.TEXT), (simple_comment, plex.IGNORE) #kanei ignore ta comment ]) self.scanner = plex.Scanner(lexicon, fp) self.la, self.val = self.next_token()