编译原理 课程设计(Python)
词法分析程序设计
```python
lookup_dic = {'begin': 1, 'if': 2, 'then': 3, 'while': 4, 'do': 5, 'end': 6,
'+': 13, '-': 14, '*': 15, '/': 16, ':': 25, ':=': 18,
'<': 20, '<>': 21, '<+': 22, '>': 23, '>=': 24, '=': 25,
';': 26, '(': 27, ')': 28, '#': 0}
def emit(value, type_str):
emit_index = ''
emit_value = value
if type_str == 'num':
emit_index = '11'
elif type_str == 'word':
if value in lookup_dic.keys():
emit_index = str(lookup_dic[value])
else:
emit_index = '10'
emit_value = '\''+value+'\''
elif typ