z66is

Untitled

Jan 15th, 2026
317
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 9.80 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Compile to Lisp</title>
  7.     <style>
  8.         * {
  9.             margin: 0;
  10.             padding: 0;
  11.             box-sizing: border-box;
  12.         }
  13.        
  14.         body {
  15.             font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  16.             background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  17.             min-height: 100vh;
  18.             padding: 20px;
  19.             display: flex;
  20.             justify-content: center;
  21.             align-items: center;
  22.         }
  23.        
  24.         .container {
  25.             background: white;
  26.             border-radius: 12px;
  27.             box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  28.             max-width: 1200px;
  29.             width: 100%;
  30.             padding: 30px;
  31.         }
  32.        
  33.         h1 {
  34.             color: #333;
  35.             margin-bottom: 10px;
  36.             text-align: center;
  37.         }
  38.        
  39.         .description {
  40.             text-align: center;
  41.             color: #666;
  42.             margin-bottom: 30px;
  43.             font-size: 14px;
  44.         }
  45.        
  46.         .editor-container {
  47.             display: grid;
  48.             grid-template-columns: 1fr 1fr;
  49.             gap: 20px;
  50.             margin-bottom: 20px;
  51.         }
  52.        
  53.         .editor-section {
  54.             display: flex;
  55.             flex-direction: column;
  56.         }
  57.        
  58.         .editor-header {
  59.             display: flex;
  60.             justify-content: space-between;
  61.             align-items: center;
  62.             margin-bottom: 10px;
  63.         }
  64.        
  65.         .editor-label {
  66.             font-weight: 600;
  67.             color: #333;
  68.             font-size: 16px;
  69.         }
  70.        
  71.         textarea {
  72.             width: 100%;
  73.             height: 400px;
  74.             padding: 15px;
  75.             border: 2px solid #e0e0e0;
  76.             border-radius: 8px;
  77.             font-family: 'Courier New', monospace;
  78.             font-size: 14px;
  79.             resize: vertical;
  80.             transition: border-color 0.3s;
  81.         }
  82.        
  83.         textarea:focus {
  84.             outline: none;
  85.             border-color: #667eea;
  86.         }
  87.        
  88.         #output {
  89.             background-color: #f8f9fa;
  90.         }
  91.        
  92.         .button-group {
  93.             display: flex;
  94.             gap: 10px;
  95.             justify-content: center;
  96.             flex-wrap: wrap;
  97.         }
  98.        
  99.         button {
  100.             padding: 12px 30px;
  101.             border: none;
  102.             border-radius: 6px;
  103.             font-size: 16px;
  104.             font-weight: 600;
  105.             cursor: pointer;
  106.             transition: all 0.3s;
  107.             box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  108.         }
  109.        
  110.         .btn-compile {
  111.             background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  112.             color: white;
  113.         }
  114.        
  115.         .btn-compile:hover {
  116.             transform: translateY(-2px);
  117.             box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  118.         }
  119.        
  120.         .btn-copy {
  121.             background: #28a745;
  122.             color: white;
  123.         }
  124.        
  125.         .btn-copy:hover {
  126.             background: #218838;
  127.             transform: translateY(-2px);
  128.             box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  129.         }
  130.        
  131.         .btn-clear {
  132.             background: #dc3545;
  133.             color: white;
  134.         }
  135.        
  136.         .btn-clear:hover {
  137.             background: #c82333;
  138.             transform: translateY(-2px);
  139.             box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  140.         }
  141.        
  142.         .btn-example {
  143.             background: #17a2b8;
  144.             color: white;
  145.         }
  146.        
  147.         .btn-example:hover {
  148.             background: #138496;
  149.             transform: translateY(-2px);
  150.             box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  151.         }
  152.        
  153.         .notification {
  154.             position: fixed;
  155.             top: 20px;
  156.             right: 20px;
  157.             padding: 15px 25px;
  158.             background: #28a745;
  159.             color: white;
  160.             border-radius: 6px;
  161.             box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  162.             opacity: 0;
  163.             transform: translateY(-20px);
  164.             transition: all 0.3s;
  165.             pointer-events: none;
  166.             z-index: 1000;
  167.         }
  168.        
  169.         .notification.show {
  170.             opacity: 1;
  171.             transform: translateY(0);
  172.         }
  173.        
  174.         @media (max-width: 768px) {
  175.             .editor-container {
  176.                 grid-template-columns: 1fr;
  177.             }
  178.            
  179.             textarea {
  180.                 height: 250px;
  181.             }
  182.            
  183.             .container {
  184.                 padding: 20px;
  185.             }
  186.         }
  187.     </style>
  188. </head>
  189. <body>
  190.     <div class="container">
  191.         <h1>🔄 Compile to Lisp</h1>
  192.         <p class="description">
  193.             Transforms brackets: replaces '[' with '(' and appends ')' for each '[' at the end of each line
  194.         </p>
  195.        
  196.         <div class="editor-container">
  197.             <div class="editor-section">
  198.                 <div class="editor-header">
  199.                     <span class="editor-label">📝 Input</span>
  200.                 </div>
  201.                 <textarea id="input" placeholder="Paste your code here..."></textarea>
  202.             </div>
  203.            
  204.             <div class="editor-section">
  205.                 <div class="editor-header">
  206.                     <span class="editor-label">✨ Output</span>
  207.                 </div>
  208.                 <textarea id="output" readonly placeholder="Compiled output will appear here..."></textarea>
  209.             </div>
  210.         </div>
  211.        
  212.         <div class="button-group">
  213.             <button class="btn-compile" onclick="compileCode()">🚀 Compile</button>
  214.             <button class="btn-copy" onclick="copyOutput()">📋 Copy Output</button>
  215.             <button class="btn-example" onclick="loadExample()">💡 Load Example</button>
  216.             <button class="btn-clear" onclick="clearAll()">🗑️ Clear All</button>
  217.         </div>
  218.     </div>
  219.    
  220.     <div class="notification" id="notification">Copied to clipboard!</div>
  221.    
  222.     <script>
  223.         // Transform a string: replace '[' with '(' and append one ')' per '[' at end of each line.
  224.        
  225.         function splitLines(s) {
  226.             const lines = [];
  227.             let currentLine = "";
  228.            
  229.             for (let i = 0; i < s.length; i++) {
  230.                const ch = s[i];
  231.                if (ch === '\n') {
  232.                    lines.push(currentLine);
  233.                    currentLine = "";
  234.                } else {
  235.                    currentLine += ch;
  236.                }
  237.            }
  238.            
  239.            // Don't forget the last line if it doesn't end with newline
  240.            lines.push(currentLine);
  241.            
  242.            return lines;
  243.        }
  244.        
  245.        function countChar(s, target) {
  246.            let count = 0;
  247.            for (let i = 0; i < s.length; i++) {
  248.                if (s[i] === target) {
  249.                    count++;
  250.                }
  251.            }
  252.            return count;
  253.        }
  254.        
  255.        function replaceBrackets(s) {
  256.            let result = "";
  257.            for (let i = 0; i < s.length; i++) {
  258.                const ch = s[i];
  259.                result += (ch === '[') ? '(' : ch;
  260.            }
  261.            return result;
  262.        }
  263.        
  264.        function processLine(line) {
  265.            const n = countChar(line, '[');
  266.            const replaced = replaceBrackets(line);
  267.            return replaced + ')'.repeat(n);
  268.        }
  269.        
  270.        function joinLines(lines) {
  271.            return lines.join('\n');
  272.        }
  273.        
  274.        function compile(s) {
  275.            const lines = splitLines(s);
  276.            const processedLines = lines.map(processLine);
  277.            return joinLines(processedLines);
  278.        }
  279.        
  280.        // UI Functions
  281.        function compileCode() {
  282.            const input = document.getElementById('input').value;
  283.            const output = compile(input);
  284.            document.getElementById('output').value = output;
  285.        }
  286.        
  287.        function copyOutput() {
  288.            const output = document.getElementById('output');
  289.            output.select();
  290.            document.execCommand('copy');
  291.            showNotification('Copied to clipboard!');
  292.        }
  293.        
  294.        function clearAll() {
  295.            document.getElementById('input').value = '';
  296.            document.getElementById('output').value = '';
  297.        }
  298.        
  299.        function loadExample() {
  300.            const example = `hello [world
  301. [foo [bar
  302. [test [nested [deep`;
  303.            document.getElementById('input').value = example;
  304.            compileCode();
  305.        }
  306.        
  307.        function showNotification(message) {
  308.            const notification = document.getElementById('notification');
  309.            notification.textContent = message;
  310.            notification.classList.add('show');
  311.            
  312.            setTimeout(() => {
  313.                 notification.classList.remove('show');
  314.             }, 2000);
  315.         }
  316.        
  317.         // Auto-compile on input change
  318.         document.getElementById('input').addEventListener('input', compileCode);
  319.        
  320.         // Keyboard shortcuts
  321.         document.addEventListener('keydown', (e) => {
  322.             // Ctrl/Cmd + Enter to compile
  323.             if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
  324.                e.preventDefault();
  325.                 compileCode();
  326.             }
  327.             // Ctrl/Cmd + Shift + C to copy
  328.             if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'C') {
  329.                e.preventDefault();
  330.                 copyOutput();
  331.             }
  332.         });
  333.     </script>
  334. </body>
  335. </html>
Advertisement