aboutsummaryrefslogtreecommitdiff
path: root/util-tables.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2025-07-02 22:55:08 +0300
committerkartofen <mladenovnasko0@gmail.com>2025-07-02 22:55:08 +0300
commit5064a7ebce75a26d0405c92040f1a40187fcc7e3 (patch)
tree7a41182cf329e77ebb760969e3f220f60079c187 /util-tables.c
parenta67266ff72280b85fed7ec498967a855a5735639 (diff)
turn clr into lalr and first steps for generating a parser
Diffstat (limited to 'util-tables.c')
-rw-r--r--util-tables.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/util-tables.c b/util-tables.c
index 83a015c..09df914 100644
--- a/util-tables.c
+++ b/util-tables.c
@@ -27,20 +27,20 @@ void util_tables_fill()
follow[i] = xcalloc(total_symbols, sizeof(*follow[i]));
first[i] = xcalloc(total_symbols, sizeof(*follow[i]));
}
-
+
for(size_t sym = 0; sym < total_symbols; sym++) {
first[sym][sym] = 1;
}
-
+
for(size_t i = 0; i < total_productions; i++) {
struct production *p = &grammar[i];
-
+
first[p->LHS][p->RHS[0]] = 1;
-
+
for(size_t j = 1; j < p->nRHS; j++)
follow[p->RHS[j-1]][p->RHS[j]] = 1;
}
-
+
#define set(e) if((e) != 1) changed = (e) = 1
int changed;
@@ -66,7 +66,7 @@ void util_tables_free()
free(follow[i]);
free(first[i]);
}
-
+
free(follow);
free(first);
}
@@ -75,7 +75,7 @@ void util_tables_print()
{
char *s1 = "-- FIRST --";
printf(" %*s%s\n", (int)((total_symbols*3) - strlen(s1))/2, "", s1);
-
+
printf(" ");
for(size_t i = 0; i < total_symbols; i++) printf("%2zu ", i);
printf("\n");
@@ -88,7 +88,7 @@ void util_tables_print()
}
printf("\n");
-
+
char *s2 = "-- FOLLOW --";
printf(" %*s%s\n", (int)((total_symbols*3) - strlen(s2))/2, "", s2);
@@ -119,7 +119,7 @@ enum symbol {
SYMBOLS_END,
};
-const size_t total_symbols = SYMBOLS_END;
+size_t total_symbols = SYMBOLS_END;
int symbol_is_terminal(symbol s) { return s < E; }
int symbol_is_nonterminal(symbol s) { return s >= E; }