(* Ocamllex scanner for PieNum *)

{
  open Parser
}

let whitespace = [' ' '\t' '\r' '\n']
let digits = ['0'-'9']
let exp = ('e' | 'E') ('+' | '-')? digits+
let alphabet = ['a'-'z' 'A'-'Z']
let alphanumund = alphabet | digits | '_'

rule token = parse
  whitespace { token lexbuf }
| "#"        { comment lexbuf }          (* Comments *)
| '('        { LPAREN }
| ')'        { RPAREN }
| '{'        { LBRACE }
| '}'        { RBRACE }
| '['        { LBRACK }
| ']'        { RBRACK }
| ';'        { SEMI }
| ','        { COMMA }
| '='        { ASSIGN}
| '+'	     { PLUS }
| '-'        { MINUS }
| '.'		 { DOT	}
| '*'        { TIMES }
| "**"		 { STARSTAR }
| '/'        { DIVIDE }
| "=="       { EQ }
| "!="       { NEQ }
| '<'        { LT }
| "&"		 { AMP }
| "<="       { LEQ }
| ">"        { GT }
| "++"		 {PLUSPLUS }
| ">="       { GEQ }
| '^'        { EXP }
| "&&"       { AND }
| "||"       { OR }
| "!"        { NOT }
| "int"      { INT }
| "float"    { FLOAT }
| "bool"     { BOOL }
| "String"   { STRING }
| "void"     { VOID }
| "true"     { TRUE }
| "false"    { FALSE }
| "if"       { IF }
| "else"     { ELSE }
| "for"		 { FOR }
| "while"    { WHILE }
| "return"   { RETURN }
| "null"     { NULL }
| "new"      {NEW}
| "[["	     {LMATBRACK}
| "]]"	     {RMATBRACK}
| "],["	     {BAR}


(*Built in Types *)
| "Img"    { IMG }
| "Arr"    { ARRAY }
| "Mat"    { MATRIX }
| ['0'-'9']+ as lxm { INTLITERAL(int_of_string lxm) }
| ('.' digits+ exp? | digits+ ('.' digits* exp? | exp)) as lxm { FLOATLITERAL(float_of_string lxm) }
| '"'(['a'-'z' 'A'-'Z' '0'-'9''|'' ' '.' '_' ',' '[' '(' '{' '}' ')' ']']* as s)'"' {STRINGLITERAL(s)}
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| eof { EOF }
| _ as char { raise (Failure("Illegal character " ^ Char.escaped char)) }

and comment = parse
  "#"  { token lexbuf }
| _    { comment lexbuf }

(*increment and decrement operations?*)
