diff options
author | Camil Staps | 2015-07-03 21:27:40 +0200 |
---|---|---|
committer | Camil Staps | 2015-07-03 21:35:56 +0200 |
commit | 47207894bda7f106ef685fe19738ae3d27f27041 (patch) | |
tree | 1ce93eb87da9551c422d96750d0d30fc634885be | |
parent | Readme (diff) |
html+php wrapper
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | index.html | 80 | ||||
-rw-r--r-- | request.php | 45 |
3 files changed, 130 insertions, 1 deletions
@@ -108,7 +108,7 @@ The `truthtable` of `e15`: The `parse` function may be used to read an expression from a String. The following rules are used: - * Whitespace is ignored. + * Spaces are ignored. * All latin letters (`[a-zA-Z]`) are considered atomic expressions * Operators are expected in their representation described above * True and False are expected as `1` and `0`, respectively @@ -140,6 +140,10 @@ The option `-e` tells the parser to show the extended truth table. With this opt True | False | True | False True | True | True | True +## Web frontend + +There is a simple web frontend in PHP and a basic HTML template which allows one to connect to the Clean application through his browser. The files for this are `index.html` and `request.php`, and a demo may be found on https://demo.camilstaps.nl/CleanLogic. + ## Future ideas * Different `toString` formats for operators: HTML (`¬`), UTF-8 (¬), LaTeX (`\neg`) diff --git a/index.html b/index.html new file mode 100644 index 0000000..ef717e5 --- /dev/null +++ b/index.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>CleanLogic</title> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> + <style type="text/css"> + textarea { + font-family: monospace; + resize: vertical; + width: 100%; + } + + textarea#expressions { + height: 200px; + } + + textarea#truthtable { + height: 400px; + } + </style> + </head> + <body> + <div class="container"> + <h1>CleanLogic</h1> + <p class="lead">Logic toolbox in <a href="http://clean.cs.ru.nl/Clean" target="_blank">Clean</a></p> + <p>Copyright © 2015 Camil Staps. This project is licensed under the MIT license. For more details, see the <a href="LICENSE" target="_blank">LICENSE</a> file.</p> + <p>This project is maintained on <a href="https://github.com/camilstaps/CleanLogic" target="_blank">GitHub</a>. For more information, see the <a href="README.md">readme file</a>.</p> + + <hr/> + + <div class="row"> + <div class="col-md-3"> + <h2>Expressions</h2> + <p>Enter expressions here, one per line:</p> + <textarea class="form-control" id="expressions">p & q -> q & p</textarea> + <a href="#legend" data-toggle="collapse" class="pull-right">Legend</a><br/> + <div class="collapse" id="legend"> + <table class="table table-condensed table-striped"> + <tr><th>Name</th><th>Normally</th><th>Here</th></tr> + <tr><td>Negation</td><td>¬</td><td><code>~</code></td></tr> + <tr><td>Conjunction</td><td>∧</td><td><code>&</code></td></tr> + <tr><td>Disjunction</td><td>∨</td><td><code>|</code></td></tr> + <tr><td>Implication</td><td>→</td><td><code>-></code></td></tr> + <tr><td>Equivalence</td><td>↔</td><td><code><-></code></td></tr> + </table> + </div> + <div class="checkbox"><label for="extended" title="Display intermediate steps (max. one expression)"><input type="checkbox" id="extended"> Intermediate steps</label></div> + <button class="btn btn-primary" id="view">View</button> + </div> + <div class="col-md-9"> + <h2>Truth table</h2> + <p>Truth tables are generated with a server-side <a href="http://clean.cs.ru.nl/Clean" target="_blank">Clean</a> program.</p> + <textarea class="form-control" id="truthtable"></textarea> + </div> + </div> + </div> + + <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> + <script> + $('#view').click(function(){ + console.log($('#expressions').val().split("\n")); + $.ajax({ + url: 'request.php', + data: { + extended: $('#extended').prop('checked'), + expressions: $('#expressions').val().split("\n") + }, + success: function (data) { + $('#truthtable').val(data); + } + }); + }).trigger('click'); + </script> + </body> +</html> diff --git a/request.php b/request.php new file mode 100644 index 0000000..2465f5a --- /dev/null +++ b/request.php @@ -0,0 +1,45 @@ +<?php +/** + * The MIT License (MIT) + * + * Copyright (c) 2015 Camil Staps + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +header('Content-type: text/plain'); + +$extended = isset($_GET['extended']) && $_GET['extended'] != 'false'; +$expressions = $_GET['expressions']; + +if ($expressions == []) + die('Not enough expressions requested'); + +foreach ($expressions as $k => $e) + if (preg_match('/[^a-zA-Z\|\&~\-><01 ]/', $e)) + die('Forbidden character in expression ' . $e); + +$expressions = array_map('escapeshellarg', $expressions); +$expressions = implode(' ', $expressions); +$extended = $extended ? '-e' : ''; + +$call = './LogicParser -b -nt ' . $extended . ' ' . $expressions; + +passthru($call); + |