diff options
| author | Simon Tatham <anakin@pobox.com> | 1999-02-05 17:42:09 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 1999-02-05 17:42:09 +0000 |
| commit | e224954f9ab0e3e8f309ce0e3f368db535ad0cf9 (patch) | |
| tree | b6206eac7671e1debc75a2a01b60a63c2d024c57 /input.c | |
| parent | fbf17205a84d846d0db1c636e86e25fd2dbdb485 (diff) | |
| download | halibut-e224954f9ab0e3e8f309ce0e3f368db535ad0cf9.zip halibut-e224954f9ab0e3e8f309ce0e3f368db535ad0cf9.tar.gz halibut-e224954f9ab0e3e8f309ce0e3f368db535ad0cf9.tar.bz2 halibut-e224954f9ab0e3e8f309ce0e3f368db535ad0cf9.tar.xz | |
Wrote some of the lexer. Nothing works yet.
[originally from svn r24]
Diffstat (limited to 'input.c')
| -rw-r--r-- | input.c | 55 |
1 files changed, 53 insertions, 2 deletions
@@ -22,13 +22,64 @@ static int get(input *in) { if (c == EOF) { fclose(in->currfp); in->currfp = NULL; - in->currindex++; } return c; } else return EOF; } +/* + * Lexical analysis of source files. + */ +typedef struct tagToken token; +struct tagToken { + int type; + char *text; +}; +enum { + tok_eof, + tok_eop, /* end of paragraph */ + tok_word, /* an ordinary word */ + tok_cmd, /* \command */ + tok_bracetext /* {text} */ +}; + +/* + * Adds a new paragraph to a linked list + */ +static paragraph addpara(paragraph ***hptrptr) { + paragraph *newpara = smalloc(sizeof(paragraph)); + newpara->next = NULL; + **hptrptr = newpara; + *hptrptr = &newpara->next; + return newpara; +} + +/* + * Reads a single file (ie until get() returns EOF) + */ +static void read_file(paragraph ***ret, input *in) { + int c; + + while (1) { + /* + * Get a token. + */ + token t = get_token(in); + if (t.type == tok_eof) + return; + printf("token: %d\n", t.type); + } +} + paragraph *read_input(input *in) { - /* FIXME: do some reading */ + paragraph *head = NULL; + paragraph **hptr = &head; + + while (in->currindex < in->nfiles) { + in->currfp = fopen(in->filenames[in->currindex], "r"); + if (in->currfp) + read_file(&hptr, in); + in->currindex++; + } } |