parsing - An error of parser -


i writing compiler in ocaml. want realize that:

program test; var    a,b : boolean;    n : integer; name    ([2,3], [4,5]) : boolean;    ([7,8], [9,10]), ([12,13], [14,15]) : integer;   begin    ... end. 

actually, each of programs contains 2-dimensional array. ([2,3], [4,5]) : boolean declares elements in [2,3]x[4,5] boolean.

my question how let parser read declaration of names, here sib_parser.mly , sib_syntax.ml. compile well, when test binary program, throws error of parser. help? thank much!

you need factorize code bit; rules show not ugly hell read, have lot of redundancy in them. example, 2 rules same, except latter terminal; have factorized part out specific rule:

type_name: | integer { st_int } | boolean { st_bool } 

to answer question, parameters in parametrized rules applications cannot sequence of terminal (what should whole thing return ?), 1 "actual" either terminal, non-terminal, or application of parametrized rule. forces break grammar separate productions, good.

%inline couple(open_sep,x,close_sep): | open_sep x1 = x comma x2 = x close_sep { (x1, x2) }  rectangle: | rect = couple(lparen, couple(lbracket, int, rbracket), rparen) { rect }  type_name: | integer { st_int } | boolean { st_bool }  binding_names: | ids_names = separated_nonempty_list (comma, rectangle) colon ty = type_name     { [] (* put want here *) } 

in case, rectangle returns (int * int) * (int * int).

ps: if encounter similar error again, not hesitate read menhir documentation (pdf).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -