Skip to content

mxcury/pCubedLang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P-Cubed (P3)

Table of Contents

Introduction

This project is a custom programming language designed to closely follow the AQA pseudocode specification, implemented in C. It is designed for those who are familiar with AQA pseudocode and want a practical way to execute their pseudocode programs.

Features

  • Syntax: Follows the AQA pseudocode structure closely, making it easy to transition from pseudocode to an executable format.
  • Performance: Implemented in C for efficient execution.
  • Educational Use: Ideal for students preparing for exams or educators demonstrating AQA pseudocode concepts.
  • Error Handling: Provides meaningful error messages based on common pseudocode mistakes.

Installation

To install and run the language on your machine, follow these steps:

  1. Ensure you have a C compiler (e.g., gcc) installed. On most Linux distributions, you can install gcc using:

    sudo apt-get install build-essential  # For Ubuntu/Debian

    Or for macOS:

    xcode-select --install
  2. Clone the repository:

    git clone https://github.com/mxcury/pCubedLang.git
  3. Navigate to the project directory:

    cd pCubedLang
  4. Compile the source code using make:

    make
  5. Install the executable:

    sudo make install
  6. Run the p3 executable:

    p3
  7. (Optional) To uninstall the program:

    sudo make uninstall

After following these steps, you'll have the p3 interpreter installed and ready to run your pseudocode programs.

Usage

Once the interpreter is compiled and installed, you can write your pseudocode programs in a .p3 file and run them using the p3 executable:

p3 <yourfile.p3>

Example:

p3 hello_world.p3

Debug Mode

To see the Abstract Syntax Tree (AST) produced during execution and how long the program took to run, use the --debug flag:

p3 --debug <yourfile.p3>

This will output additional information, including the AST structure and execution time.

p3 --debug hello_world.p3

This command will:

  • Compile and run hello_world.p3.
  • Output the AST generated by the parser.
  • Display how long it took to run the program.

Syntax Overview

The language follows AQA pseudocode conventions, which include the following key elements:

  • Variables: Declared using DECLARE followed by the variable name and type.

    count <- 0
    
  • Input/Output: Supports OUTPUT, USERINPUT, etc.

    OUTPUT "Enter a number"
    number <- USERINPUT
    
  • Control Flow: Includes IF, ELSE, WHILE, FOR, and other standard constructs.

    IF number > 0 THEN
        OUTPUT "Positive"
    ELSE
        OUTPUT "Negative"
    ENDIF
    
  • Loops: Supports FOR, WHILE, and REPEAT...UNTIL loops.

    FOR i <- 1 TO 10
        OUTPUT i
    ENDFOR
    

Examples

Here are some examples to demonstrate the language in action:

  1. Hello World

    OUTPUT "Hello, World!"
    
  2. Sum of Numbers

    sum <- 0
    FOR i <- 1 TO 10
        sum <- sum + i
    ENDFOR
    OUTPUT sum
    
  3. Simple IF Statement

    OUTPUT "Enter a number:"
    num <- USERINPUT
    num <- STRING_TO_INT(num)
    IF num > 0 THEN
        OUTPUT "Positive"
    ELSE
        OUTPUT "Negative or Zero"
    ENDIF
    

Contributing

If you'd like to contribute to this project, feel free to fork the repository and submit a pull request. Please ensure your contributions adhere to the existing coding style and structure of the project.

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published