How can I handle a parameter sequence in Ocamlyacc for a program written in Rustine?

42 Views Asked by At

I am currently working in an parser for Rustine using ocamllex and ocamlyacc and I would like my parser to recognize pattern such as fn add(x:i32, y:i32) ( for now ). I have written a lexer.mll and a parser.mly . The problem comes when I have multiple parameters. My parser recognizes fn add(x:i32 but not the rest , y:i32) . I have this message : Fatal error: exception Stdlib.Parsing.Parse_error. Even for patterns like fn add(x:i32) , it only recognizes fn add(x:i32 not the ')'.

Here what I have written :

motif:
    | p_id DeuxPts type_ {ParametreMut($1,$3)}
parametre:
    | epsilon {$1}
    | motif {[$1]}
    | motif Virgule parametre {$1::$3}

epsilon:
    | {[]}

p_id:
| Id {$1}
| Mutable Id{$2}


declaration_fonction: 
    | Fn Id ParO parametre ParF t_o b  {
        let e1 = List.fold_right (fun x a -> Param(x,a)) $4 VoidParam   in 
        Fn($2,e1,$6,$7)}   

and a here a piece of my lexer :

| '(' {print_endline "ParO";ParO}
| ':' {print_endline "DeuxPts";DeuxPts}
| ',' {print_endline "Virgule";Virgule}
| ')' {print_endline "ParF";ParF}
| '{' {print_endline "AccoladeO";AccoladeO}
| '}' {AccoladeF}
| "let" {print_endline "Let"; Let}
| '\n' { print_endline "Newline";NewLine }
| "->" {print_endline "Fleche";Fleche}
| "fn" {print_endline "Fn"; Fn}
| "r#"?['a'-'z''A'-'Z''_']['a'-'z''A'-'Z''_''0'-'9']* as id {print_endline "Id"; Id id}
| '''['a'-'z''A'-'Z''_']['a'-'z''A'-'Z''_''0'-'9']* as etiq {Etiq etiq}  
0

There are 0 best solutions below