Pepper Programming Language v1.0

Introduction

Pepper is a simple yet powerful programming language designed for educational purposes. It combines intuitive syntax with modern programming concepts, making it ideal for learning programming fundamentals.

Key Features

Educational

Educational Focus

Designed specifically for learning programming concepts

Simple

Simple Syntax

Clear and readable code structure

Modern

Modern Features

Includes essential programming concepts

Installation

To run Pepper programs, you need Python 3.7 or later installed on your system. The interpreter can be run directly from the command line:

python main.py your_script.pep

For interactive mode:

python main.py

Quick Start

Hello World

%% Hello World in Pepper
LET message: string = "Hello, World!"
SHOW(message)
Save this code in a file with .pep extension and run it using the Pepper interpreter.

Basic Syntax

Pepper uses a clean, readable syntax with clear keywords and statements.

Comments

%% This is a comment

Statements

LET x: int = 10
SHOW(x)
REAS x = x 1 +

Variables

Variables in Pepper must be declared with explicit types using the LET keyword and can be reassigned using REAS.

LET age: int = 25
LET name: string = "John"
LET pi: float = 3.14
LET isActive: bool = true
LET numbers: list = [1, 2, 3]

REAS age = age 1 +

Data Types

Type Description Example
int Integer numbers LET x: int = 42
float Floating-point numbers LET pi: float = 3.14159
string Text strings LET name: string = "Hello"
bool Boolean values LET flag: bool = true
list Lists of values LET nums: list = [1, 2, 3]

Operators

Arithmetic (RPN)

Pepper uses Reverse Polish Notation (RPN) for arithmetic operations.

LET result: int = 5 3 +    %% Addition
LET product: int = 4 2 *  %% Multiplication
LET power: float = 2 3 ** %% Exponentiation
LET div: float = 10 2 /   %% Division
LET intDiv: int = 10 3 !/ %% Integer division

Boolean Operators

LET x1: int = 5
LET y: int = 3
LET p: bool = true
LET q: bool = false
LET a: bool = x1 && y     %% Equality
LET b: bool = x1 &$$& y   %% Inequality
LET c: bool = p @$@ q    %% Logical AND
LET d: bool = p #$# q    %% Logical OR
LET e: bool = ~@ p       %% Logical NOT

Control Flow

Conditional Statements

IF x > y DO
    SHOW("x is greater")
ELIF x < y DO
    SHOW("y is greater")
ELSE DO
    SHOW("x equals y")
END

Loops

FOR i FROM 1 TO 5 DO
    SHOW(i)
LOOP_END

WHILE x > 0 DO
    REAS x = x 1 -
LOOP_END

GOTO Statements

LBL start;
SHOW("Loop")
REAS x = x 1 -
GOTO start; x > 0

Functions

Functions are declared using the ::() syntax and called using the |> operator.

greet::(name: string)->
    SHOW("Hello, " + name + "!")
<-void

("World") |> greet

add::(x: int, y: int)->
    RETURN x y +
<-int

LET sum: int = (5, 3) |> add

Imports

Imports in Pepper are done with the IMPORT function FROM module syntax. Imports are local to the .pep file being run.

%% module.pep
add::(x: int, y: int)->
    RETURN x y +
<-int

%% main.pep
IMPORT add FROM module
SHOW((5,3) |> add)

Lists

Lists support various operations using special syntax.

LET nums: list = [1, 2, 3]
REAS nums = nums 4 [a]      %% Append
REAS nums = nums 2 [r]      %% Remove
REAS nums = nums 5 [n] 2    %% Insert at position
REAS nums = nums 1 [p] 10   %% Replace first occurrence
REAS nums = nums [?]        %% Get random element
LET len: int = nums [l]     %% Get length
LET val: int = nums [i] 2   %% Get item at index

Strings

Strings support similar operations to lists plus concatenation.

LET str: string = "Hello"
REAS str = str "!" [a]      %% Append
REAS str = str "l" [r]      %% Remove first 'l'
REAS str = str "x" [n] 2    %% Insert at position
LET len: int = str [l]      %% Get length

Standard Library

Pepper includes a comprehensive standard library with various utility functions organized into different namespaces.

String Library (string)

Function Description Example
upper() Converts string to uppercase LET up: string = upper FROM string "hello" _
lower() Converts string to lowercase LET low: string = lower FROM string "HELLO" _
len() Returns length of string LET length: int = len FROM string "hello" _
trim() Removes leading/trailing whitespace LET trimmed: string = trim FROM string " hello " _
replace(old, new) Replaces all occurrences of 'old' with 'new' LET replaced: string = replace FROM string "hello" ("l", "w")
split(delimiter) Splits string into list by delimiter LET parts: list = split FROM string "a,b,c" (",")
join(list) Joins list elements with string as delimiter LET joined: string = join FROM string "," (["a", "b"])
contains(substring) Checks if string contains substring LET has: bool = contains FROM string "hello" ("el")
starts_with(prefix) Checks if string starts with prefix LET starts: bool = starts_with FROM string "hello" ("he")
ends_with(suffix) Checks if string ends with suffix LET ends: bool = ends_with FROM string "hello" ("lo")

Math Library (math)

Function Description Example
sqrt() Square root LET root: float = sqrt FROM math 16.0 _
pow(exponent) Power function LET power: float = pow FROM math 2.0 (3)
abs() Absolute value LET abs_val: float = abs FROM math -42.5 _
pi() Returns π constant LET pi: float = pi FROM math _ _
e() Returns e constant LET e: float = e FROM math _ _

Random Library (random)

Function Description Example
rnd() Random float between 0 and 1 LET r: float = rnd FROM random _ _
rnd(stop) Random integer between 0 and stop-1 LET n: int = rnd FROM random _ (10)
rnd(start, stop) Random integer between start and stop LET d: int = rnd FROM random _ (1, 6)

List Library (list)

Function Description Example
sort([reverse]) Sorts list LET sorted: list = sort FROM list [3,1,2] _
reverse() Reverses list LET rev: list = reverse FROM list [1,2,3] _
sum() Sums numeric list LET total: int = sum FROM list [1,2,3] _
avg() Averages numeric list LET average: float = avg FROM list [1,2,3] _
For a complete reference of all standard library functions, see the Standard Library Reference.

Input/Output

LET name: string = INPT("Enter your name: ")
SHOW("Hello, " + name + "!")

Random Operations

? 42                          %% Set random seed
LET x2: float = ?             %% Random float 0-1
LET y1: float = ? 10 *        %% Random float 0-10
LET z: int = ? 6 * 1 +       %% Random int 1-6

Complete Examples

Temperature Converter

convert::(celsius: float)->
    LET fahrenheit: float = celsius 9 * 5 / 32 +
    RETURN fahrenheit
<-float

LET temp: float = INPT("Enter temperature in Celsius: ")
LET converted: float = (temp) |> convert
SHOW(temp + "C is " + converted + "F")

Number Guessing Game

? 42
LET target: int = ? 100 * 1 +  %% SETS ANSWER TO 64
LET guess: int = INPT("Guess a number (1-100): ")
WHILE guess &$$& target DO
    IF guess < target DO
        SHOW("Too low!")
    ELSE DO
        SHOW("Too high!")
    END
    REAS guess = INPT("Try again: ")
LOOP_END
SHOW("Correct!")
                        

Best Practices

Naming Conventions

  • Use descriptive variable names
  • Start variable names with letters
  • Use underscores for multi-word names
Avoid using reserved keywords as variable names.

Community & Support

These don't exist