summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-13 22:03:41 -0400
committerJakob Kaivo <jkk@ung.org>2019-03-13 22:03:41 -0400
commit90dd1b18f121b55463e785f65be4b8dfa696e600 (patch)
tree3e024db25b79b9c63bde47ae368488755a2195f9
migrate to gitlabHEADmaster
-rw-r--r--Makefile12
-rw-r--r--liby.c17
-rw-r--r--yacc.c64
3 files changed, 93 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..cd9a3e1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+.POSIX:
+
+CFLAGS=-D_XOPEN_SOURCE=700 -g
+
+all: yacc liby.a
+
+yacc: yacc.c
+
+liby.a: liby.a(liby.o)
+
+clean:
+ rm -f yacc *.o *.a
diff --git a/liby.c b/liby.c
new file mode 100644
index 0000000..f5cdd9a
--- /dev/null
+++ b/liby.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <locale.h>
+
+extern int yyparse(void);
+
+int yyerror(const char *s)
+{
+ fprintf(stderr, "%s\n", s);
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ setlocale(LC_ALL, "");
+ yyparse();
+ return 0;
+}
diff --git a/yacc.c b/yacc.c
new file mode 100644
index 0000000..75f1fc1
--- /dev/null
+++ b/yacc.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define C_ID_FIRSTCHAR "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+int main(int argc, char *argv[])
+{
+ char *fileprefix = "y";
+ char *symbolprefix = "yy";
+ int header = 0;
+ int lines = 1;
+ int debug = 0;
+ int verbose = 0;
+ int c;
+
+ while ((c = getopt(argc, argv, "bdlptv")) != -1) {
+ switch (c) {
+ case 'b':
+ /* Change file prefix */
+ fileprefix = optarg;
+ break;
+
+ case 'd':
+ /* Write a header file */
+ header = 1;
+ break;
+
+ case 'l':
+ /* Omit #line directives */
+ lines = 0;
+ break;
+
+ case 'p':
+ /* Change symbol prefix */
+ symbolprefix = optarg;
+ if (!strchr(C_ID_FIRSTCHAR, *symbolprefix)) {
+ printf("'%s' is not a valid prefix\n", optarg);
+ return 1;
+ }
+ break;
+
+ case 't':
+ /* Include debugging code */
+ debug = 1;
+ break;
+
+ case 'v':
+ /* Output a description file */
+ verbose = 1;
+ break;
+
+ default:
+ return 1;
+ }
+ }
+
+ if (optind != argc - 1) {
+ fprintf(stderr, "Must specify exactly one grammar file\n");
+ return 1;
+ }
+
+ return 0;
+}