From d43994ebc260ea0ad6cd82c929059a44f998a782 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sun, 11 Jun 2017 22:50:09 +0100 Subject: Initial Commit --- .gitignore | 4 ++++ Makefile | 19 +++++++++++++++++++ ocml.l | 18 ++++++++++++++++++ ocml.y | 42 ++++++++++++++++++++++++++++++++++++++++++ rose.ocml | 7 +++++++ 5 files changed, 90 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 ocml.l create mode 100644 ocml.y create mode 100644 rose.ocml 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 +#include + +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 -- cgit v1.2.1