Commit 04debbdf authored by Sergio Costas's avatar Sergio Costas

Merge branch 'newtree'

parents 7ea4fde6 67f527a7
......@@ -3,27 +3,61 @@
import sys
from crusty import crusty
lib = crusty.crusty()
tree = lib.parse_file(sys.argv[1])
lib = crusty.crusty("lexyacclib/crusty.h","lexyacclib/crusty.so")
tree = lib.read_file(sys.argv[1])
if tree is None:
sys.exit()
def print_node(node,isright,spaces):
if (node is None):
if isright:
print()
return
if not isright:
print(" "*spaces,end = "")
text = node.type
if (node.data is not None):
text += " ({:s})".format(node.data)
text += "->"
print(text,end = "")
spaces += len(text)
print_node(node.right,True,spaces)
print_node(node.left,False,spaces)
def print_param(node):
data = ""
if node.t_signed:
data += "signed "
if node.t_unsigned:
data += "unsigned "
if node.t_char:
data += "char "
if node.t_int:
data += "int "
if node.t_void:
data += "void "
if node.name is not None:
data += node.name
return data
for node in tree:
print_node(node,False,0)
tree2 = lib.process_tree(tree)
for node in tree2:
print(node)
def procnode(node):
if node is None:
return None
t,data2 = lib.process_node(node)
if data2 is None:
return node
if t == "VARIABLE_DEFINITION":
listdata = data2
else:
listdata = [data2]
for data in listdata:
data.child1 = procnode(node.child1)
data.child2 = procnode(node.child2)
data.child3 = procnode(node.child3)
data.child4 = procnode(node.child4)
data.right = procnode(node.right)
data.next = procnode(node.next)
if t == "VARIABLE_DEFINITION":
return data2
else:
return None
def print_nodes(nodelist, tabs = 0):
for element in nodelist:
print(" "*tabs,end = "")
print("Tipo: {:s}; Nombre: {:s}".format(str(element.type),str(element.name)))
if element.child1 is not None:
print_nodes(element.child1, tabs+1)
#print_nodes(tree)
try:
variables,functions = lib.process_tree(tree)
lib.process_functions(tree,variables,functions)
except:
pass
lib.print_errors()
This diff is collapsed.
......@@ -3,7 +3,7 @@ ifneq ($(LIB),no)
CC = gcc -c -DLIBRARY -fpic
LN = gcc -g -shared -o crusty.so
else
CC = gcc -c -DDO_PRINT
CC = gcc -g -c -DDO_PRINT
LN = gcc -o crusty
endif
......
This diff is collapsed.
#include <string.h>
#include <stdbool.h>
#ifdef DO_PRINT
#define MAX_VPOS 200
#endif
struct type_element {
char *data;
struct type_element *next;
};
struct AST {
int type;
int line;
char *filename;
int type;
char *data;
struct AST *parent;
struct AST *left;
int pointer;
bool t_const;
bool t_restrict;
bool t_volatile;
bool t_void;
bool t_char;
bool t_short;
bool t_int;
bool t_long;
bool t_longlong;
bool t_float;
bool t_double;
bool t_signed;
bool t_unsigned;
bool t_bool;
bool t_complex;
bool t_imaginary;
bool t_struct;
bool t_union;
bool t_enum;
bool t_extern;
bool t_typedef;
bool t_static;
bool t_auto;
bool t_register;
bool t_inline;
bool function;
bool t_crusty;
bool t_crusty_borrow;
bool t_crusty_recycle;
bool t_null;
bool t_ellipsis;
bool t_label;
char *name;
long long int intval;
double floatval;
struct AST *right;
struct AST *child1;
struct AST *child2;
struct AST *child3;
struct AST *child4;
struct AST *condition;
struct AST *next;
struct AST *function_params;
struct AST *bitfield;
struct AST *struct_data;
struct AST *enum_data;
struct AST *arrays;
struct AST *assignment;
struct AST *for_ch1;
struct AST *for_ch2;
struct AST *for_ch3;
};
extern int current_line;
extern char* current_file;
extern struct type_element *types_list;
extern struct AST *types_list;
extern char *token_list[];
extern struct AST *full_tree;
extern char do_verbose;
void set_code_tree(struct AST *tree);
char find_type(char *type);
struct AST *find_type(char *type);
int prepare_leaf(int current_token);
int prepare_leaf(unsigned long long int, double, int);
struct AST * new_leaf(int type, char *data, struct AST *left, struct AST *right);
struct AST * new_leaf(int type, struct AST *template);
struct AST * new_leaf_char(int type, char *data);
struct AST * new_leaf_tree(int type, struct AST *left, struct AST *right);
struct AST * new_leaf_tree_container(int type, struct AST *left, int container_type, struct AST *inner_left, struct AST *inner_right);
void append_right(struct AST *leaf, struct AST *right);
void append_next(struct AST *leaf, struct AST *next);
void append_next_leaf(struct AST *leaf,int type_leaf);
void append_fparams(struct AST *leaf, struct AST *param);
void mix_ast_leaves(struct AST *base, struct AST *new_leaf);
void copy_ast_data(struct AST *base, struct AST *new_leaf);
struct AST *transform_leaf(struct AST *leaf, int newtype);
void check_typedef(struct AST *type);
void check_typedef(struct AST *);
void show_error(int line,struct AST *element);
#ifdef DO_PRINT
void print_tree(struct AST *,int,int,bool);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment