Hydrogen-python/lexical/rule.py

90 lines
1.6 KiB
Python

# 所有的 token 的类型
token_type = [
'right-arrow',
'else',
'if',
'i32',
'f32',
'return',
'void',
'while',
'addition',
'subtraction',
'fn',
'multiplication',
'division',
'yushu',
'bigger-equal',
'smaller-equal',
'bigger',
'smaller',
'equal',
'not-equal',
'evaluate',
'semicolon',
'comma',
'colon',
'left-parentheses',
'right-parentheses',
'left-bracket',
'right-bracket',
'left-brace',
'right-brace',
'id',
'float-num',
'int-num',
]
# 分隔符号
split_char_type = [
'space'
]
# 注释
note_char_type = (
'note-start',
'note-end',
'note-single'
)
# 正则表达式字典
regex_dict = {
'right-arrow':r'->',
'space': r' +',
'note-start': r'/\*',
'note-end': r'\*/',
'note-single': r'//',
'else': r'else',
'if': r'if',
'i32': r'i32',
'f32':r'f32',
'return': r'return',
'void': r'void',
'fn':r'fn',
'while': r'while',
'addition': r'\+',
'subtraction': r'-',
'multiplication': r'\*',
'division': r'/',
'yushu': r'%',
'bigger': r'>',
'bigger-equal': r'>=',
'smaller': r'<',
'smaller-equal': r'<=',
'equal': r'==',
'not-equal': r'!=',
'evaluate': r'=',
'semicolon': r';',
'colon': r':',
'comma': r',',
'left-parentheses': r'\(',
'right-parentheses': r'\)',
'left-bracket': r'\[',
'right-bracket': r'\]',
'left-brace': r'\{',
'right-brace': r'\}',
'id': r'[a-zA-Z][a-zA-Z_]*',
'float-num': r'\d+\.\d+[eE][+-]\d+|\d+\.\d+|\d+[eE][+-]\d+',
'int-num': r'[1-9][0-9]*|0',
}