summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-11 22:50:09 +0100
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-06-11 22:50:09 +0100
commitd43994ebc260ea0ad6cd82c929059a44f998a782 (patch)
treed78dd42544cc86372636bf85c13539fee1897822
Initial CommitHEADmaster
-rw-r--r--.gitignore4
-rw-r--r--Makefile19
-rw-r--r--ocml.l18
-rw-r--r--ocml.y42
-rw-r--r--rose.ocml7
5 files changed, 90 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..39b9d96
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.swp
+*.tab.*
+*.yy.*
+ocml
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2f08bc7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+P=ocml
+
+${P}: ${P}.tab.o lex.yy.o
+ gcc -o $@ $^ -lfl
+
+%.o: %.c ${P}.tab.h
+ gcc -c $^
+
+${P}.tab.h: ${P}.y
+ bison -d ${P}.y
+
+lex.yy.c: ${P}.l
+ flex ${P}.l
+
+${P}.tab.c: ${P}.y
+ bison ${P}.y
+
+clean:
+ rm -f *.tab.* *.yy.* ${P}
diff --git a/ocml.l b/ocml.l
new file mode 100644
index 0000000..6808935
--- /dev/null
+++ b/ocml.l
@@ -0,0 +1,18 @@
+%{
+#include "ocml.tab.h"
+extern int yylval;
+%}
+
+%%
+[0-9]+ yylval = atoi(yytext); return tNum;
+sk return tSkip;
+ch return tChain;
+sl return tSlip;
+sc return tSingle;
+hdc return tHalfDouble;
+dc return tDouble;
+tr return tTriple;
+\{ return tStartBlock;
+\} return tEndBlock;
+[ \t\n]+ ;
+. return tErr;
diff --git a/ocml.y b/ocml.y
new file mode 100644
index 0000000..d6f33e7
--- /dev/null
+++ b/ocml.y
@@ -0,0 +1,42 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+
+extern char* yytext;
+%}
+
+%token tSkip tChain tSlip tSingle tHalfDouble tDouble tTriple tStartBlock tEndBlock tNum tErr
+%%
+
+ start: start input
+ | input
+ ;
+
+ input: stitch
+ | tNum stitch
+ | block
+ | tNum block
+ ;
+
+stitch: tSkip
+ | tChain
+ | tSlip
+ | tSingle
+ | tHalfDouble
+ | tDouble
+ | tTriple
+ ;
+
+ block: tStartBlock start tEndBlock
+ ;
+
+%%
+int yyerror(char* s) {
+ if (yytext[0]==10) printf("!!SYNTAX ERROR!! Token read was NEWLINE.\n");
+ else if (yytext[0]=='\0') printf("!!SYNTAX ERROR!! Unexpected end of input.\n");
+ else printf("!!SYNTAX ERROR!! Token read was \"%s\".\n", yytext);
+}
+
+int main() {
+ return yyparse();
+}
diff --git a/rose.ocml b/rose.ocml
new file mode 100644
index 0000000..471a12e
--- /dev/null
+++ b/rose.ocml
@@ -0,0 +1,7 @@
+26ch
+sk
+25{sc}
+5{5dc sl}
+4{5hdc sl}
+3{5sc sl}
+ch