parse_smtv2_model_parser.mly 2.32 KB
Newer Older
David Hauzar's avatar
David Hauzar committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
%{
%}

%start <Model_parser.model_element list> output

%token <string> SPACE
%token <string> ATOM
%token STORE
%token CONST
%token AS
%token <string> INT_STR
%token <string> MINUS_INT_STR
%token LPAREN RPAREN
%token EOF
%%

output:
| EOF { [] }
| text_with_spaces LPAREN pairs RPAREN { $3 }

pairs:
| possible_space { [] }
| possible_space LPAREN term SPACE value RPAREN pairs 
24
    { (Model_parser.create_model_element ~name:$3 ~value:$5 ())::$7 }
David Hauzar's avatar
David Hauzar committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

possible_space:
| { "" }
| SPACE { $1 }

term:
| text { $1 }
| LPAREN term_list RPAREN 
    { "(" ^ $2 ^ ")" }

term_list:
| possible_space { $1 }
| possible_space term term_list { $1 ^ $2 ^ $3 }

text:
| MINUS_INT_STR { $1 }
| INT_STR { $1 }
| text_without_int { $1 }

text_without_int:
| ATOM { $1 }
| STORE { "store" }
| CONST { "const"  }
| AS { "as" }

text_with_spaces:
| { "" }
| text { $1 }
| text SPACE text_with_spaces { $1 ^ $2 ^ $3 }

value:
| integer { $1 }
| other_val_str { Model_parser.Other $1 }
| array { Model_parser.Array $1 }

integer:
| INT_STR { Model_parser.Integer $1 }
| LPAREN possible_space MINUS_INT_STR possible_space RPAREN 
    { Model_parser.Integer $3 }

(* Everything that cannot be integer (positive and negative) and array. *)
other_val_str:
| text_without_int { $1 }
| LPAREN possible_space RPAREN { "(" ^ $2 ^ ")" }
| LPAREN possible_space paren_other_val_str RPAREN 
    { "(" ^ $3 ^ ")" }

(* Everything that cannot be negative integer and start of an array  *)
paren_other_val_str:
| other_than_neg_int_and_array_store term_list { $1 ^ $2 }
75 76
| LPAREN possible_space other_than_const_array possible_space RPAREN 
    { "(" ^ $3 ^ ")" }
David Hauzar's avatar
David Hauzar committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

other_than_neg_int_and_array_store:
| INT_STR { $1 }
| ATOM { $1 }
| CONST { "const"  }
| AS { "as" }

other_than_const_array:
| MINUS_INT_STR { $1 }
| INT_STR { $1 }
| CONST { "const"  }

(* Example:
   (store (store ((as const (Array Int Int)) 0) 1 2) 3 4) *)
array:
92 93 94 95 96 97
| LPAREN possible_space 
    LPAREN possible_space 
      AS SPACE CONST possible_space array_skipped_part possible_space 
    RPAREN possible_space 
    integer possible_space 
  RPAREN 
David Hauzar's avatar
David Hauzar committed
98
    { Model_parser.array_create_constant ~value:$13 }
99 100 101 102
| LPAREN possible_space 
    STORE possible_space array possible_space integer SPACE integer
    possible_space 
  RPAREN 
David Hauzar's avatar
David Hauzar committed
103 104 105 106
	{ Model_parser.array_add_element ~array:$5 ~index:$7 ~value:$9 }

array_skipped_part:
| LPAREN term_list RPAREN {}
107