Skip to content

Instantly share code, notes, and snippets.

@tkurtbond
tkurtbond / split_bounded.adb
Created August 1, 2022 13:37
An Ada procedure to split bounded strings on a delimiter string with example of use.
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Bounded; use Ada.Strings.Bounded;
with Ada.Text_IO.Bounded_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Containers.Vectors;
procedure split_bounded is
package B_String is new
Ada.Strings.Bounded.Generic_Bounded_Length (Max => 128);
use B_String;
@tkurtbond
tkurtbond / split_unbounded.adb
Last active August 1, 2022 13:32
An Ada procedure to split unbounded strings on a delimiter string with example of use.
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.Containers.Vectors;
procedure split_unbounded is
package Unbounded_String_Vectors is new
Ada.Containers.Vectors (Natural, Unbounded_String);
use Unbounded_String_Vectors;
@tkurtbond
tkurtbond / generic.Mod
Created July 13, 2022 01:10
First stab at a generic linked list in Oberon-2
MODULE generic;
IMPORT Out;
TYPE ListItem = POINTER TO ListDesc;
ListDesc = RECORD
next: ListItem;
END;
IntegerItem = POINTER TO IntegerDesc;
@tkurtbond
tkurtbond / Match.Mod
Last active July 1, 2022 21:09
The regexp matcher from *The Practice of Programming*, translated to Oberon-2.
(* Match.Mod -- The regexp matcher from *The Practice of Programming*, translated to Oberon-2. *)
(* See: http://genius.cat-v.org/brian-kernighan/articles/beautiful *)
(* This code is a simple regular expression matcher that implements
the following constructs:
c matches any literal character c
. matches any single character
^ matches the beginning of the input string
$ matches the end of the input string
@tkurtbond
tkurtbond / tpop_regexp.c
Last active July 1, 2022 21:07
Example regexp matcher from *The Practice of Programming*.
/* tpop_match.c -- The regexp matcher from *The Practice of Programming*. */
/* See: http://genius.cat-v.org/brian-kernighan/articles/beautiful */
/* This code is a simple regular expression matcher that implements
the following constructs:
c matches any literal character c
. matches any single character
^ matches the beginning of the input string
$ matches the end of the input string
@tkurtbond
tkurtbond / Oberon-3.rst
Created June 12, 2022 03:09
Translation of Oberon-3 document from OfrontPlus compiler

Oberon-3

A new experimental Oberon-3 dialect arose in the process of rethinking and improving the Ofront + translator. It is most similar to Component Pascal, so only the differences will be listed below.

Especially recommended for development for 8, 16 and 32-bit microcontrollers. Although it is perfectly adapted for development for 64-bit architectures.

@tkurtbond
tkurtbond / sort-versions
Last active June 9, 2022 18:13
Sort semantic versions, with things like .rc1, .rc2, .rc11 ending up in the right places.
#! /usr/bin/env bash
# sort-versions -- Sort semantic versions, with things like .rc1, .rc2, .rc11 ending up in the right places.
REVERSE=''
let errors=0
while getopts "?hr" opt
do
case "$opt" in
(\?|h) let errors++ ;;
@tkurtbond
tkurtbond / Oberon2_app_b.atg
Last active June 3, 2022 14:31
Coco/R grammar for Oberon-2, from Appendix B of the Oberon-2 report.
COMPILER Oberon2_app_b
CHARACTERS
letter = 'A' .. 'Z' + 'a' .. 'z'.
digit = "0123456789".
hexDigit = digit + 'A' .. 'F'.
sqChar = ANY - '"'.
dqChar = ANY - "'".
TOKENS
@tkurtbond
tkurtbond / Oberon2_body.atg
Last active May 30, 2022 20:07
Coco/R grammar for Oberon-2, from the body of the Oberon-2 report.
COMPILER Oberon2
CHARACTERS
letter = 'A' .. 'Z' + 'a' .. 'z'.
digit = "0123456789".
hexDigit = digit + 'A' .. 'F'.
sqChar = ANY - '"'.
dqChar = ANY - "'".
TOKENS
(loop for f from -20 to 220
do (let ((c (* (/ 5 9) (- f 32)))
(k (+ 273.15 (* (/ 5 9) (- f 32)))))
(format t "~6,2f℉ ~6,2f℃ ~6,2fK~%" f c k)))
(loop for f from -20 to 220
for c = (* (/ 5 9) (- f 32))
for k = (+ 273.15 (* (/ 5 9) (- f 32)))
do (format t "~6,2f℉ ~6,2f℃ ~6,2fK~%" f c k))