File:  [Research Unix] / researchv10no / cmd / sml / lib / mlyacc / sample.lex
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:34 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

open Calc.LexValue
type lexresult=V
val eof = fn () => EOF
%%
alpha=[A-Za-z];
digit=[0-9];
ws = [\ \t\n];
%%
{ws}+	 => (lex());
{digit}+ => (NUM (revfold (fn (a,r) => ord(a)-ord("0")+10*r) (explode yytext) 0));
"+"	 => (PLUS);
"*"	 => (TIMES);
";"	 => (EOS);
{alpha}+ => (if yytext="print" then PRINT else ID yytext);
"-"	 => (SUB);
"^"	 => (CARAT);
"/"	 => (DIV);
.	 => (Calc.HDR.error ("ignoring bad character " ^ yytext); lex());

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.