added code example to the main README
This commit is contained in:
@@ -6,6 +6,32 @@ This language was written as a personal study of how interpreters and compilers
|
|||||||
### Objectives
|
### Objectives
|
||||||
This project aims to be an interpreter design reference, therefore it optimizes for code quality and readability over execution speed and expressive power.
|
This project aims to be an interpreter design reference, therefore it optimizes for code quality and readability over execution speed and expressive power.
|
||||||
|
|
||||||
|
### Show me the code!
|
||||||
|
Here's a basic example of a noja program that implements a bubble sort and uses it to sort a list
|
||||||
|
```
|
||||||
|
L = [3, 2, 1];
|
||||||
|
|
||||||
|
do {
|
||||||
|
swapped = false;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while i < count(L)-1 and not swapped: {
|
||||||
|
|
||||||
|
if L[i+1] < L[i]: {
|
||||||
|
|
||||||
|
swapped = true;
|
||||||
|
tmp = L[i+1];
|
||||||
|
L[i+1] = L[i];
|
||||||
|
L[i] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
} while swapped;
|
||||||
|
|
||||||
|
print(L, '\n'); # Outputs [1, 2, 3]
|
||||||
|
```
|
||||||
|
|
||||||
## Supported platforms
|
## Supported platforms
|
||||||
I wrote it on a linux machine, but there should be very few places where a linux host is assumed, so it should be very easy to port.
|
I wrote it on a linux machine, but there should be very few places where a linux host is assumed, so it should be very easy to port.
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
#include <stddef.h> // NULL
|
#include <stddef.h> // NULL
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
// If this is turned on, this library will assume that the
|
// If this is turned on, these functions will assume
|
||||||
// UTF-8 strings will mainly contain ASCII characters.
|
// the UTF-8 strings will mainly contain ASCII characters.
|
||||||
#define ASSUME_ASCII 1
|
#define ASSUME_ASCII 1
|
||||||
|
|
||||||
/* SYMBOL
|
/* SYMBOL
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
#ifndef XUTF8_H
|
#ifndef UTF8_H
|
||||||
#define XUTF8_H
|
#define UTF8_H
|
||||||
#include <stdint.h> // uint32_t
|
#include <stdint.h> // uint32_t
|
||||||
int utf8_sequence_from_utf32_codepoint(char *utf8_data, int nbytes, uint32_t utf32_code);
|
int utf8_sequence_from_utf32_codepoint(char *utf8_data, int nbytes, uint32_t utf32_code);
|
||||||
int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t *utf32_code);
|
int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t *utf32_code);
|
||||||
|
|||||||
Reference in New Issue
Block a user