diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | ocml.l | 18 | ||||
-rw-r--r-- | ocml.y | 42 | ||||
-rw-r--r-- | rose.ocml | 7 |
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} @@ -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; @@ -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 |