structure Tokens = Tokens open Tokens type pos = unit type svalue = svalue type ('a, 'b) token = ('a, 'b) token type lexresult = (svalue, pos) token fun eof () = SEMICOLON((),()) fun error (e, pos, _) = (print e; print "\n") %% %header (functor MyCLexFun(structure Tokens : MyC_TOKENS)); space=[\ \t\n\r]; digit=[0-9]; alpha=[A-Za-z_]; %% "=" => (EQUAL((),())); "+" => (PLUS((),())); "(" => (LPAREN((),())); ")" => (RPAREN((),())); ">" => (GREATER((),())); "{" => (LBRACE((),())); "}" => (RBRACE((),())); ";" => (SEMICOLON((),())); "-"? {digit}+ => (CONST(valOf(Int.fromString yytext),(),())); {alpha}+ => (case yytext of "while" => WHILE((),()) | "print" => PRINT((),()) | x => VAR(x,(),())); {space}+ => (lex()(* 空白をスキップして字句解析を続行 *));