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