By analyzing the design constraints and the update rules, we constructed a simple description of the language to be input to the compiler. There are two options in this design, either to have one compiler for both the constraints and the rules, or to build two compilers, one for each. From the analysis of the constraints and the rules we found that there are many similarities between them; thus building one compiler for both is the logical option in this case.
The following is the language definition in Backus Naur Form (BNF):
<program> :: <constraint-prog> | <rule-prog> <constraint-prog> :: begin-constraints <constraint-sequence> end-constraints <rule-prog> :: begin-rules <rule-sequence> end-rules <constraint-sequence> :: <constraint> ; <constraint-sequence> | <constraint> ; <rule-sequence> :: <rule> ; <rule-sequence> | <rule> ; <constraint> :: <exp> <comparison-op> <exp> <rule> :: <variable> = <exp> <exp> :: <exp> * <term> | <exp> / <term> | <term> <term> :: <term> + <factor> | <term> - <factor> | <factor> <factor> :: <variable> | <constant> | (<exp>) <variable> :: <alphabet> <alphanum> | <alphabet> <constant> :: <int>.<int> | - <int>.<int> | <int> | - <int> <int> :: <digit> <int> | <digit> <alphanum> :: <alphabet> <alphanum> | <digit> <alphanum> | <alphabet> | <digit> <alphabet> :: a..z | A..Z | _ <digit> :: 0..9 <comparison-op> :: = | < | > | <= | >= | <>
The following is an example of some constraints described using this syntax:
begin-constraints link1_length > 1.2 ; link2_length > 1.5 ; link3_length > 0.8 ; link2_length + link3_length < MAX_TOT_LEN ; link1_mass < 1.4 ; link2_mass + link3_mass < 4.0 ; joint1_gear_ratio < 5.0 ; end-constraints
Another example showing some update rules using the same syntax:
begin-rules link1_mass = link1_length * link1_density * link1_cross_area ; link2_mass = link2_length * link2_density * link2_cross_area ; link3_mass = link3_length * link3_density * link3_cross_area ; joint1_gear_ratio = motor1_speed / link1_max_speed ; end-rules
From these examples it is clear that adding arrays to this language can reduce the length of the programs, but given the fact that these constraints and rules will be entered once at installation time, then adding or changing these rules and constraints will not be so frequent, thus, we will not complicate the compiler, at least in the first design phase. Some error detection and recovery modules for syntax error handling can be added to this compiler later.