-OBJS=croma.o lex.yy.o parse.o macro.o errors.o
+OBJS=croma.o lex.yy.o lex.mlex.o parse.o macro.o errors.o
CFLAGS=-c -g
LDFLAGS=-o croma
lex lexer.l
$(CC) $(CFLAGS) lex.yy.c
+lex.mlex.o: mlexer.l
+ lex --prefix=mlex mlexer.l
+ $(CC) $(CFLAGS) lex.mlex.c
+
errors.o: errors.c errors.h
$(CC) $(CFLAGS) errors.c
--- /dev/null
+#include "dynstring.h"
+
+void init_dynstring(void)
+{
+ TAILQ_INIT(&dstrings_head);
+}
+
+struct dstring* alloc_and_insert_string(size_t len)
+{
+ struct dstring *s = calloc(len, sizeof(char));
+
+ if (s == NULL)
+ fail("Unable to alloc() memory");
+
+ TAILQ_INSERT_TAIL(&dstrings_head, s, strings);
+
+ return block;
+}
+
+struct dstring* alloc_after(struct dstring *before)
+{
+ if (before == NULL)
+ return NULL;
+
+ struct dstring *ptr;
+
+ TAILQ_FOREACH(ptr, &dstrings_head, strings) {
+ if (strncmp(ptr->p, before->p, 32) == 0)
+ {
+ struct dstring *s = calloc(len, sizeof(char));
+
+ if (s == NULL)
+ fail("Unable to alloc() memory");
+
+ TAILQ_INSERT_AFTER(dstrings_head, dstring, dstring, p)
+ }
+ }
+}
--- /dev/null
+#ifndef __DYNSTRING_H__
+#define __DYNSTRING_H__
+
+#include <stdlib.h>
+#include "queue.h"
+
+struct dstring {
+ char *p;
+ int length;
+ TAILQ_ENTRY(dstring) strings;
+};
+
+TAILQ_HEAD(dstring_heads, dstring) dstrings_head;
+
+#endif
--- /dev/null
+%{
+/*
+ mlexer.l - a lexer used to parse the strings in memory.
+*/
+
+#undef YY_INPUT
+
+#include "tokens.h"
+
+char *mlexer_ptr;
+
+int mlexwrap()
+{
+ return(1);
+}
+
+void init_mlexer(char *ptr)
+{
+ mlexer_ptr = ptr;
+}
+
+#define YY_INPUT(buf,result,max_size) \
+{ \
+int c = *mlexer_ptr++; \
+if (c == '\0')\
+ result = YY_NULL;\
+else{\
+ result = 1;\
+ buf[0] = c;\
+ }\
+}
+%}
+
+%%
+
+[:word:]+ { return WORD; }
+[:print:]+ { return OTHER; }
+<<EOF>> { return -1; }
+
+%%
\ No newline at end of file
extern int yylineno;
extern FILE *yyin;
+extern int mlexlex();
+extern char *mlextext;
+
char *token_list[] = { "left parenthesis",
"right parenthesis",
"{{",
fail("Unable to allocate memory");
}
+void bind_macro_arg(struct croma_block *b)
+{
+ /*
+ Note : this code assumes that every new element is inserted at the tail.
+ */
+}
void parse_block(struct croma_block *b)
{
}
-/*
- This routine extracts a word from a string, without modifying it.
- */
-
-
-char *extract_word(char *s)
-{
- while(*s == ' ' || *s == '\t' || *s == '\n')
- s++;
-
- char *wend = s;
-
- while(*wend != ' ' && *wend != '\t' && *wend != '\n' && *wend !='(' && *wend != ')')
- wend++;
-
- wend--; /* Get rid of the last (unwanted) character */
-
- if (wend == s)
- return NULL;
-
- int len = (wend - s);
- char *r = calloc(len + 1, sizeof(char));
- char *p = r;
-
- wend = s;
-
- int i;
- /* Copy the contents of the word in r. */
- for(i = 0; i <= len; i++)
- *p++ = *wend++;
-
- return r;
-}
-
/*
Replace arguments replaces all the references to the arguments
of b in t by their values.
+ It occurs only in memory.
*/
char *replace_arguments(struct croma_block *b, char *t)
return NULL;
char *buf = malloc(8192);
- char *ss = s; /* Used only to compute the length of the buffer */
- int buflen = s - ss;
-
struct croma_block *b;
-
int i = 0;
if (b == NULL)
fail("Unable to allocate memory");
-
- while(*s != '\0' && buflen < 8192) {
+ int c = mlexlex();
- while(*s == ' ' || *s == '\t' || *s == '\n')
- *buf++ = *s++;
+ while(c != -1 && i < 8192) {
+
+ switch(c) {
- char *name = extract_word(s);
+ case WORD:
+ char *name = extract_word(mlextext);
b = lookup_symbol(name);
if (b != NULL) {
}
- /* FIXME : implement argument list parsing */
- buflen = s - ss;
+ break;
+
}
void foreach_expr(void);
void define_expr(void);
+int extract_word(char *s);
void parse_arglist(struct croma_block *b, int (*tokenize)(void), void (*f) (struct croma_block *b));
void parse_block(struct croma_block *b);
enum {
LPAREN = 0, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES,
- QUOTE, FOREACH, DEFINE,
+ QUOTE, FOREACH, DEFINE, OTHER,
};