baum

changeset 0:2f71d692d4f9

initial commit
author meillo@marmaro.de
date Thu, 07 Feb 2008 12:51:54 +0100
parents
children 3da0ff17c8e7
files .hgignore Makefile baum.c
diffstat 3 files changed, 127 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Thu Feb 07 12:51:54 2008 +0100
     1.3 @@ -0,0 +1,6 @@
     1.4 +syntax: glob
     1.5 +*~
     1.6 +*.swp
     1.7 +
     1.8 +*.o
     1.9 +baum
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Thu Feb 07 12:51:54 2008 +0100
     2.3 @@ -0,0 +1,51 @@
     2.4 +# common makefile
     2.5 +
     2.6 +# program
     2.7 +PROGRAM = baum
     2.8 +SRC = baum.c
     2.9 +OBJ = ${SRC:.c=.o}
    2.10 +DEP =
    2.11 +
    2.12 +# compile env
    2.13 +CC = gcc
    2.14 +LD = ${CC}
    2.15 +DEBUG = -g
    2.16 +CFLAGS = -Wall -c ${DEBUG}
    2.17 +LFLAGS = -Wall ${DEBUG}
    2.18 +
    2.19 +####
    2.20 +
    2.21 +all: options ${PROGRAM}
    2.22 +
    2.23 +options:
    2.24 +	@echo build options:
    2.25 +	@echo "CC     = ${CC}"
    2.26 +	@echo "LD     = ${LD}"
    2.27 +	@echo "CFLAGS = ${CFLAGS}"
    2.28 +	@echo "LFLAGS = ${LFLAGS}"
    2.29 +	@echo
    2.30 +
    2.31 +.cpp.o:
    2.32 +	$(CC) $(CFLAGS) $<
    2.33 +
    2.34 +${OBJ}: ${DEP}
    2.35 +
    2.36 +${PROGRAM}: ${OBJ}
    2.37 +	$(LD) $(LFLAGS) ${OBJ} -o $@
    2.38 +
    2.39 +debug: all
    2.40 +	gdb ${PROGRAM}
    2.41 +
    2.42 +strip: ${PROGRAM}
    2.43 +	@echo stripping ${PROGRAM}
    2.44 +	@strip ${PROGRAM}
    2.45 +
    2.46 +tar: clean
    2.47 +	@echo creating archive
    2.48 +	@tar -czvf ${PROGRAM}.tar.gz *
    2.49 +
    2.50 +clean:
    2.51 +	@echo cleaning
    2.52 +	@rm -f ${PROGRAM} ${OBJ}
    2.53 +
    2.54 +.PHONY: all options debug strip tar clean
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/baum.c	Thu Feb 07 12:51:54 2008 +0100
     3.3 @@ -0,0 +1,70 @@
     3.4 +/*
     3.5 + * baum - an esoteric programming language
     3.6 + *
     3.7 + * (c) markus schnalke <meillo@marmaro.de>
     3.8 + * and julian forster
     3.9 + *
    3.10 + */
    3.11 +
    3.12 +
    3.13 +#include <stdio.h>
    3.14 +#include <stdlib.h>
    3.15 +
    3.16 +
    3.17 +struct Node {
    3.18 +	char* name;
    3.19 +	char value;
    3.20 +	struct Node* down;
    3.21 +	struct Node* right;
    3.22 +};
    3.23 +
    3.24 +struct Node* root;
    3.25 +
    3.26 +
    3.27 +struct Node* newNode(char* name) {
    3.28 +	struct Node* node;
    3.29 +	node = (struct Node*) malloc(sizeof(struct Node));
    3.30 +	node->name = name;
    3.31 +	node->value = 0;
    3.32 +	node->right = 0;
    3.33 +	node->down = 0;
    3.34 +	return node;
    3.35 +}
    3.36 +
    3.37 +void init() {
    3.38 +	root = newNode("print");
    3.39 +	root->down = newNode("sum");
    3.40 +}
    3.41 +
    3.42 +void cleanup(struct Node* node) {
    3.43 +	if (node->down != NULL) {
    3.44 +		cleanup(node->down);
    3.45 +	}
    3.46 +	if (node->right != NULL) {
    3.47 +		cleanup(node->right);
    3.48 +	}
    3.49 +	free(node); node=0;
    3.50 +}
    3.51 +
    3.52 +void printNode(struct Node* node) {
    3.53 +	printf("Node: %20s (%c)\n", node->name, node->value);
    3.54 +}
    3.55 +
    3.56 +void printTree(struct Node* root) {
    3.57 +	printNode(root);
    3.58 +	if (root->down != NULL) {
    3.59 +		printTree(root->down);
    3.60 +	}
    3.61 +	if (root->right != NULL) {
    3.62 +		printTree(root->right);
    3.63 +	}
    3.64 +}
    3.65 +
    3.66 +
    3.67 +int main(int argc, char* argv[]) {
    3.68 +	init();
    3.69 +	printTree(root);
    3.70 +	cleanup(root);
    3.71 +	
    3.72 +	return(0);
    3.73 +}