Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/ml-yacc/examples/calc/calc.lex
ViewVC logotype

Annotation of /sml/trunk/src/ml-yacc/examples/calc/calc.lex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : monnier 2 structure Tokens = Tokens
2 :    
3 :     type pos = int
4 :     type svalue = Tokens.svalue
5 :     type ('a,'b) token = ('a,'b) Tokens.token
6 :     type lexresult= (svalue,pos) token
7 :    
8 :     val pos = ref 0
9 :     fun eof () = Tokens.EOF(!pos,!pos)
10 :     fun error (e,l : int,_) = TextIO.output (TextIO.stdOut, String.concat[
11 :     "line ", (Int.toString l), ": ", e, "\n"
12 :     ])
13 :    
14 :     %%
15 :     %header (functor CalcLexFun(structure Tokens: Calc_TOKENS));
16 :     alpha=[A-Za-z];
17 :     digit=[0-9];
18 :     ws = [\ \t];
19 :     %%
20 :     \n => (pos := (!pos) + 1; lex());
21 :     {ws}+ => (lex());
22 :     {digit}+ => (Tokens.NUM (valOf (Int.fromString yytext), !pos, !pos));
23 :    
24 :     "+" => (Tokens.PLUS(!pos,!pos));
25 :     "*" => (Tokens.TIMES(!pos,!pos));
26 :     ";" => (Tokens.SEMI(!pos,!pos));
27 :     {alpha}+ => (if yytext="print"
28 :     then Tokens.PRINT(!pos,!pos)
29 :     else Tokens.ID(yytext,!pos,!pos)
30 :     );
31 :     "-" => (Tokens.SUB(!pos,!pos));
32 :     "^" => (Tokens.CARAT(!pos,!pos));
33 :     "/" => (Tokens.DIV(!pos,!pos));
34 :     "." => (error ("ignoring bad character "^yytext,!pos,!pos);
35 :     lex());
36 :    
37 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0