如何运行the-super-tiny-compiler?Eclipse运行无输入输出问题咨询
Great question! Let's break this down clearly—this isn't a code missing issue, it's just how the project is designed.
为什么程序立即终止,没有输入提示?
The super tiny compiler is a teaching-focused demo of core compiler logic (lexical analysis → parsing → code generation), not a full interactive command-line tool. Here's what's happening:
- The default code in
the-super-tiny-compiler.jsincludes a hardcoded test input:const input = '(add 2 (subtract 4 2))'; const output = compiler(input); console.log(output); - When you run the file, it immediately compiles this preset input, logs the result (
add(2, subtract(4, 2));), and exits. There's no built-in code to prompt you for custom input—this is intentional for the demo. - If you don't see any output in Eclipse, double-check your run configuration: make sure you're running it as a Node.js Application (right-click the file → Run As → Node.js Application) and that the Console view is visible and set to show the correct process output.
正确的运行方法
You have a few options depending on what you want to do:
1. Run the default test case
Just use the Node.js run configuration in Eclipse as mentioned above. You should see the compiled JavaScript output in the Console view. If it's still not showing, try running the file directly from a terminal (outside Eclipse) with:
node the-super-tiny-compiler.js
This will confirm if the issue is with Eclipse's console setup or the code itself.
2. Add interactive input support
If you want to type your own Lisp-style code to compile, modify the end of the file to add Node.js's readline module for user input:
// Add this at the bottom of the file const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question('Enter your Lisp-style code: ', (userInput) => { try { const compiledOutput = compiler(userInput); console.log('Compiled result:', compiledOutput); } catch (err) { console.error('Error compiling code:', err.message); } rl.close(); });
Now when you run the file, it will prompt you for input, compile it, and show the result.
3. Run in a browser
If you prefer, you can wrap the compiler in an HTML file to run it in a browser:
<!DOCTYPE html> <html> <body> <script src="the-super-tiny-compiler.js"></script> <script> // Open your browser's developer console (F12) and run: // compiler('(multiply 3 (add 5 2))') // You'll get the compiled JavaScript as a return value </script> </body> </html>
确认代码完整性
The project's code is complete as-is—its purpose is to demonstrate the inner workings of a compiler, not to be a production-ready tool. All the core logic (tokenizer, parser, transformer, generator) is included in the single .js file.
内容的提问来源于stack exchange,提问作者GateNikalegaTeraBhai

