Skip to content

Quick start

sanya_fritz edited this page Apr 20, 2024 · 7 revisions

PonyScript Programming Language Documentation

PonyScript Compiler

Description

The PonyScript compiler is a tool that transforms source code written in PonyScript into C++ code. Then this C++ code is compiled using GCC (GNU Compiler Collection) into an executable file.

Compilation Process

  1. Translation to C++: Source code in PonyScript is translated into equivalent C++ code, preserving the structure and logic of the program.

  2. Compilation using GCC: The generated C++ code is compiled using GCC, resulting in the creation of an executable file.

Advantages of Compiling via C++

  • Performance: Compiling to C++ allows leveraging optimizations available in C++, thereby enhancing the performance of the executable file.

  • Portability: The resulting executable file can be run on various platforms supported by GCC without needing to recompile the source code.

  • Integration with Existing Libraries: The ability to use libraries written in C++ or having a connection with it expands the development capabilities in PonyScript.

Limitations

  • Possible Compatibility Issues: Using GCC may lead to some compatibility issues, especially when porting the program to platforms not supported by GCC.

Usage Example

int magic(int argc, char *argv[])
{
  neighln("Hello World");
}

This example demonstrates a program printing "Hello World" to the console.

Creating a Project

In the project directory, there must be a .ponycfg file where project settings are specified.

[File Name] = pony

In this example, it is indicated that the output file will be named pony.exe.

Your code should be in .psc files.

Compilation and Execution

pony [path to project folder]

Main Library

The main library of the language is lib.dll, it is automatically included in your project.

  • Main methods of lib:
    • neigh(string): function to print a string to the console.
    • neighln(string): function to print a string to the console with a newline.
    • read(): function to input data from the console.
    • readkey(): function to wait for a key press.
    • str(): function to convert bool, int, double to string.
    • to_int(): function to convert string to int.
    • range(int, int): function returns List of numbers in range.

Working with Strings

Working with strings in PonyScript is done using the ponystring class.

  • Methods of the ponystring class:

    • fromInt(int value): Creates a ponystring object from an integer value.
    • fromDouble(double value): Creates a ponystring object from a floating-point number.
    • split(char delimiter = ' '): Splits the string into substrings based on the specified delimiter.
    • removeExtraSpaces(): Removes extra spaces from the string.
    • replaceSubstring(const ponystring& oldSubstr, const ponystring& newSubstr): Replaces substrings in the string with other substrings.
    • strip(const std::string& chars = " \t\r\n"): Removes specified characters from the beginning and end of the string.
    • toUpperCase(): Converts the string to uppercase.
    • toLowerCase(): Converts the string to lowercase.
    • trim(): Removes spaces from the beginning and end of the string.
    • isEmpty(): Checks if the string is empty.
    • isDigit(): Checks if the string consists only of digits.

    You can make a formatted string use this sintax f"some text {code} text"

Working with Lists

Working with lists in PonyScript is done using the List class.

  • Methods of the List class:
    • append(T data): Adds an element to the end of the list.
    • toString() const: Returns a string representation of the list.
    • sort(): Sorts the elements of the list.
    • remove(const T& value): Removes the specified element from the list.
    • remove_index(size_t index): Removes an element at the specified index.
    • operator[]: Allows accessing elements of the list by index.
    • clear(): Clears the list.
    • getSize() const: Returns the current size of the list.

Working with Additional Libraries

Additional libraries allow extending the functionality of PonyScript.

They can be written in PonyScript or in C++.

To include a library, use the friend command.

friend math // This command includes the math library

Resources