summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>1999-02-05 17:42:09 +0000
committerSimon Tatham <anakin@pobox.com>1999-02-05 17:42:09 +0000
commite224954f9ab0e3e8f309ce0e3f368db535ad0cf9 (patch)
treeb6206eac7671e1debc75a2a01b60a63c2d024c57 /input.c
parentfbf17205a84d846d0db1c636e86e25fd2dbdb485 (diff)
downloadhalibut-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.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/input.c b/input.c
index 9dc524c..e70c6a7 100644
--- a/input.c
+++ b/input.c
@@ -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++;
+ }
}