| 1 |
wakaba |
1.1 |
<!DOCTYPE HTML> |
| 2 |
|
|
<html lang=en> |
| 3 |
|
|
<title>SAMI LR(1) Parser Generator</title> |
| 4 |
|
|
<link rel=stylesheet href="http://suika.fam.cx/www/style/html/xhtml"> |
| 5 |
|
|
<style> |
| 6 |
|
|
output { |
| 7 |
|
|
display: block; |
| 8 |
|
|
white-space: pre; |
| 9 |
|
|
} |
| 10 |
|
|
textarea { |
| 11 |
|
|
height: 10em; |
| 12 |
|
|
} |
| 13 |
|
|
p, output { |
| 14 |
|
|
text-indent: 0; |
| 15 |
|
|
} |
| 16 |
|
|
</style> |
| 17 |
|
|
|
| 18 |
|
|
<h1>LR(1) Parser Generator</h1> |
| 19 |
|
|
|
| 20 |
|
|
<p><label><strong>Grammer</strong>:<br> |
| 21 |
|
|
<textarea id=grammer></textarea></label> |
| 22 |
|
|
|
| 23 |
|
|
<p><label><strong>Parsing table (as text)</strong>:<br> |
| 24 |
|
|
<textarea id=parsing-table-text></textarea></label> |
| 25 |
|
|
|
| 26 |
|
|
<p><label><strong>Parsing table (as JavaScript object)</strong>:<br> |
| 27 |
|
|
<textarea id=parsing-table-js></textarea></label> |
| 28 |
|
|
|
| 29 |
|
|
<script src="http://suika.fam.cx/www/js/sami/script/sami-core.js"></script> |
| 30 |
|
|
<script src="http://suika.fam.cx/www/js/sami/script/sami-pg.js"></script> |
| 31 |
|
|
<script> |
| 32 |
|
|
SAMI.Global.install (); |
| 33 |
|
|
|
| 34 |
|
|
new SAMI.Observer ('change', $('grammer'), function () { |
| 35 |
|
|
var grammer = $('grammer').value; |
| 36 |
|
|
var pt = SAMI.PG.LR1.rulesStringToParsingTable (grammer, null, function (ev) { |
| 37 |
|
|
SAMI.Element.setTextContent ($('parsing-table-text'), |
| 38 |
|
|
'Error: Unexpected token type {' + ev.token.type + ', ' + ev.token.value + '}; ' + ev.value); |
| 39 |
|
|
}); |
| 40 |
|
|
|
| 41 |
|
|
if (pt) { |
| 42 |
|
|
SAMI.Element.setTextContent ($('parsing-table-text'), pt.toString ()); |
| 43 |
|
|
SAMI.Element.setTextContent ($('parsing-table-js'), pt.toSource ()); |
| 44 |
|
|
} |
| 45 |
|
|
}); |
| 46 |
|
|
|
| 47 |
|
|
</script> |