Add files via upload
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
# (c) 2018 Jan Lerking
|
||||
# Python lexer for c header files.
|
||||
# Used for creating corresponding NASM include files.
|
||||
# Contains tokens expanded with reserved 'C' keywords
|
||||
|
||||
def init():
|
||||
global tokens
|
||||
tokens = [
|
||||
'CSTART',
|
||||
'CMID',
|
||||
'CEND',
|
||||
'RPAREN',
|
||||
'LPAREN',
|
||||
'ENDLINE',
|
||||
'RETVAL',
|
||||
'PREPROCESS',
|
||||
'ID',
|
||||
'PLUS',
|
||||
'MINUS',
|
||||
'DIV',
|
||||
'MULT',
|
||||
'ASSIGN',
|
||||
'EQUAL',
|
||||
'LBRACE',
|
||||
'RBRACE',
|
||||
'COMMA',
|
||||
'SEMICOLON',
|
||||
'LANGLE',
|
||||
'RANGLE',
|
||||
'POINTER'
|
||||
]
|
||||
|
||||
reserved = {
|
||||
'auto' : 'AUTO',
|
||||
'break' : 'BREAK',
|
||||
'case' : 'CASE',
|
||||
'char' : 'CHAR',
|
||||
'const' : 'CONST',
|
||||
'continue' : 'CONTINUE',
|
||||
'default' : 'DEFAULT',
|
||||
'do' : 'DO',
|
||||
'int' : 'INT',
|
||||
'long' : 'LONG',
|
||||
'register' : 'REGISTER',
|
||||
'return' : 'RETURN',
|
||||
'short' : 'SHORT',
|
||||
'signed' : 'SIGNED',
|
||||
'sizeof' : 'SIZEOF',
|
||||
'static' : 'STATIC',
|
||||
'struct' : 'STRUCT',
|
||||
'switch' : 'SWITCH',
|
||||
'typedef' : 'TYPEDEF',
|
||||
'union' : 'UNION',
|
||||
'unsigned' : 'UNSIGNED',
|
||||
'void' : 'VOID',
|
||||
'volatile' : 'VOLATILE',
|
||||
'while' : 'WHILE',
|
||||
'double' : 'DOUBLE',
|
||||
'else' : 'ELSE',
|
||||
'enum' : 'ENUM',
|
||||
'extern' : 'EXTERN',
|
||||
'float' : 'FLOAT',
|
||||
'for' : 'FOR',
|
||||
'goto' : 'GOTO',
|
||||
'if' : 'IF'
|
||||
}
|
||||
|
||||
global preprocessor_directives
|
||||
preprocessor_directives = {
|
||||
'#include' : 'PREPROCESS',
|
||||
'#define' : 'PREPROCESS',
|
||||
'#undef' : 'PREPROCESS',
|
||||
'#if' : 'PREPROCESS',
|
||||
'#ifdef' : 'PREPROCESS',
|
||||
'#ifndef' : 'PREPROCESS',
|
||||
'#error' : 'PREPROCESS',
|
||||
'__FILE__' : 'PREPROCESS',
|
||||
'__LINE__' : 'PREPROCESS',
|
||||
'__DATE__' : 'PREPROCESS',
|
||||
'__TIME__' : 'PREPROCESS',
|
||||
'__TIMESTAMP__' : 'PREPROCESS',
|
||||
'pragma' : 'PREPROCESS',
|
||||
'#' : 'PREPROCESS',
|
||||
'##' : 'PREPROCESS'
|
||||
}
|
||||
|
||||
global regular
|
||||
regular = {
|
||||
'/*' : 'CSTART',
|
||||
'*' : 'CMID',
|
||||
'*/' : 'CEND',
|
||||
'=' : 'ASSIGN',
|
||||
'==' : 'EQUAL',
|
||||
'{' : 'LBRACE',
|
||||
'}' : 'RBRACE',
|
||||
'\+' : 'PLUS',
|
||||
'-' : 'MINUS',
|
||||
'\*' : 'MULT',
|
||||
'/' : 'DIV',
|
||||
'\(' : 'LPAREN',
|
||||
'\)' : 'RPAREN',
|
||||
',' : 'COMMA',
|
||||
';' : 'SEMICOLON',
|
||||
'\<' : 'LANGLE',
|
||||
'\>' : 'RANGLE'
|
||||
}
|
||||
|
||||
tokens += reserved.values()
|
||||
Reference in New Issue
Block a user