Update Makefile to make it compile with recent pilex
[c_to_python.git] / ansi_c.py
1 #!/usr/bin/env python3
2
3 # Copyright (C) 2018 Nick Downing <nick@ndcode.org>
4 # SPDX-License-Identifier: GPL-2.0-only
5 #
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
19 import t_def
20 import element
21 import sys
22 import xml.etree.ElementTree
23 import y_tab
24
25 root = y_tab.yyparse(t_def.AST.TranslationUnit)
26 element.serialize(root, 'a.xml', 'utf-8')
27 root = element.deserialize('a.xml', t_def.factory, 'utf-8')
28 #xml.etree.ElementTree.dump(root)
29
30 for i in root.children:
31   if isinstance(i, t_def.AST.Declaration):
32     base_type = i.children[0].get_type()
33     for j in i.children[1].children:
34       type, name = j.children[0].get_type_and_name(base_type)
35       sys.stdout.write('{0:s} {1:s}\n'.format(str(type), name))