diff --git a/lexer/__pycache__/keywords.cpython-34.pyc b/lexer/__pycache__/keywords.cpython-34.pyc new file mode 100644 index 0000000..40baa92 Binary files /dev/null and b/lexer/__pycache__/keywords.cpython-34.pyc differ diff --git a/lexer/__pycache__/tokens.cpython-34.pyc b/lexer/__pycache__/tokens.cpython-34.pyc new file mode 100644 index 0000000..ad59931 Binary files /dev/null and b/lexer/__pycache__/tokens.cpython-34.pyc differ diff --git a/lexer/gtk.h b/lexer/gtk.h new file mode 100644 index 0000000..7b901e1 --- /dev/null +++ b/lexer/gtk.h @@ -0,0 +1,293 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#ifndef __GTK_H__ +#define __GTK_H__ + +#define __GTK_H_INSIDE__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef GTK_DISABLE_DEPRECATED +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif /* GTK_DISABLE_DEPRECATED */ + +#include + +#undef __GTK_H_INSIDE__ + +#endif /* __GTK_H__ */ diff --git a/lexer/keywords.py b/lexer/keywords.py new file mode 100644 index 0000000..ea03bd7 --- /dev/null +++ b/lexer/keywords.py @@ -0,0 +1,107 @@ +# (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', + 'POINTER', + 'PREPROCESS', + 'ID', + 'PLUS', + 'MINUS', + 'DIV', + 'MULT', + 'ASSIGN', + 'EQUAL', + 'LBRACE', + 'RBRACE', + 'COMMA', + 'SEMICOLON', + 'LANGLE', + 'RANGLE' + ] + + 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() \ No newline at end of file diff --git a/lexer/lexer.py b/lexer/lexer.py new file mode 100644 index 0000000..fff4e30 --- /dev/null +++ b/lexer/lexer.py @@ -0,0 +1,22 @@ +# (c) 2018 Jan Lerking +# Python lexer for c header files. +# Used for creating corresponding NASM include files. + +import keywords +import os + +keywords.init() + +lexed_line = [] + +def lex_line(l): + prep = keywords.preprocessor_directives + reg = keywords.regular + for w in l: + if w in prep: + lexed_line.append(prep(w)) + lexed_line.append(w) + break + if w in reg: + lexed_line.append(reg(w)) + lexed_line.append(w) \ No newline at end of file