|
| 1 | +%token EOF NEWLINE SEMICOLON COMMA DOT OP_PAR CL_PAR OP_CUR CL_CUR AT TYPE LAR |
| 2 | +%token GREATER SMALLER TRUE FALSE DIFF KAPPA_RAR KAPPA_LRAR KAPPA_LNK PIPE |
| 3 | +%token INIT OBS KAPPA_WLD KAPPA_SEMI |
| 4 | +%token <int> INT |
| 5 | +%token <string> ID |
| 6 | +%token <string> KAPPA_MRK LABEL |
| 7 | +%token <float> FLOAT |
| 8 | +%token <string> STRING |
| 9 | +%start newline |
| 10 | +%type <Ast.t> newline |
| 11 | +%% |
| 12 | + |
| 13 | +newline: |
| 14 | + | start_rule NEWLINE {$1} |
| 15 | +; |
| 16 | + |
| 17 | +start_rule: |
| 18 | + | rule_expression {$1} |
| 19 | + | instruction {$1} |
| 20 | + | error |
| 21 | + {raise (ExceptionDefn.Syntax_Error("start_rule"))} |
| 22 | + ; |
| 23 | + |
| 24 | +rule_expression: |
| 25 | + | rule_label lhs_rhs arrow lhs_rhs |
| 26 | + { Ast.RULE ($1,({Ast.lhs=$2; Ast.bidirectional=$3; |
| 27 | + Ast.rhs=$4;}))} |
| 28 | + ; |
| 29 | + |
| 30 | +arrow: |
| 31 | + | KAPPA_RAR {false} |
| 32 | + | KAPPA_LRAR {true} |
| 33 | + ; |
| 34 | + |
| 35 | +rule_label: |
| 36 | + | LABEL {$1} |
| 37 | + ; |
| 38 | + |
| 39 | +instruction: |
| 40 | + | INIT init_declaration {$2} |
| 41 | + | INIT error |
| 42 | + { raise (ExceptionDefn.Syntax_Error("Malformed initial condition"))} |
| 43 | + | OBS variable_declaration {$2} |
| 44 | + ; |
| 45 | + |
| 46 | +variable_declaration: |
| 47 | + | LABEL non_empty_mixture {Ast.OBS ($1,$2)} |
| 48 | +; |
| 49 | + |
| 50 | +init_declaration: |
| 51 | + | non_empty_mixture {(Ast.INIT $1)} |
| 52 | + ; |
| 53 | + |
| 54 | +lhs_rhs: |
| 55 | + mixture {$1}; |
| 56 | + |
| 57 | +mixture: |
| 58 | + /*empty*/ {[]} |
| 59 | + | non_empty_mixture {$1} |
| 60 | +; |
| 61 | + |
| 62 | +non_empty_mixture: |
| 63 | + | OP_PAR non_empty_mixture CL_PAR {$2} |
| 64 | + | agent_expression COMMA non_empty_mixture {$1 :: $3} |
| 65 | + | agent_expression {[$1]} |
| 66 | + ; |
| 67 | + |
| 68 | +agent_expression: |
| 69 | + | ID OP_PAR interface_expression CL_PAR {($1,$3)} |
| 70 | + | ID error |
| 71 | + { raise (ExceptionDefn.Syntax_Error("Malformed agent '"^$1^"'"))} |
| 72 | + ; |
| 73 | + |
| 74 | +interface_expression: |
| 75 | + /*empty*/ {[]} |
| 76 | + | ne_interface_expression {$1} |
| 77 | + ; |
| 78 | + |
| 79 | +ne_interface_expression: |
| 80 | + | port_expression COMMA ne_interface_expression {$1::$3} |
| 81 | + | port_expression {[$1]} |
| 82 | + ; |
| 83 | + |
| 84 | +port_expression: |
| 85 | + | ID internal_state link_state |
| 86 | + {{Ast.port_nme=$1; Ast.port_int=$2; Ast.port_lnk=$3}} |
| 87 | + ; |
| 88 | + |
| 89 | +internal_state: |
| 90 | + /*empty*/ {[]} |
| 91 | + | KAPPA_MRK internal_state {$1::$2} |
| 92 | + | error |
| 93 | + {raise (ExceptionDefn.Syntax_Error ("Invalid internal state"))} |
| 94 | + ; |
| 95 | + |
| 96 | +link_state: |
| 97 | + /*empty*/ {[]} |
| 98 | + | KAPPA_LNK INT link_state {(Ast.LNK_VALUE $2)::$3} |
| 99 | + | KAPPA_LNK KAPPA_SEMI link_state {(Ast.LNK_SOME)::$3} |
| 100 | + | KAPPA_LNK ID DOT ID link_state {(Ast.LNK_TYPE($2,$4))::$5} |
| 101 | + | KAPPA_WLD link_state {(Ast.LNK_ANY)::$2} |
| 102 | + | KAPPA_LNK error |
| 103 | + {raise (ExceptionDefn.Syntax_Error("Invalid link state"))} |
| 104 | +; |
0 commit comments