mcc-prof.opp.exp 3.12 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
File "mcc-prof.mly", line 50, characters 23-32:
Warning: the token TokOutput is unused.
%{
open Prof_parse_state
open Prof_type

let pos_of_single = function
     VarExpr (_, pos)
   | NumExpr (_, pos)
   | PlusExpr (_, _, pos)
   | MinusExpr (_, _, pos)
   | DivExpr (_, _, pos)
   | MultExpr (_, _, pos)
   | Average (_, pos)
   | PrintExpr (_, pos) ->
      pos

%}
%start main
%token <string * Prof_type.pos> TokString
%token <Prof_type.pos> TokSemi
%token <Prof_type.pos> TokRightParen
%token <Prof_type.pos> TokRightBrack
%token <Prof_type.pos> TokPrint
%token <Prof_type.pos> TokPercentages
%token <Prof_type.pos> TokOutput
%token <Prof_type.pos> TokLeftParen
%token <Prof_type.pos> TokLeftBrack
%token <int * Prof_type.pos> TokInt
%token <Symbol.symbol * Prof_type.pos> TokId
%token <float * Prof_type.pos> TokFloat
%token TokEof
%token <Prof_type.pos> TokComma
%token <Prof_type.pos> TokAverage
%token <Prof_type.pos> TokPlus
%token <Prof_type.pos> TokMinus
%token <Prof_type.pos> TokMult
%token <Prof_type.pos> TokDiv
%left TokPlus TokMinus 
%left TokMult TokDiv 
%type <Prof_type.expr list> main
%%

main:
45 46
| _1 = expr_list _2 = TokEof
    {                              ( _1 )}
47 48

expr_list:
49 50 51 52
| _1 = expr
    {                              ( [_1] )}
| _1 = expr_list _2 = TokSemi _3 = expr
    {                              ( _1 @ [_3] )}
53 54

expr:
55 56 57 58
| _1 = item
    {                              ( Single _1 )}
| _1 = multi
    {                              ( Multi _1 )}
59 60

item:
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| _1 = TokId
    {                              ( VarExpr (fst _1, snd _1) )}
| _1 = item _2 = TokPlus _3 = item
    {                              ( PlusExpr (_1, _3, union_pos (pos_of_single _1) (pos_of_single _3)) )}
| _1 = item _2 = TokMinus _3 = item
    {                              ( MinusExpr (_1, _3, union_pos (pos_of_single _1) (pos_of_single _3)) )}
| _1 = item _2 = TokDiv _3 = item
    {                              ( DivExpr (_1, _3, union_pos (pos_of_single _1) (pos_of_single _3)) )}
| _1 = item _2 = TokMult _3 = item
    {                              ( MultExpr (_1, _3, union_pos (pos_of_single _1) (pos_of_single _3)) )}
| _1 = TokLeftParen _2 = item _3 = TokRightParen
    {                              ( _2 )}
| _1 = item_result
    {                              ( _1 )}
| _1 = TokInt
    {                              ( NumExpr (float_of_int (fst _1), snd _1) )}
| _1 = TokFloat
    {                              ( NumExpr (fst _1, snd _1) )}
79 80

item_list:
81 82 83 84
| _1 = item
    {                              ( [_1] )}
| _1 = item_list _2 = TokComma _3 = item
    {                              ( _1 @ [_3] )}
85 86

item_result:
87 88 89 90
| _1 = TokAverage _2 = TokLeftParen _3 = multi _4 = TokRightParen
    {                              ( Average (_3, union_pos _1 _4) )}
| _1 = TokPrint _2 = TokLeftParen _3 = TokString _4 = TokRightParen
    {                              ( PrintExpr (fst _3, snd _3) )}
91 92

multi:
93 94 95 96
| _1 = TokPercentages _2 = TokLeftParen _3 = multi _4 = TokRightParen
    {                              ( Percentages (_3, union_pos _1 _4) )}
| _1 = TokLeftBrack _2 = item_list _3 = TokRightBrack
    {                              ( ListExpr (_2, union_pos _1 _3) )}
97 98 99 100 101

%%