diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/liblex |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/liblex')
-rwxr-xr-x | sys/src/liblex/allprint.c | 39 | ||||
-rwxr-xr-x | sys/src/liblex/main.c | 13 | ||||
-rwxr-xr-x | sys/src/liblex/mkfile | 17 | ||||
-rwxr-xr-x | sys/src/liblex/reject.c | 58 | ||||
-rwxr-xr-x | sys/src/liblex/yyless.c | 27 | ||||
-rwxr-xr-x | sys/src/liblex/yywrap.c | 9 |
6 files changed, 163 insertions, 0 deletions
diff --git a/sys/src/liblex/allprint.c b/sys/src/liblex/allprint.c new file mode 100755 index 000000000..d508afd8b --- /dev/null +++ b/sys/src/liblex/allprint.c @@ -0,0 +1,39 @@ +#include <u.h> +#include <libc.h> +#include <stdio.h> + +extern FILE* yyout; + +int +printable(int c) +{ + return 040 < c && c < 0177; +} + +void +allprint(char c) +{ + + switch(c) { + case '\n': + fprintf(yyout,"\\n"); + break; + case '\t': + fprintf(yyout,"\\t"); + break; + case '\b': + fprintf(yyout,"\\b"); + break; + case ' ': + fprintf(yyout,"\\\bb"); + break; + default: + if(!printable(c)) + fprintf(yyout,"\\%-3o",c); + else + c = putc(c,yyout); + USED(c); + break; + } + return; +} diff --git a/sys/src/liblex/main.c b/sys/src/liblex/main.c new file mode 100755 index 000000000..47df5edc0 --- /dev/null +++ b/sys/src/liblex/main.c @@ -0,0 +1,13 @@ +#include <u.h> +#include <libc.h> +#include <stdio.h> + +int yylex(void); + +void +main(int argc, char *argv[]) +{ + USED(argc, argv); + yylex(); + exits(0); +} diff --git a/sys/src/liblex/mkfile b/sys/src/liblex/mkfile new file mode 100755 index 000000000..6b7aba649 --- /dev/null +++ b/sys/src/liblex/mkfile @@ -0,0 +1,17 @@ +</$objtype/mkfile + +LIB=/$objtype/lib/libl.a +OFILES=\ + allprint.$O\ + main.$O\ + reject.$O\ + yyless.$O\ + yywrap.$O\ + +UPDATE=\ + mkfile\ + $HFILES\ + ${OFILES:%.$O=%.c}\ + ${LIB:/$objtype/%=/386/%}\ + +</sys/src/cmd/mksyslib diff --git a/sys/src/liblex/reject.c b/sys/src/liblex/reject.c new file mode 100755 index 000000000..24e8bee1f --- /dev/null +++ b/sys/src/liblex/reject.c @@ -0,0 +1,58 @@ +#include <u.h> +#include <libc.h> +#include <stdio.h> + +extern FILE* yyout; +extern FILE* yyin; +extern int yyprevious, *yyfnd; +extern char yyextra[]; +extern char yytext[]; +extern int yyleng; + +extern +struct +{ + int *yyaa, *yybb; + int *yystops; +} *yylstate [], **yylsp, **yyolsp; + +int yyback(int *p, int m); +int yyinput(void); +void yyoutput(int c); +void yyunput(int c); + +int +yyracc(int m) +{ + + yyolsp = yylsp; + if(yyextra[m]) { + while(yyback((*yylsp)->yystops, -m) != 1 && yylsp > yylstate) { + yylsp--; + yyunput(yytext[--yyleng]); + } + } + yyprevious = yytext[yyleng-1]; + yytext[yyleng] = 0; + return m; +} + +int +yyreject(void) +{ + for(; yylsp < yyolsp; yylsp++) + yytext[yyleng++] = yyinput(); + if(*yyfnd > 0) + return yyracc(*yyfnd++); + while(yylsp-- > yylstate) { + yyunput(yytext[yyleng-1]); + yytext[--yyleng] = 0; + if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0) + return yyracc(*yyfnd++); + } + if(yytext[0] == 0) + return 0; + yyoutput(yyprevious = yyinput()); + yyleng = 0; + return -1; +} diff --git a/sys/src/liblex/yyless.c b/sys/src/liblex/yyless.c new file mode 100755 index 000000000..6ee8a6176 --- /dev/null +++ b/sys/src/liblex/yyless.c @@ -0,0 +1,27 @@ +#include <u.h> +#include <libc.h> +#include <stdio.h> + +extern char yytext[]; +extern int yyleng; +extern int yyprevious; + +void yyunput(int c); + +void +yyless(int x) +{ + char *lastch, *ptr; + + lastch = yytext+yyleng; + if(x>=0 && x <= yyleng) + ptr = x + yytext; + else + ptr = (char*)x; + while(lastch > ptr) + yyunput(*--lastch); + *lastch = 0; + if (ptr >yytext) + yyprevious = lastch[-1]; + yyleng = ptr-yytext; +} diff --git a/sys/src/liblex/yywrap.c b/sys/src/liblex/yywrap.c new file mode 100755 index 000000000..9c55d6fcd --- /dev/null +++ b/sys/src/liblex/yywrap.c @@ -0,0 +1,9 @@ +#include <u.h> +#include <libc.h> +#include <stdio.h> + +int +yywrap(void) +{ + return 1; +} |