Parsing negative integers in a calculator

I’m new to Menhir and I’m trying to implement a calculator using it. I’m aiming to include negative integers in my calculator as well. But I’m having trouble with one specific kind of expression. My parser fails when it encounters inputs like “43-1” when there is no space between the ‘-’ character and the positive integer operand to it’s right. Myparser.mly is as follows:

%token EOF
%token LPAREN
%token RPAREN
%token <int> INT
%token PLUS
%token TIMES
%token MINUS
%token DIV
%token MOD
%token POW

%start <Ast.expr> prog 

%%

prog:
    | e = expr; EOF { e } 
    ;

expr:
    | term { $1 }
    | expr PLUS term { Ast.Binop(Add, $1, $3) }
    | expr MINUS term { Ast.Binop(Sub,$1, $3) }
    ;

term: 
    | powterm { $1 }
    | expr TIMES powterm { Ast.Binop(Mul, $1, $3) }
    | expr DIV powterm { Ast.Binop(Div, $1, $3) }
    | expr MOD powterm { Ast.Binop(Mod, $1, $3) }
    ;

powterm:
    | factor { $1 }
    | factor POW powterm { Ast.Binop(Pow, $1,  $3) }

factor:
    | INT { Int($1) }
    | MINUS INT { Int(-1 * $2) }
    | LPAREN expr RPAREN { $2 }
    ;

What mistake have I made in my parser? Any help is much appreciated.

Whitespace handling is typically the purview of the lexer, not the parser, so that’s where I would start looking.

Cheers,
Nicolas

What does ‘fail’ mean?
Does Menhir complain about conflicts? Like

% dune clean && dune build                              
Warning: 2 states have reduce/reduce conflicts.
Warning: 10 reduce/reduce conflicts were arbitrarily resolved.

Because when I run it on your file I get

% menhir --explain lib/Myparser.mly 
Warning: 2 states have reduce/reduce conflicts.
Warning: 10 reduce/reduce conflicts were arbitrarily resolved.

You can see the problems in the generated file Myparser.mly.