PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/ m-music-language/src/scanner.mll

http://m-music-language.googlecode.com/
Unknown | 63 lines | 60 code | 3 blank | 0 comment | 0 complexity | f2024a7e6f1ae663264bcd61e7bf36f5 MD5 | raw file
 1{ open Parser } (* Get the token types *)
 2
 3rule token = parse
 4	[' ' '\t' '\r' '\n'] { token lexbuf } (* Whitespace *)
 5	| "/*" { comment lexbuf } (* Comments *)
 6	| "//" { singlecomment lexbuf }
 7	| '(' { LPAREN } 
 8	| ')' { RPAREN } (* punctuation *)
 9	| '{' { LBRACE } 
10	| '}' { RBRACE }
11	| ';' { SEMI } 
12	| ',' { COMMA }
13	| '.' { DOT }
14	| '+' { PLUS } (* started here *)
15	| '-' { MINUS }
16	| '*' { TIMES } 
17	| '/' { DIVIDE }
18	| '%' { MOD }
19	| "+=" { PLUSEQ }
20	| "-=" { MINUSEQ }
21	| "*=" { TIMESEQ }
22	| "/=" { DIVIDEEQ }
23	| "%=" { MODEQ }
24	| '=' { ASSIGN } 
25	| '!' { NOT }
26	| "++" { PLUSPLUS }
27	| "--" { MINUSMINUS }
28	| "==" { EQ }
29	| "!=" { NEQ } 
30	| '<' { LT }
31	| "<=" { LEQ } 
32	| ">" { GT }
33	| ">=" { GEQ } 
34	| "&&" { AND }
35	| "||" { OR }
36	| "if" { IF } (* keywords *) 
37	| "else" { ELSE } 
38	| "for" { FOR }
39	| "while" { WHILE } 
40	| "return" { RETURN }
41	| "void" { DATATYPE("void") }
42	| "int" { DATATYPE("int") }
43	| "float" { DATATYPE("float") }
44	| "bool" { DATATYPE("bool") }
45	| "note" { DATATYPE("note") }
46	| "chord" { DATATYPE("chord") }
47	| "staff" { DATATYPE("staff") }
48	| "part" { DATATYPE("part") }
49	| "true"|"false" as boollit { BOOLLITERAL(bool_of_string boollit) }
50	| (['a'-'g' 'A'-'G']['s' 'f' 'S' 'F']?['0'-'9'])|('r'|'R') as pitchlit { PITCHLITERAL(pitchlit) }
51	| eof { EOF } (* Endoffile *)
52	| ['0'-'9']+ as lxm { INTLITERAL(int_of_string lxm) } (* integers *)
53	| ((['0'-'9']+'.'['0'-'9']*)) as floatlit { FLOATLITERAL(float_of_string floatlit) }
54	| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
55	| _ as char { raise (Failure("illegal character: " ^ Char.escaped char)) }
56
57	and comment = parse
58	"*/" { token lexbuf } (* Endofcomment *)
59	| _ { comment lexbuf } (* Eat everything else *)
60	
61	and singlecomment = parse
62	['\r' '\n'] {token lexbuf } (* Endofcomment *)
63	| _ {singlecomment lexbuf } (* Eat everything else *)