pace_like_guard { drive Move drive blocked blocked Turn Left once_left once_left Turn Left twice_left twice_left Turn Left drive }
pace_like_guard (turn_dir) {
drive Move drive blocked
blocked Turn turn_dir once
once Turn turn_dir twice
twice Turn turn_dir drive
}
and then called this with either
&pace_like_guard (Left)
or
&pace_like_guard (Right).
Though this quite a silly example we can show how the example program given in the task description is written with the use of macros in the phec langauge.
random_search { search (desire, return_address) { search Sense Ahead return_address not_found desire not_found Choose (links, recht, gerade) links Turn TurnLeft search recht Turn TurnRight search gerade Move search not_found } search_for_food &search (Food, found_food) found_food PickUp go_home search_for_foodgo_home &search (Home, found_home) found_home Drop search_for_food }
The search macro will search for the desired condition, here it is applied searching for food and then searching for home. This example also demonstrates that we now have a very primitive form of procedure, since the return address can be passed in as a parameter.
simple_beahaviour { search (desire) { search Sense Ahead found not_found desire not_found Choose (links, recht, gerade) links Turn TurnLeft search recht Turn TurnRight search gerade Move search not_found found If desire = Food Then { collect PickUp go_home search_for_food } Else { drop_food Drop search_for_food} } search_for_food &search (Food) go_home &search (Home) }
Program ::= <LabeledStatments>*LabeledStatments ::= label <Statement>
Statement ::= '{' <Program> '}' -- Block | '('label*')' '{' <Program> '}' -- Macro | &label label '(' <Identifier>* ')' -- MacroUse | Choose '('label*')' -- comma seperated | If <BoolExpr> Then { <Program> } Else { <Program> } | Sense <SenseDir> label label <Condition> | Mark <Mark> label | Unmark <Mark> label | PickUp label label | Drop label | Turn <TurnDir> label | Move label label | Flip <Num> label label
Mark ::= Mark0 | Mark1 | Mark2 | Mark3 | Mark4 | Mark5 Marker ::= Marker0 | Marker1 | Marker2 | Marker3 | Marker4 | Marker5 TurnDir ::= {Left | Right} Num ::= 0..
BoolExpr ::= (<BoolExpr>) | <BoolExpr> && <BoolExpr> | <BoolExpr> || <BoolExpr> | <Identifier> = <Identifier>
Identifier ::= {<SenseDir> | <TurnDir> | <Condition> | <Marker> | <Mark> | label}
Condition ::= Friend | Foe | FriendWithFood | FoeWithFood | Food | Rock | <Marker> | FoeMarker | Home | FoeHome
SenseDir ::= Here | Ahead | Left | Right
Commenting is in Haskell syntax: -- for one line comment {- for multiple line comment -} comments can be nested.
#include file.phec -- includes file.phec at this position#times (Var) (Num) abitrary contents with some $<ExprWithVar>$ in which are evaluated for each copy of the block #endtimes
where
ExprWithVar ::= Var | Number | (<ExprWithVar>)
| <ExprWithVar> '*' <ExprWithVar>
| <ExprWithVar> '/' <ExprWithVar>
| <ExprWithVar> '%' <ExprWithVar>
| <ExprWithVar> '+' <ExprWithVar>
| <ExprWithVar> '-' <ExprWithVar>
| <ExprWithVar> '|' <ExprWithVar>
| <ExprWithVar> '&' <ExprWithVar>
| <ExprWithVar> '==' <ExprWithVar>
| <ExprWithVar> '/=' <ExprWithVar>
| <ExprWithVar> '<<' <ExprWithVar>
| <ExprWithVar> '>>' <ExprWithVar>
Content
Powered by SnipSnap 1.0b2-uttoxeter