From 51f3bfd0e73d5e78d9fe71e6106a2a883619e18f Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 31 Aug 2024 16:06:55 +0000 Subject: stage 1. --- s1/mkfile | 10 ++++++++ s1/rhoc.y | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 s1/mkfile create mode 100644 s1/rhoc.y (limited to 's1') diff --git a/s1/mkfile b/s1/mkfile new file mode 100644 index 0000000..ec4ce25 --- /dev/null +++ b/s1/mkfile @@ -0,0 +1,10 @@ + +#include +#include +#include + +Biobuf *bin; +int lineno; +int prompt; + +int yyparse(void); + +void +yyerror(char *msg) +{ + fprint(2, "%s at line %d\n", msg, lineno); +} + +int +yylex(void) +{ + int c; + + if(prompt){ + print("%d: ", lineno); + prompt--; + } + while((c = Bgetc(bin)) == ' ' || c == '\t') + ; + if(c == '.' || isdigit(c)){ + Bungetc(bin); + Bgetd(bin, &yylval); + return NUMBER; + } + if(c == '\n'){ + lineno++; + prompt++; + } + return c; +} + +void +usage(void) +{ + fprint(2, "usage: %s\n", argv0); + exits("usage"); +} + +void +main(int argc, char *argv[]) +{ + ARGBEGIN{ + default: usage(); + }ARGEND; + + if(argc > 0) + usage(); + bin = Bfdopen(0, OREAD); + if(bin == nil) + sysfatal("Bfdopen: %r"); + lineno++; + prompt++; + yyparse(); + Bterm(bin); + exits(0); +} -- cgit v1.2.3