SCM Repository
View of /sml/trunk/src/ml-yacc/examples/calc/calc.lex
Parent Directory
|
Revision Log
Revision 2 -
(download)
(annotate)
Sat Oct 4 23:33:09 1997 UTC (23 years, 5 months ago) by monnier
File size: 1021 byte(s)
Sat Oct 4 23:33:09 1997 UTC (23 years, 5 months ago) by monnier
File size: 1021 byte(s)
Initial revision
structure Tokens = Tokens type pos = int type svalue = Tokens.svalue type ('a,'b) token = ('a,'b) Tokens.token type lexresult= (svalue,pos) token val pos = ref 0 fun eof () = Tokens.EOF(!pos,!pos) fun error (e,l : int,_) = TextIO.output (TextIO.stdOut, String.concat[ "line ", (Int.toString l), ": ", e, "\n" ]) %% %header (functor CalcLexFun(structure Tokens: Calc_TOKENS)); alpha=[A-Za-z]; digit=[0-9]; ws = [\ \t]; %% \n => (pos := (!pos) + 1; lex()); {ws}+ => (lex()); {digit}+ => (Tokens.NUM (valOf (Int.fromString yytext), !pos, !pos)); "+" => (Tokens.PLUS(!pos,!pos)); "*" => (Tokens.TIMES(!pos,!pos)); ";" => (Tokens.SEMI(!pos,!pos)); {alpha}+ => (if yytext="print" then Tokens.PRINT(!pos,!pos) else Tokens.ID(yytext,!pos,!pos) ); "-" => (Tokens.SUB(!pos,!pos)); "^" => (Tokens.CARAT(!pos,!pos)); "/" => (Tokens.DIV(!pos,!pos)); "." => (error ("ignoring bad character "^yytext,!pos,!pos); lex());
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |