Presentation is loading. Please wait.

Presentation is loading. Please wait.

Catriel Beeri Pls/Winter 2004/5 interpreters 1 Language processors for EL  An interpreter transEval from  An interpreter natEval from An important theme:

Similar presentations


Presentation on theme: "Catriel Beeri Pls/Winter 2004/5 interpreters 1 Language processors for EL  An interpreter transEval from  An interpreter natEval from An important theme:"— Presentation transcript:

1 Catriel Beeri Pls/Winter 2004/5 interpreters 1 Language processors for EL  An interpreter transEval from  An interpreter natEval from An important theme: deriving interpreters directly from the rules

2 Catriel Beeri Pls/Winter 2004/5 interpreters 2  Deriving an interpreter from We derive: next (a stepper) for each E, next(E) = E’, where E -- the goal, E’ -- the solution A full interpreter: transEval -- drives next until final (extended) value is obtained

3 Catriel Beeri Pls/Winter 2004/5 interpreters 3 How does next work: Check on goal E the conditions of previous chapter, determine the applicable group of rules An axiom group: –Check more conditions –Apply unique applicable axiom A proper rule group: –Determine E1 -- 1 st step down on selection path –Call (recursively) next(E1) –Given its solution E’1, construct the solution E’ Note: E=E0, E1, … En -- the goals of the calls – the selection path E0  E’0, … En  E’n -- the labels of the proof tree (virtual construction)

4 Catriel Beeri Pls/Winter 2004/5 interpreters 4

5 Catriel Beeri Pls/Winter 2004/5 interpreters 5 Examples: 2 + 3 4/0 2 4 (2 * 3) + 4 (2 3) + 4

6 Catriel Beeri Pls/Winter 2004/5 interpreters 6 Example tuple i = 1 Apply-op (3,5) * app-rand: applic A non-value applic next((3+5,4-5)) next(3+5) builtIn(+, (3,5)) 8 8 (8,4-5) A value

7 Catriel Beeri Pls/Winter 2004/5 interpreters 7 In what sense is next “derived from the rules? How much is routine derivation/ human analysis ? 1. find applicable rules for E: Primary construct C of E selects rules --- how? compare C to primary construct is each rule’s head left part – rule head goal pattern (why pattern?) applic

8 Catriel Beeri Pls/Winter 2004/5 interpreters 8 2. check conditions, narrow set of applicable rules: need to associate direct sub-expressions with variables in the goal patterns --- why & how? Convenience: make the conditions explicit in the rules Variable assignment identifies which sub-expressions are to be checked 2 nd condition fails  rule is disqualified applic

9 Catriel Beeri Pls/Winter 2004/5 interpreters 9 3. proper rule --- generate new goal: The binding of direct sub-expressions to variables instantiates the rule’s transition premise goal The call next((3+5,4-2)) is generated applic

10 Catriel Beeri Pls/Winter 2004/5 interpreters 10 4. recursive call returns --- generate solution: The binding is extended by the recursive solution, instantiate the rules’s head solution pattern The call next((3+5,4-2)) is generated It returns (8,4-2), which is bound to Now the solution is returned applic

11 Catriel Beeri Pls/Winter 2004/5 interpreters 11 Summary: Pattern match of E with goal patterns of rules –excludes some rules –For a remaining rule, binds variables in its goal pattern to E’s direct sub-expressions Binding  check conditions  more rules excluded If remaining rule is an axiom, solution is generated If a proper rule, –Binding used to generate a recursive call –Its solution extends the variable assignment –Binding for head solution pattern is now full, solution is generated

12 Catriel Beeri Pls/Winter 2004/5 interpreters 12 Comments: Actually, after checking, several rules remain –Either all proper, or all axioms –when proper, all generates same new goal (we are lucky!) When a recursive call returns ER, the data flow described above is short-circuited – how? Our description of derivation from the rules is complete but there is still one bothersome detail

13 Catriel Beeri Pls/Winter 2004/5 interpreters 13 Look at the first clause

14 Catriel Beeri Pls/Winter 2004/5 interpreters 14 The condition is not written in the rule! Here, human analysis was used What would be the algorithm if only the conditions in the rules were used? discussion An advantage of deriving from the rules: the rules are a declarative specification of the algorithm Can we change the rules so human analysis is not required for the derivation?

15 Catriel Beeri Pls/Winter 2004/5 interpreters 15 An algorithmic version of the rules (apply-op-a) (applic-rator-a) (applic-rand-a) (tup-eval) ……. If + errors rules are left to you (make the conditions explicit)

16 Catriel Beeri Pls/Winter 2004/5 interpreters 16  Deriving natEval from accepts goal E, returns its (extended) value – the solution Same principles, some differences: Rules have several evaluation premises  several recursive calls per rule When binding for the head goal allows several new goals, the order of calls is arbitrary (but select order to check conditions as early as possible!) When several rules are potentially applicable, a new goal common to all is generated first

17 Catriel Beeri Pls/Winter 2004/5 interpreters 17

18 Catriel Beeri Pls/Winter 2004/5 interpreters 18 Which of transEval, natEval is simpler to write, more efficient? How can we improve, by eliminating some of the analysis/recursive calls?


Download ppt "Catriel Beeri Pls/Winter 2004/5 interpreters 1 Language processors for EL  An interpreter transEval from  An interpreter natEval from An important theme:"

Similar presentations


Ads by Google