The goal of this question is to learn about a variation of event-driven programming language features. A

Question:

The goal of this question is to learn about a variation of event-driven programming language features. A common variation of event support in languages and libraries allows programmers to specify a priority among observers, and the observers run according to the specified priority. A common usage of priority among observers is to prevent low-priority observers from blocking higher-priority observers, or to ensure that the higher-priority observers finish their task.

In the current semantics of Eventlang, the when expression registers observer expressions to run when an event is signaled. The current syntax of this expression does not allow priorities within observer expressions. Observer expressions are executed in the order in which they are registered at run time; that is, the observer expression’s execution order is the same as its dynamic registration order.

Modify the syntax, AST, and semantics of the when expression to the following:whenexp: '('When exp Do exp (exp)? ')';

such that the last optional expression in the syntax must evaluate to a number between 0 and 10, which specifies the priority of the observer expression. In other words, the first expression exp evaluates to an EventVal, the second expression is the observer body, and the third expression evaluates to the observer priority, which is a number between 0 and 10.


When a priority is not given, it is assumed to be 5; that is, the when expression of the form (when ev do (+ a b)) is the same as the when expression (when ev do (+ a b) 5).

Modify the semantics of the event announcement (i.e., the semantics of the announce expression) such that it runs observer expressions in the order of their priority from 0-10. All observers that have the same priority are run in the order in which they are registered.

Some examples illustrating this new semantics appear here:$ (define ev (event (a b))) $(when ev do (+ a b) 0) $ (when ev do (* a b) 1) $ (announce ev (23)) 6 $(when ev

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: