From: khamidou Date: Sat, 21 Feb 2009 06:16:41 +0000 (+0100) Subject: first commit X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=f5297f8277449ce785668eadcdccf5447f484d5b;p=croma.git first commit --- f5297f8277449ce785668eadcdccf5447f484d5b diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5246a72 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +OBJS=lex.yy.o croma.o +CFLAGS=-c +LDFLAGS=-o croma -lfl + +croma: OBJS + $(CC) $(LDFLAGS) $(OBJS) + +croma.o: croma.c + $(CC) $(CFLAGS) croma.c + +lex.yy.o: lexer.lex + lex lexer.lex + $(CC) $(CFLAGS) lex.yy.c \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/croma.c b/croma.c new file mode 100644 index 0000000..2f5232e --- /dev/null +++ b/croma.c @@ -0,0 +1,14 @@ +/* + croma, a macro processor. + +*/ + +#include +#include + + +int main(int argc, char **argv) +{ + + +} diff --git a/errors.h b/errors.h new file mode 100644 index 0000000..df657c7 --- /dev/null +++ b/errors.h @@ -0,0 +1,6 @@ +#ifndef __ERRORS_H__ +#define __ERRORS_H__ + +#define fatal(msg) do { printf(msg); exit(EXIT_FAILURE); } while(0) + +#endif diff --git a/expansions.c b/expansions.c new file mode 100644 index 0000000..81f6922 --- /dev/null +++ b/expansions.c @@ -0,0 +1,67 @@ +#include "expansions.h" +#include + +struct croma_word *alloc_word(struct croma_word *prev, + struct croma_word *next) +{ + struct croma_word *w = malloc(sizeof(struct croma_word)); + if (w == NULL) + return NULL; + + w->prev = prev; + w->next = next; + + if (prev != NULL) + prev->next = w; + + if (next != NULL) + next->prev = w; + + return w; +} + +void free_words(struct croma_word *w) +{ + if (w->next != NULL) + free_words(w->next); + + if (w->value != NULL) + free(w->value); + + if (w != NULL) + free(w); +} + +struct croma_word *dup_list(struct croma_word *l) +{ + struct croma_word *w = alloc_word(l, NULL); + if (w == NULL) + fatal("Unable to alloc() memory"); + + w->strdup(w->value); + w->next = dup_list(w); + + return w; +} + +/* replaces all the occurences of a word in a list */ +void replace_occurences(struct croma_word *l, char *o, char *replacement) +{ + if (l == NULL) + return; + + if(strcmp(n, l->value) == 0) { + free(l->value); + l->value = strdup(replacement); + } + + if (l->next != NULL) + replace_occurences(l->next, o, replacement); + +} + +void process_file(void) +{ + struct +} + diff --git a/expansions.h b/expansions.h new file mode 100644 index 0000000..ce2d9b8 --- /dev/null +++ b/expansions.h @@ -0,0 +1,15 @@ +#ifndef __EXPANSIONS_H__ +#define __EXPANSIONS_H__ + +struct croma_word { + char *value; + struct croma_word *prev, *next; +}; + +struct croma_word *alloc_word(struct croma_word *prev, + struct croma_word *next); +void free_words(struct croma_word *w); +struct croma_word *dup_list(struct croma_word *l); +void replace_occurences(struct croma_word *l, char *o, char *replacement); + +#endif diff --git a/lexer.lex b/lexer.lex new file mode 100644 index 0000000..5b4635e --- /dev/null +++ b/lexer.lex @@ -0,0 +1,16 @@ +%{ +/* + lexical analyzer for croma +*/ + +#include "tokens.h" + +%} + +"(" { return LPAREN; } +")" { return RPAREN; } +"{" { return LBRACKET; } +"}" { return RBRACKET; } +[:alpha:]+ { return WORD; }; +"$$" { return DOLDOL; } +[ \t\n]+ { return SPACES; } diff --git a/tokens.h b/tokens.h new file mode 100644 index 0000000..54d3f01 --- /dev/null +++ b/tokens.h @@ -0,0 +1,8 @@ +#ifndef __TOKENS_H__ +#define __TOKENS_H__ + +enum { + LPAREN, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES, +}; + +#endif