| 1 |
(* predict.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2006 |
| 4 |
* John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 5 |
* Aaron Turon (http://www.cs.uchicago.edu/~adrassi) |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Decision trees for predictions. |
| 9 |
*) |
| 10 |
|
| 11 |
structure Predict = |
| 12 |
struct |
| 13 |
|
| 14 |
structure S = LLKSpec |
| 15 |
structure TSet = Token.Set |
| 16 |
|
| 17 |
datatype 'a tree |
| 18 |
= Pick of 'a |
| 19 |
| ByTok of (TSet.set * 'a tree) list |
| 20 |
| Choice of 'a list (* try each in order *) |
| 21 |
(* | Error of TSet.set *) |
| 22 |
|
| 23 |
datatype predict_maps = PMaps of { |
| 24 |
prodPredict : S.nonterm -> S.prod tree, |
| 25 |
ebnfPredict : S.nonterm -> bool tree |
| 26 |
} |
| 27 |
|
| 28 |
fun toString aToS tree = let |
| 29 |
fun tos (i, Pick a) = "PICK " ^ (aToS a) |
| 30 |
| tos (i, ByTok branches) = "\n" ^ i ^ |
| 31 |
(String.concatWith ("\n" ^ i) |
| 32 |
(map (fn (s, t) => (Token.setToString s) ^ " => " ^ |
| 33 |
tos (i ^ " ", t)) branches)) |
| 34 |
in |
| 35 |
tos ("", tree) |
| 36 |
end |
| 37 |
|
| 38 |
end |