comparison python/ppci/c3/lexer.py @ 315:084cccaa5deb

Added console and screen
author Windel Bouwman
date Sat, 21 Dec 2013 10:03:01 +0100
parents b145f8e6050b
children 8d07a4254f04
comparison
equal deleted inserted replaced
314:38f5f298ce0e 315:084cccaa5deb
6 """ 6 """
7 Lexical analyzer part. Splits the input character stream into tokens. 7 Lexical analyzer part. Splits the input character stream into tokens.
8 """ 8 """
9 9
10 keywords = ['and', 'or', 'not', 'true', 'false', 10 keywords = ['and', 'or', 'not', 'true', 'false',
11 'else', 'if', 'while', 'return', 11 'else', 'if', 'while', 'for', 'return',
12 'function', 'var', 'type', 'const', 12 'function', 'var', 'type', 'const',
13 'struct', 'cast', 13 'struct', 'cast',
14 'import', 'module'] 14 'import', 'module']
15 15
16 16
43 ('NEWLINE', r'\n'), 43 ('NEWLINE', r'\n'),
44 ('SKIP', r'[ \t]'), 44 ('SKIP', r'[ \t]'),
45 ('COMMENTS', r'//.*'), 45 ('COMMENTS', r'//.*'),
46 ('LONGCOMMENTBEGIN', r'\/\*'), 46 ('LONGCOMMENTBEGIN', r'\/\*'),
47 ('LONGCOMMENTEND', r'\*\/'), 47 ('LONGCOMMENTEND', r'\*\/'),
48 ('LEESTEKEN', r'==|->|<<|>>|!=|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}|&|\^|\|'), 48 ('LEESTEKEN', r'==|->|<<|>>|!=|\+\+|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}|&|\^|\|'),
49 ('STRING', r"'.*?'") 49 ('STRING', r"'.*?'")
50 ] 50 ]
51 tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec) 51 tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec)
52 gettok = re.compile(tok_re).match 52 gettok = re.compile(tok_re).match
53 line = 1 53 line = 1