commit 05d44bb40760cd5b395c56e93da9dd15bc00eba9
parent c7410c4f3c4253c0f1363a8bcdfb0a068a3403c3
Auteur: Loïc Daignault-Pichette <loic@asteride.xyz>
Date: Sun, 15 Feb 2026 16:20:31 -0500
Exporter des symboles
Diffstat:
| M | tfm.c | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
| M | tfm.h | | | 6 | ++++++ |
2 fichiers modifiés, 51 insertions(+), 0 suppressions(-)
diff --git a/tfm.c b/tfm.c
@@ -133,6 +133,51 @@ fin:
return 0;
}
+ssize_t
+tfm_symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max)
+{
+ size_t lngr, i;
+ char *ctn;
+
+ TFM_COHERENT(tfm);
+ assert(symb);
+ assert(max > 0);
+
+ ctn = tampinf_ctn(tfm->symbs);
+
+ /* Sybmoles spéciaux. */
+ switch (id) {
+ case TFM_SYMB_EPSILON:
+ if (max < 3)
+ return -1;
+ memcpy(symb, "@0@", 3);
+ return 3;
+ }
+ assert(id <= 0xFF);
+
+ /* Les autres identifiants strictement positifs sont leur propre
+ * symbole. */
+ if (id > 0) {
+ /* On sait déjà que le tampon symb a une longueur supérieure à
+ * zéro. */
+ *symb = id;
+ return 1;
+ }
+
+ assert(tampinf_dedans(tfm->symbs, -id));
+ lngr = *(unsigned char *)(ctn + -id);
+
+ /* Le symbole doit rentrer dans le tampon. */
+ if (lngr > max)
+ return -1;
+
+ /* Copier le symbole. */
+ for (i = 0, ctn += -id + 1; i < lngr; i++)
+ symb[i] = ctn[i];
+
+ return lngr;
+}
+
int
tfm_mfinal(struct tfm *tfm, size_t ietat)
{
diff --git a/tfm.h b/tfm.h
@@ -74,6 +74,12 @@ int tfm_ajt(struct tfm *tfm, size_t es, size_t ed, ssize_t se, ssize_t ss);
* transparente. Renvoie 0, ou -1 en cas d’erreur. */
int tfm_symb_id(struct tfm *tfm, char *symb, size_t lngr, ssize_t *id);
+/* Placer le symbole du transducteur tfm correspondant à l’identifiant id dans
+ * le tampon symb, de taille max.
+ * Prend pour acquis que id est valide. Renvoie la taille du symbole, ou -1 en
+ * cas d’erreur. */
+ssize_t tfm_symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max);
+
/* Marquer un état comme final.
* Renvoie 0, ou -1 en cas d’erreur. */
int tfm_mfinal(struct tfm *tfm, size_t ietat);