add_infix : string * int * HOLgrammars.associativity -> unit
<str1> s <str2>
s <t1> <t2>
It is also possible that the choice of string s will result in an ambiguous grammar. This will be marked with a warning. The parser may behave in strange ways if it encounters ambiguous phrases, but will work normally otherwise.
- add_infix ("+", 500, HOLgrammars.LEFT);
> val it = () : unit
- val t = Term`x + y`;
<<HOL message: inventing new type variable names: 'a, 'b, 'c.>>
> val t = `x + y` : term
- dest_comb t; > val it = (`$+ x`, `y`) : term * term
- Term`\$+. x + y`; <<HOL message: inventing new type variable names: 'a, 'b, 'c.>> > val it = `\$+. x + y` : term - dest_abs it; > val it = (`$+`,`x + y`) : term * term
- Term`x + y + z`; <<HOL message: inventing new type variable names: 'a, 'b.>> > val it = `x + y + z` : term - dest_comb it; > val it = (`$+ (x + y)`, `z`) : term * term
- Term`p /\ q + r`; <<HOL message: inventing new type variable names: 'a, 'b.>> > val it = `p /\ q + r` : term - dest_comb it; > val it = (`$/\ p`, `q + r`) : term * term
Lib.try add_infix("-", 500, HOLgrammars.RIGHT);
Exception raised at Parse.add_infix:
Grammar Error: Attempt to have differently associated infixes
(RIGHT and LEFT) at same level
- Lib.try add_infix("-", 900, HOLgrammars.RIGHT);
Exception raised at Parse.add_infix:
Grammar Error: Attempt to have different forms at same level
- add_infix("+", 400, HOLgrammars.RIGHT);
> val it = () : unit
- Term`p + q`;
<<HOL warning: Parse.Term: Grammar ambiguous on token pair + and +,
and probably others too>>
<<HOL message: inventing new type variable names: 'a, 'b, 'c>>
> val it = ``p + q`` : term