cime-poly-interp.opp.exp 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
File "cime-poly-interp.mly", line 29, characters 7-15:
Warning: the token LEFT_BRA is unused.
File "cime-poly-interp.mly", line 29, characters 16-25:
Warning: the token RIGHT_BRA is unused.
%{

  open Signatures;;
  open Poly_interp;;

  exception Syntax_error of string

  let var s =
    try
      let n = Listutils.index s !current_poly_vars
      in IntPolynomials.var n
    with 
	Not_found -> raise (Syntax_error ("undefined variable "^s))
;;

%}
%start poly_interp_entry
%start weight_entry
%token <string> VAR
%token SEMICOLON
%token RIGHT_PAR
%token RIGHT_BRA
%token LEFT_PAR
%token LEFT_BRA
%token <User_signatures.symbol_id> INTERP
%token <Numbers.t> INT
%token EQUAL
%token EOF
%token COMMA
%token PLUS
%token MINUS
%token MULT
%token EXP
%left PLUS MINUS 
%left MULT 
%nonassoc UMINUS 
%right EXP 
%type <(User_signatures.symbol_id, Poly_interp.IntPolynomials.poly) Signatures.SymbolMap.t > poly_interp_entry
%type <(User_signatures.symbol_id, int) Signatures.SymbolMap.t > weight_entry
%%

poly_interp_entry:
47 48
| _1 = interp _2 = EOF
    {             ( _1 )}
49 50 51

interp:
| 
52 53 54
    {                           ( SymbolMap.empty )}
| _1 = symbol_interp _2 = EQUAL _3 = poly _4 = SEMICOLON _5 = interp
    {                           ( SymbolMap.add _1 _3 _5 )}
55 56

symbol_interp:
57 58 59 60
| _1 = INTERP
    {                            ( current_poly_vars := []; _1 )}
| _1 = INTERP _2 = LEFT_PAR _3 = vars
    {                           ( current_poly_vars := _3; _1 )}
61 62

vars:
63 64 65 66
| _1 = VAR _2 = RIGHT_PAR
    {                           ( [_1] )}
| _1 = VAR _2 = COMMA _3 = vars
    {                           ( _1::_3 )}
67 68

poly:
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| _1 = VAR
    {                           ( var _1 )}
| _1 = INT
    {                           ( IntPolynomials.cte _1 )}
| _1 = LEFT_PAR _2 = poly _3 = RIGHT_PAR
    {                           ( _2 )}
| _1 = poly _2 = PLUS _3 = poly
    {                           ( IntPolynomials.add _1 _3 )}
| _1 = poly _2 = MINUS _3 = poly
    {                           ( IntPolynomials.sub _1 _3 )}
| _1 = MINUS _2 = poly %prec UMINUS
    {                           ( IntPolynomials.minus _2 )}
| _1 = poly _2 = MULT _3 = poly
    {                           ( IntPolynomials.mult _1 _3 )}
| _1 = poly _2 = EXP _3 = INT
    {    ( try
	IntPolynomials.power _1 (Numbers.to_int _3) 
86 87 88
      with 
	Failure("int_of_big_int") ->
	  failwith "Exponent too large"
89
    )}
90 91

weight_entry:
92 93
| _1 = weight _2 = EOF
    {             ( _1 )}
94 95 96

weight:
| 
97 98 99
    {                             ( SymbolMap.empty )}
| _1 = INTERP _2 = EQUAL _3 = INT _4 = SEMICOLON _5 = weight
    {                                    ( SymbolMap.add _1 (Numbers.to_int _3) _5 )}
100 101 102 103 104

%%