Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
jtpaasch / demo-01.dl
Created March 27, 2024 21:11
Cousot's prefix trace semantics in (Souffle) datalog. Run the demos: `souffle -D- demo-01.dl` etc.
#include "library.dl"
// =========================================================
// EXAMPLE
// =========================================================
/*
------------------------------------------------------------
THE PROGRAM
@jtpaasch
jtpaasch / memory.dl
Last active March 15, 2024 13:55
Simulating memory with Datalog (big/little endian reads/writes of bytes)
// Here's one way to use Souffle datalog to simulate
// reading bytes from memory and assembling a value
// out of them (big/little endian-wise).
// Working with string representations of binary numbers
// in Souffle is somewhat tedious, so I'm going to do
// this by storing bytes as numbers. Then, when I pull
// out the bytes and assemble them into a value, I just
// need to calculate the number from that sequence of
// integer byte values.
@jtpaasch
jtpaasch / CPP_BNF_Quickstart.md
Created March 3, 2024 18:37
C++ BNF Grammar quickstart

C++ BNF Grammar

The C++ grammar is convoluted. These notes offer a quickstart/bird's eye view into it.

BNF grammars

Here are some versions of the grammar (or C-variants):

@jtpaasch
jtpaasch / Clang_AST_Parsing.md
Created February 16, 2024 19:13
Parsing C++ ASTs with Clang
@jtpaasch
jtpaasch / 01-aexpr.dl
Last active January 3, 2024 14:44
The reaching definitions analysis (done in Souffle datalog), from Principles of Program Analysis, ch. 2.
/*
=======================================================
01 - Arithmetic expressions
=======================================================
Encoding arithmetic expressions and simple assignments with datalog.
The language is a subset of the one in PPA, pp. 3-4.
*/
@jtpaasch
jtpaasch / List_insertion.cpp
Created October 20, 2023 15:51
Working example of the running example on p. 15 of Chang et al, "Shape Analysis," in Trends and Foundations of Programming Languages vol 6, no 1-2, pp. 1-158.
#include <iostream>
using namespace std;
typedef struct list {
struct list * n;
int d;
} list;
void insert(list * l, int d) {
@jtpaasch
jtpaasch / StateMonad.hs
Created October 17, 2023 18:51
Example of Haskell's state monad (after the Monday Morning Haskell blog post)
module Main where
import qualified Control.Monad.State as M
import qualified Data.Array as A
import System.Random (StdGen, mkStdGen, randomR)
-- In a tic-tac-toe game, there is an 'X' player, and an 'O' player
data Player = PlayerO | PlayerX deriving (Eq, Show)
@jtpaasch
jtpaasch / Sexp_parser.hs
Created October 9, 2023 16:29
Parsing S-expressions in Haskell (using S-Cargot)
module Main where
import qualified Data.Text as T
import qualified Text.Parsec.Pos as P
import qualified Data.SCargot as S
import qualified Data.SCargot.Common as C
import qualified Data.SCargot.Language.Basic as B
import qualified Data.SCargot.Repr.WellFormed as W
type Sexp = W.WellFormedExpr (C.Located T.Text)
@jtpaasch
jtpaasch / Fold_left_vs_right.hs
Created October 6, 2023 14:17
The difference between fold left and fold right
-- This version of fold applies 'f' to the head of the list '[a]'
-- to get a new accumulation 'acc', then it recurses into the tail
-- of the list '[a]' where it then repeats. This means that the
-- accumulated results are built up by adding in the elements
-- of the list, one at a time, starting with the first element
-- (on the left), and then moving through them, going right.
foldLeft :: (b -> a -> b) -> b -> [a] -> b
foldLeft f acc xs =
case xs of
[] -> acc
@jtpaasch
jtpaasch / Relational-program-verification.md
Last active October 27, 2022 20:05
Notes on relational program verification

Relational Verification

Beckert, B. and M. Ulbrich. (2018) "Trends in Relational Program Verification." In I. Schaefer and P. Muller (Eds.), Principled Software Development: Essays Dedicated to Arnd Poetzsch-Heffter on the Occasion of His 60th Birthday. Springer, pp. 41-58.

Relational verification verifies relational properties that relate different programs.

To verify relational properties, one must (in principle) compare several runs of the same program.

Some examples of relational properties: