///// // Musa Al-hassy // January 2017 // McMaster University ///// /* * This is header is for an embedded domain specific language: Dijkstra's guarded command language. * * In doubt, run * * gcc -E myfile.c * * to and look at the offending line to find out what's wrong! */ #include // to use exit(n) #define bool int // it's probably better to use a typedef.. #define true 1 #define false 0 #define BEGIN { #define END } #define TERMINATOR ; // notice the lack of trailing/terminating semi-colons at the end of driver-code ;) // we're mimicking GCL guarded statements and so using their approach to // semicolons as separators, for sequencing, rather than terminators #define IF if (false) { #define FI TERMINATOR END else {exit(EXIT_FAILURE);} // end the IF-many and end the recent most then-clause // NEEDS TO crash/abort if none of the guards work! As per GCL specs! // "guard B then S" ~~> " } else if (B) {S " #define guard TERMINATOR END else if ( #define has ) BEGIN #define DO while(true) BEGIN IF #define OD TERMINATOR END else break; END // end previous guard, end the IF, exit loop, end loop body // type agnostic swap operation #define swap(x, y) { typeof(x) temp = x; x = y; y = temp; }