Skip to content

A simple way to run Free Pascal programs in the browser so new developers can learn the language without having to install anything.

License

Notifications You must be signed in to change notification settings

ikelaiah/fpc-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ FPC Playground

License: MIT Free Pascal Python Flask Docker Web Supports Windows Supports Linux Version

A simple way to run Free Pascal programs in the browser so new developers can learn the language without having to install anything.

Give it a try here: FPC Playground

Warning

This project is still a work in progress and will not support all Free Pascal features.

FPC Playground Screenshot

Table of Contents

🌟 Features

  • Web-based Pascal editor with syntax highlighting
  • Real-time compilation and execution
  • Program arguments support - Pass command line arguments to your Pascal programs
  • User input support - Handle ReadLn() statements with dedicated input fields
  • Example programs to get started quickly
  • Security filtering to prevent dangerous operations
  • Educational-friendly interface with clear separation of code, input, and output

πŸ”’ Security Features

  • Smart Keyword Detection: Advanced pattern matching prevents dangerous operations while allowing legitimate code
  • Multi-layered Validation: Character encoding, complexity checks, and comprehensive threat detection
  • Word Boundary Matching: Uses regex word boundaries (\b) for precise keyword detection
  • Context-Aware Shell Detection: Shell commands only blocked in dangerous contexts (e.g., sh -c, /bin/sh)
  • Educational Focus: Secure enough for learning environments, flexible enough for creativity

βœ‹ Prerequisites

Make sure you have Docker installed. You can download it from Docker's official site.

πŸš€ Quick Start

  1. Clone the repository: git clone https://github.com/ikelaiah/fpc-playground.git
  2. Run Docker Compose: docker-compose up
  3. Access the frontend at http://localhost:8080 and start coding!

⭐ Feedback

We value your feedback! If you enjoy using FPC Playground, please star the repository and share your thoughts.

πŸƒ Running Locally

Using Docker Compose

To simplify setup, you can use Docker Compose to run both the backend and frontend services:

  1. Clone the repository:
git clone https://github.com/ikelaiah/fpc-playground.git
  1. Navigate to the project directory:
cd fpc-playground
  1. Run Docker Compose:
docker-compose up
  1. Access the frontend at http://localhost:8080 and the backend at http://localhost:5000.

πŸŽ“ Using the Playground

The FPC Playground provides an intuitive interface for learning Pascal programming:

Code Editor

  • Write your Pascal code with syntax highlighting
  • Use the example buttons to load pre-written programs
  • Fix quotes automatically for Pascal compatibility

Program Arguments

  • Use the "Program Arguments" textarea to pass command line arguments to your program
  • Separate multiple arguments with spaces
  • Example: arg1 arg2 arg3

User Input

  • Use the "User Input" textarea to provide input for ReadLn() statements
  • Enter each input value on a separate line
  • The program will read these values in order when it encounters ReadLn()

Example Usage

program TestInput;
var
    name: string;
    age: integer;
begin
    writeln('What is your name?');
    readln(name);
    writeln('How old are you?');
    readln(age);
    writeln('Hello ', name, ', you are ', age, ' years old!');
end.

For this program, enter in the User Input field:

John
25

The output will be:

What is your name?
How old are you?
Hello John, you are 25 years old!

Without Docker Compose

Backend

To run the backend manually without Docker Compose, follow these steps:

  1. Clone the repository:
git clone https://github.com/ikelaiah/fpc-playground.git
  1. Navigate to the backend directory:
cd fpc-playground/backend
  1. Build the Docker image:
docker build -t fpc-playground-backend .
  1. Run the Docker container:
docker run -p 5000:5000 fpc-playground-backend

Frontend

The frontend is a simple HTML page that interacts with the backend API using JavaScript.

To run the frontend manually, you can simply open the index.html file in your web browser. It will automatically connect to the backend running on http://localhost:5000.

πŸ§ͺ Testing with curl

Run the following commands to test the backend using curl:

cd backend
docker build -t fpc-playground-backend .
docker run -p 5000:5000 fpc-playground-backend

Test a simple "Hello, World!" program

Note: The API requires base64 encoded Pascal code, arguments, and input.

# Create test payload with base64 encoded Pascal code
echo '{"code":"'$(echo "program HelloWorld; begin writeln('Hello, World!'); end." | base64 -w 0)'","args":"","input":""}' > test.json
curl -X POST http://localhost:5000/run -H "Content-Type: application/json" -d @test.json

Alternative method using a helper script:

# Create a simple test script
cat > test_api.sh << 'EOF'
#!/bin/bash
CODE="program HelloWorld; begin writeln('Hello, World!'); end."
ENCODED_CODE=$(echo -n "$CODE" | base64 -w 0)
echo '{"code":"'$ENCODED_CODE'","args":"","input":""}' | curl -X POST http://localhost:5000/run -H "Content-Type: application/json" -d @-
EOF
chmod +x test_api.sh
./test_api.sh

⚠️ Current Limitations

  • Code size: Maximum 16KB per program
  • Output size: Limited to 48KB to prevent abuse
  • Rate limiting: 150 requests per hour, 10 per minute
  • Pascal features: Not all Free Pascal features supported (work in progress)
  • Complex structures: Limited nested structures (max 20 begin statements, 100 parentheses, 50 brackets)
  • Character encoding: Only standard ASCII characters (32-126) plus newlines, carriage returns, and tabs

πŸ”§ Troubleshooting

Common Issues

  • "Code contains restricted keyword": Check for Pascal reserved words in variable names or use different names
  • "Code structure too complex": Simplify nested structures or break code into smaller functions
  • Connection refused: Ensure Docker containers are running on correct ports (8080 for frontend, 5000 for backend)
  • Compilation errors: Verify Pascal syntax - the playground uses Free Pascal 3.2.2+
  • "Code contains invalid characters": Use only standard ASCII characters in your code

Getting Help

πŸ™Œ Contributing

We welcome contributions! To contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes and commit them (git commit -m "Add feature").
  4. Push to your branch (git push origin feature-branch).
  5. Open a pull request.

βš–οΈ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

About

A simple way to run Free Pascal programs in the browser so new developers can learn the language without having to install anything.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published