Mercurial > lcfOS
comparison python/c3/lexer.py @ 205:d77cb5962cc5
Added some handcoded arm code generation
author | Windel Bouwman |
---|---|
date | Sun, 23 Jun 2013 18:23:18 +0200 |
parents | de3a68f677a5 |
children | 003c8a976fff |
comparison
equal
deleted
inserted
replaced
204:de3a68f677a5 | 205:d77cb5962cc5 |
---|---|
26 ('NEWLINE', r'\n'), | 26 ('NEWLINE', r'\n'), |
27 ('SKIP', r'[ \t]'), | 27 ('SKIP', r'[ \t]'), |
28 ('COMMENTS', r'//.*'), | 28 ('COMMENTS', r'//.*'), |
29 ('LONGCOMMENTBEGIN', r'\/\*'), | 29 ('LONGCOMMENTBEGIN', r'\/\*'), |
30 ('LONGCOMMENTEND', r'\*\/'), | 30 ('LONGCOMMENTEND', r'\*\/'), |
31 ('LEESTEKEN', r'==|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}'), | 31 ('LEESTEKEN', r'==|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}|&|\^|\|'), |
32 ('STRING', r"'.*?'") | 32 ('STRING', r"'.*?'") |
33 ] | 33 ] |
34 tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec) | 34 tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec) |
35 gettok = re.compile(tok_re).match | 35 gettok = re.compile(tok_re).match |
36 line = 1 | 36 line = 1 |
41 typ = mo.lastgroup | 41 typ = mo.lastgroup |
42 val = mo.group(typ) | 42 val = mo.group(typ) |
43 if typ == 'NEWLINE': | 43 if typ == 'NEWLINE': |
44 line_start = pos | 44 line_start = pos |
45 line += 1 | 45 line += 1 |
46 elif typ == 'COMMENT': | 46 elif typ == 'COMMENTS': |
47 pass | 47 pass |
48 elif typ == 'LONGCOMMENTBEGIN': | 48 elif typ == 'LONGCOMMENTBEGIN': |
49 incomment = True | 49 incomment = True |
50 elif typ == 'LONGCOMMENTEND': | 50 elif typ == 'LONGCOMMENTEND': |
51 incomment = False | 51 incomment = False |
71 loc = SourceLocation(line, mo.start()-line_start, mo.end() - mo.start()) | 71 loc = SourceLocation(line, mo.start()-line_start, mo.end() - mo.start()) |
72 yield Token(typ, val, loc) | 72 yield Token(typ, val, loc) |
73 pos = mo.end() | 73 pos = mo.end() |
74 mo = gettok(s, pos) | 74 mo = gettok(s, pos) |
75 if pos != len(s): | 75 if pos != len(s): |
76 col = pos - line_start | 76 col = pos - line_start |
77 pos = line | 77 loc = SourceLocation(line, col, 1) |
78 raise CompilerError('Unexpected character {0}'.format(s[pos]), pos) | 78 raise CompilerError('Unexpected character "{0}"'.format(s[pos]), loc) |
79 loc = SourceLocation(line, 0, 0) | 79 loc = SourceLocation(line, 0, 0) |
80 yield Token('END', '', loc) | 80 yield Token('END', '', loc) |
81 | 81 |