summaryrefslogtreecommitdiffabout
path: root/lib/forlan.h
Side-by-side diff
Diffstat (limited to 'lib/forlan.h') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/forlan.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/lib/forlan.h b/lib/forlan.h
new file mode 100644
index 0000000..4dadc70
--- a/dev/null
+++ b/lib/forlan.h
@@ -0,0 +1,123 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#define FORLAN_DBG_LEX 3
+#define FORLAN_DBG_GRAM 2
+#define FORLAN_DBG_EVAL 1
+
+extern int forlan_dbg;
+
+void forlan_init();
+void forlan_lex_begin(const char *input, size_t length,
+ struct grecs_locus_point *pt);
+void forlan_lex_end(void);
+int forlan_parse(const char *input, size_t length,
+ struct grecs_locus_point *pt);
+
+union forlan_node; /* Declared below */
+
+enum forlan_type {
+ forlan_type_null, /* Unknown/unset type */
+ forlan_type_comp, /* A path component */
+ forlan_type_test, /* Value test (f[X]) */
+ forlan_type_func, /* Function call */
+ forlan_type_cond, /* Conditional */
+ forlan_type_stmt, /* Statement */
+ forlan_type_lit, /* Literal */
+ forlan_type_expr, /* Boolean expression */
+ forlan_type_last /* Return last evaluated grecs_node */
+};
+
+/* A path component */
+struct forlan_node_comp {
+ enum forlan_type type;
+ int abs;
+ union forlan_node *node;
+};
+
+/* Path test: .path.comp[value] */
+struct forlan_node_test {
+ enum forlan_type type;
+ char *comp;
+ char *value;
+};
+
+/* Function call */
+struct forlan_node_func {
+ enum forlan_type type;
+ void *fp; /* FIXME: replace with typedef */
+ struct grecs_list *args; /* Arguments are struct forlan_node * */
+};
+
+/* Conditional */
+struct forlan_node_cond {
+ enum forlan_type type;
+ union forlan_node *expr; /* Controlling expression */
+ union forlan_node *iftrue; /* Run this if expr yields true */
+ union forlan_node *iffalse; /* Run this if expr yields false */
+};
+
+/* Statement or statement list */
+struct forlan_node_stmt {
+ enum forlan_type type;
+ union forlan_node *stmt;
+ union forlan_node *next;
+};
+
+/* Literal string */
+struct forlan_node_lit {
+ enum forlan_type type;
+ char *string;
+};
+
+/* Boolean opcodes */
+enum forlan_opcode {
+ forlan_opcode_node, /* Evaluate node, set 'last' */
+ forlan_opcode_and, /* Boolean AND */
+ forlan_opcode_or, /* Boolean OR */
+ forlan_opcode_not /* Boolean NOT */
+};
+
+/* Boolean expression */
+struct forlan_node_expr {
+ enum forlan_type type;
+ enum forlan_opcode opcode;
+ union forlan_node *arg[2];
+};
+
+/* Now get all this together */
+union forlan_node {
+ enum forlan_type type;
+ struct forlan_node_comp comp; /* A path component */
+ struct forlan_node_test test; /* Value test (f[X]) */
+ struct forlan_node_func func; /* Function call */
+ struct forlan_node_cond cond; /* Conditional */
+ struct forlan_node_stmt stmt; /* Statement */
+ struct forlan_node_lit lit; /* Literal */
+ struct forlan_node_expr expr; /* Boolean expression */
+ /* forlan_type_last needs no additional data */
+};
+
+union forlan_node *forlan_node_create(enum forlan_type type);
+void forlan_node_free(union forlan_node *);
+struct grecs_list *forlan_stmt_list(void);
+struct grecs_list *forlan_complist(void);
+union forlan_node *forlan_stmt_from_list(struct grecs_list *list);
+
+extern union forlan_node *forlan_parse_tree;
+
+void forlan_dump_node(FILE *fp, union forlan_node *p, int *num, int lev);
+void forlan_dump_tree(FILE *fp, union forlan_node *node);

Return to:

Send suggestions and report system problems to the System administrator.