summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code2/parser.c
diff options
context:
space:
mode:
authorThing1 <thing1@seacrossedlovers.xyz>2024-08-29 15:01:34 +0100
committerThing1 <thing1@seacrossedlovers.xyz>2024-08-29 15:01:34 +0100
commitd28f618c0e4c3da57c856a31d9ce3003a086e7ed (patch)
tree9edb35867649ba55268f40591015f4ff226f5abf /comp/lucas-standen-NEA/code2/parser.c
parentcfdd3c90877b59dc674cc9f68c0b7b4bb7c14ba8 (diff)
finished the new tokenizer
Diffstat (limited to 'comp/lucas-standen-NEA/code2/parser.c')
-rw-r--r--comp/lucas-standen-NEA/code2/parser.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/comp/lucas-standen-NEA/code2/parser.c b/comp/lucas-standen-NEA/code2/parser.c
index ebf8e47..d9cb7bd 100644
--- a/comp/lucas-standen-NEA/code2/parser.c
+++ b/comp/lucas-standen-NEA/code2/parser.c
@@ -5,7 +5,12 @@
#include "util.h"
-int countChars(char *s, char c){
+typedef struct strings {
+ char **strs;
+ int count;
+} strings;
+
+int countChars(char *s, char c){ // counts the number of times c ocurrs in s
int count = 0;
for (int i = 0; i < strlen(s); i++){
if (s[i] == c) count++;
@@ -13,7 +18,7 @@ int countChars(char *s, char c){
return count;
}
-char **parse(FILE *f){
+strings *parse(FILE *f){
fseek(f, 0, SEEK_END);
int len = ftell(f);
rewind(f);
@@ -43,9 +48,12 @@ char **parse(FILE *f){
tokCount++;
}
}
+ strings *strs = malloc(sizeof(strings));
+ strs->strs = tokens;
+ strs->count = tokCount;
free(line);
free(contents);
- return tokens;
+ return strs;
}