PureBasic
'''PureBasic''' is a high-level programming language by Fantaisie Software based on BASIC rules. PureBasic has been created for beginners and experts alike.
PureBasic is a portable programming language with current up-to-date implementations on Windows, Linux, and MacOS. The same code can be compiled and run natively on each OS. An older version for the Amiga platform is also available, but no longer maintained.
See Also
Merged content
- uses an integer cell size and memory size is allowed to grow as needed.
Procedure displayEndingMsg()
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
End
EndProcedure
Procedure displayErrorThenEnd(msg.s)
PrintN(msg)
displayEndingMsg()
EndProcedure
Macro bracketSearch(drx = 1) ;drx = -1 to search backwards
bktCnt = drx ;start count with the current bracket
;count nested loops till matching one is found
Repeat
i + drx ;move the code pointer
If Mid(code$, i, 1) = "]"
bktCnt - 1
ElseIf Mid(code$, i, 1) = "["
bktCnt + 1
EndIf
Until bktCnt = 0
EndMacro
If Not OpenConsole()
MessageRequester("Error", "Unable to open console.")
End
EndIf
Define memsize = 1000 ;this may grow as needed
Define instChars$ = "+-<>.,[]" ;valid characters
Define ptr = 0 ;memory pointer
Print("Filename (blank to use std in)...? ")
filename$ = Input()
If filename$ = ""
Repeat
line$ = Input()
source$ = source$ + line$
Until line$ = ""
Else
OpenFile(1, filename$)
Repeat
line$ = ReadString(1)
source$ = source$ + line$
Until Eof(1)
CloseFile(1)
EndIf
;remove non-code and validate number of brackets
bktCnt = 0
For i = 1 To Len(source$)
char$ = Mid(source$, i, 1)
;validate instruction character
If FindString(instChars$, char$, 1)
code$ + char$
;count brackets
Select char$
Case "["
bktCnt + 1
Case "]"
bktCnt - 1
EndSelect
EndIf
Next
If bktCnt ;mismatched brackets
displayErrorThenEnd("Uneven brackets")
EndIf
Dim memory(memsize) ;use integer cell size
Define inLine$ = "" ;input buffer
For i = 1 To Len(code$) ;loop through the code
Select Mid(code$, i, 1) ;examine the current instruction
Case "+"
memory(ptr) + 1
Case "-"
memory(ptr) - 1
Case "."
Print(Chr(memory(ptr)))
Case ","
If inLine$ = "": inLine$ = Input(): EndIf ;buffer input
memory(ptr) = Asc(Left(inLine$, 1)) ;store first char off the buffer
inLine$ = Mid(inLine$, 2) ;delete first char from the buffer
Case ">"
ptr + 1
If ptr > memsize
memsize + 1000
Redim memory(memsize)
EndIf
Case "<"
ptr - 1
If ptr < 0
displayErrorThenEnd("Memory pointer out of range")
EndIf
Case "["
If memory(ptr) = 0
bracketSearch()
EndIf
Case "]"
If memory(ptr) <> 0
bracketSearch(-1)
EndIf
EndSelect
Next
displayEndingMsg()
Tasks
- 100 doors
- 15 Puzzle Game
- 24 game
- 9 billion names of God the integer
- A+B
- ABC Problem
- AKS test for primes
- Abundant odd numbers
- Abundant, deficient and perfect number classifications
- Ackermann function
- Active object
- Address of a variable
- Align columns
- Almost prime
- Amb
- Amicable pairs
- Anagrams
- Anagrams/Deranged anagrams
- Animate a pendulum
- Animation
- Apply a callback to an array
- Arbitrary-precision integers (included)
- Archimedean spiral
- Arithmetic-geometric mean
- Arithmetic/Complex
- Arithmetic/Integer
- Array concatenation
- Array length
- Arrays
- Assertions
- Associative array/Creation
- Associative array/Iteration
- Atomic updates
- Averages/Arithmetic mean
- Averages/Median
- Averages/Mode
- Averages/Pythagorean means
- Averages/Root mean square
- Averages/Simple moving average
- Babbage problem
- Balanced brackets
- Barnsley fern
- Base64 encode data
- Benford's law
- Best shuffle
- Binary digits
- Binary search
- Binary strings
- Bitcoin/address validation
- Bitmap
- Bitmap/Bézier curves/Cubic
- Bitmap/Bézier curves/Quadratic
- Bitmap/Flood fill
- Bitmap/Histogram
- Bitmap/Midpoint circle algorithm
- Bitmap/Read a PPM file
- Bitmap/Write a PPM file
- Bitwise IO
- Bitwise operations
- Boolean values
- Box the compass
- Bresenham's Line Algorithm
- Brownian tree
- Bulls and cows
- Bulls and cows/Player
- CRC-32
- CSV data manipulation
- Caesar cipher
- Call a foreign-language function
- Call a function in a shared library
- Case-sensitivity of identifiers
- Catalan numbers
- Catalan numbers/Pascal's triangle
- Character codes
- Check that file exists
- Checkpoint synchronization
- Chinese remainder theorem
- Classes
- Closest-pair problem
- Collections
- Color of a screen pixel
- Color quantization
- Colour bars/Display
- Colour pinstripe/Display
- Combinations
- Combinations with repetitions
- Comma quibbling
- Command-line arguments
- Comments
- Compare a list of strings
- Compile-time calculation
- Compound data type
- Concurrent computing
- Conditional structures
- Constrained random points on a circle
- Convert decimal number to rational
- Convert seconds to compound duration
- Copy a string
- Count in factors
- Count in octal
- Count occurrences of a substring
- Create a file
- Create a two-dimensional array at runtime
- Create an HTML table
- Create an object at a given address
- Cumulative standard deviation
- Date format
- Date manipulation
- Day of the week
- Delete a file
- Detect division by zero
- Determine if a string is numeric
- Determine if only one instance is running
- Digital root
- Dinesman's multiple-dwelling problem
- Dining philosophers
- Discordian date
- Documentation
- Dot product
- Doubly-linked list/Definition
- Doubly-linked list/Element definition
- Doubly-linked list/Element insertion
- Doubly-linked list/Traversal
- Dragon curve
- Draw a clock
- Draw a cuboid
- Draw a pixel
- Draw a sphere
- Echo server
- Empty directory
- Empty program
- Empty string
- Enforced immutability
- Entropy
- Enumerations
- Environment variables
- Equilibrium index
- Ethiopian multiplication
- Euler method
- Euler's sum of powers conjecture
- Evaluate binomial coefficients
- Even or odd
- Events
- Evolutionary algorithm
- Exceptions
- Execute Brainfuck
- Execute HQ9+
- Execute a Markov algorithm
- Execute a system command
- Exponentiation operator
- Extreme floating point values
- FASTA format
- Factorial
- Factors of an integer
- Farey sequence
- Fibonacci n-step number sequences
- Fibonacci sequence
- Fibonacci word
- Filter
- Find common directory path
- Find limit of recursion
- Find the last Sunday of each month
- Find the missing permutation
- Five weekends
- FizzBuzz
- Flatten a list
- Flow-control structures
- Floyd's triangle
- Forest fire
- Formatted numeric output
- Forward difference
- Four bit adder
- Fractal tree
- Function composition
- Function definition
- Function prototype
- GUI component interaction
- GUI enabling/disabling of controls
- GUI/Maximum window dimensions
- Galton box animation
- Gamma function
- Generate lower case ASCII alphabet
- Generic swap
- Globally replace text in several files
- Go Fish
- Gray code
- Grayscale image
- Greatest common divisor
- Greatest element of a list
- Greatest subsequential sum
- Greyscale bars/Display
- Guess the number
- Guess the number/With feedback
- Guess the number/With feedback (player)
- HTTP
- Hamming numbers
- Handle a signal
- Happy numbers
- Hash from two arrays
- Hash join
- Haversine formula
- Hello world!
- Hello world/Graphical
- Hello world/Line printer
- Hello world/Newline omission
- Hello world/Standard error
- Hello world/Text
- Hello world/Web server
- Higher-order functions
- History variables
- Hofstadter Q sequence
- Hofstadter-Conway $10,000 sequence
- Honeycombs
- Horizontal sundial calculations
- Horner's rule for polynomial evaluation
- Host introspection
- Hostname
- Huffman coding
- I before E except after C
- IBAN
- Identity matrix
- Image noise
- Include a file
- Increment a numerical string
- Infinity
- Inheritance/Multiple
- Inheritance/Single
- Input loop
- Integer comparison
- Integer overflow
- Integer sequence
- Introspection
- Iterated digits squaring
- JSON
- Jensen's Device
- JortSort
- Josephus problem
- Joystick position
- Jump anywhere
- Kaprekar numbers
- Keyboard input/Flush the keyboard buffer
- Keyboard input/Keypress check
- Keyboard input/Obtain a Y or N response
- Keyboard macros
- Knapsack problem/0-1
- Knapsack problem/Continuous
- Knapsack problem/Unbounded
- Knuth shuffle
- Kronecker product
- LZW compression
- Langton's ant
- Last Friday of each month
- Leap year
- Least common multiple
- Leonardo numbers
- Letter frequency
- Levenshtein distance
- Linear congruential generator
- Literals/Floating point
- Literals/Integer
- Literals/String
- Logical operations
- Long multiplication
- Longest common subsequence
- Longest string challenge
- Look-and-say sequence
- Loop over multiple arrays simultaneously
- Loops/Break
- Loops/Continue
- Loops/Do-while
- Loops/Downward for
- Loops/For
- Loops/For with a specified step
- Loops/Infinite
- Loops/N plus one half
- Loops/Nested
- Loops/While
- Loops/with multiple ranges
- Lucas-Lehmer test
- Luhn test of credit card numbers
- MD5
- Machine code
- Magic squares of doubly even order
- Magic squares of odd order
- Mandelbrot set
- Map range
- Matrix multiplication
- Matrix transposition
- Maze generation
- Maze solving
- Memory allocation
- Menu
- Metered concurrency
- Middle three digits
- Miller–Rabin primality test
- Minesweeper game
- Modular inverse
- Monte Carlo methods
- Monty Hall problem
- Morse code
- Multiple distinct objects
- Multiplication tables
- Munchausen numbers
- Munching squares
- Mutual recursion
- N-queens problem
- Non-decimal radices/Output
- Nth root
- Null object
- Number names
- Number reversal game
- Numerical integration
- Odd word problem
- One of n lines in a file
- One-dimensional cellular automata
- OpenGL
- Operator precedence
- Order two numerical lists
- Ordered words
- Palindrome detection
- Pangram checker
- Parallel calculations
- Parametrized SQL statement
- Pascal matrix generation
- Pascal's triangle
- Pascal's triangle/Puzzle
- Password generator
- Percentage difference between images
- Perfect numbers
- Permutation test
- Permutations
- Permutations/Derangements
- Pernicious numbers
- Phrase reversals
- Pi
- Pick random element
- Pinstripe/Display
- Play recorded sounds
- Playing cards
- Plot coordinate pairs
- Pointers and references
- Polymorphism
- Power set
- Price fraction
- Primality by trial division
- Prime decomposition
- Priority queue
- Probabilistic choice
- Problem of Apollonius
- Program name
- Program termination
- Proper divisors
- Pythagoras tree
- Pythagorean triples
- Quaternion type
- Queue/Definition
- Queue/Usage
- Quickselect algorithm
- Quine
- RCRPG
- RPG Attributes Generator
- Random number generator (device)
- Random number generator (included)
- Random numbers
- Range expansion
- Range extraction
- Rate counter
- Ray-casting algorithm
- Read a file line by line
- Read a specific line from a file
- Read entire file
- Real constants and functions
- Regular expressions
- Remove duplicate elements
- Remove lines from a file
- Rename a file
- Rep-string
- Repeat a string
- Return multiple values
- Reverse a string
- Reverse words in a string
- Rock-paper-scissors
- Roman numerals/Decode
- Roman numerals/Encode
- Roots of a function
- Roots of unity
- Rosetta Code/Count examples
- Rosetta Code/Fix code tags
- Rot-13
- Run-length encoding
- Runge-Kutta method
- SEDOLs
- SHA-1
- SHA-256
- SOAP
- Scope modifiers
- Search a list
- Secure temporary file
- Self-describing numbers
- Send email
- Sequence of primes by trial division
- Set
- Seven-sided dice from five-sided dice
- Shell one-liner
- Short-circuit evaluation
- Show Ascii table
- Show the epoch
- Sierpinski carpet
- Sierpinski triangle
- Sieve of Eratosthenes
- Simple windowed application
- Simulate input/Keyboard
- Simulate input/Mouse
- Singleton
- Singly-linked list/Element definition
- Singly-linked list/Element insertion
- Singly-linked list/Traversal
- Sleep
- Smith numbers
- Sockets
- Sort an array of composite structures
- Sort an integer array
- Sort disjoint sublist
- Sort numbers lexicographically
- Sort stability
- Sort three variables
- Sorting algorithms/Bead sort
- Sorting algorithms/Bogosort
- Sorting algorithms/Bubble sort
- Sorting algorithms/Cocktail sort
- Sorting algorithms/Comb sort
- Sorting algorithms/Counting sort
- Sorting algorithms/Gnome sort
- Sorting algorithms/Heapsort
- Sorting algorithms/Insertion sort
- Sorting algorithms/Merge sort
- Sorting algorithms/Pancake sort
- Sorting algorithms/Permutation sort
- Sorting algorithms/Quicksort
- Sorting algorithms/Radix sort
- Sorting algorithms/Selection sort
- Sorting algorithms/Shell sort
- Sorting algorithms/Sleep sort
- Sorting algorithms/Stooge sort
- Sorting algorithms/Strand sort
- Soundex
- Special characters
- Special variables
- Spiral matrix
- Split a character string based on change of character
- Stable marriage problem
- Stack
- Stack traces
- Stair-climbing puzzle
- Start from a main routine
- Statistics/Basic
- Statistics/Normal distribution
- Stem-and-leaf plot
- Straddling checkerboard
- String append
- String case
- String comparison
- String concatenation
- String interpolation (included)
- String length
- String matching
- String prepend
- Strip a set of characters from a string
- Strip block comments
- Strip comments from a string
- Strip control codes and extended characters from a string
- Strip whitespace from a string/Top and tail
- Substring
- Substring/Top and tail
- Sudoku
- Sum and product of an array
- Sum digits of an integer
- Sum multiples of 3 and 5
- Sum of a series
- Sum of squares
- Sutherland-Hodgman polygon clipping
- Symmetric difference
- Synchronous concurrency
- System time
- Take notes on the command line
- Temperature conversion
- Terminal control/Clear the screen
- Terminal control/Coloured text
- Terminal control/Cursor positioning
- Terminal control/Dimensions
- Terminal control/Display an extended character
- Terminal control/Hiding the cursor
- Terminal control/Inverse video
- Terminal control/Ringing the terminal bell
- Test a function
- Text processing/1
- Text processing/2
- Text processing/Max licenses in use
- The Twelve Days of Christmas
- Thue-Morse
- Time a function
- Tokenize a string
- Top rank per group
- Topological sort
- Trabb Pardo–Knuth algorithm
- Tree traversal
- Trigonometric functions
- Truncatable primes
- Truncate a file
- URL decoding
- URL encoding
- UTF-8 encode and decode
- Unbias a random generator
- Undefined values
- Validate International Securities Identification Number
- Vampire number
- Van der Corput sequence
- Variable size/Get
- Variable size/Set
- Variables
- Vector products
- Verify distribution uniformity/Naive
- Vigenère cipher
- Walk a directory/Non-recursively
- Walk a directory/Recursively
- Web scraping
- Window creation
- Window management
- Wireworld
- Word wrap
- Write entire file
- Write float arrays to a text file
- Write to Windows event log
- XML/Input
- XML/Output
- Xiaolin Wu's line algorithm
- Yin and yang
- Zeckendorf number representation
- Zero to the zero power
- Zig-zag matrix