Skip to content

Instantly share code, notes, and snippets.

View Chubek's full-sized avatar

Behrang Nevii Chubek

View GitHub Profile
@Chubek
Chubek / Pacal-Syntax.ml
Last active July 26, 2024 23:14
Pascal-Syntax.ml: ISO Pascal's syntax formalized in OCaml type system
(* Formalism for ISO-7185:1990 "Pascal" Syntax *)
(* These will be extended into an AST *)
(* ISO Pascal is different from Delphi *)
(* Please submit your comments to chubakbidpaa [at] riseup [dot] net *)
type pas_kw = And | Array | Begin | Case | Const
| Div | Do | Downto | Else | End
| File | For | Function | Goto
| If | In | Label | Mod | Nil
| Not | Of | Or | Packed | Procedure
@Chubek
Chubek / README.md
Last active May 30, 2024 16:01
TSV datasets of ROFF (Requests, Escapes, NRs, SRs, Characters)

This Gist contains a total of 5 tab-separated values files (TSV), and they list:

  • ROFF-Requests.tsv -> ROFF requests, this file is the only one where the structure is taken from the manual downloaded from TROFF's website authored by the late Joe Ossanna and the legendary BWK, refer to the listing in the manual to get a sense of what each column means (name;args;default;default arg values;flags;description).
  • ROFF-Escapes.tsv -> The escape sequences --- those accepting arguments and those variable have been marked;
  • ROFF-NRs.tsv -> The built-in numeric registers (which GROFF just calls registers);
  • ROFF-SRs.tsv -> The built-in string registers (which GROFF just calls strings);
  • ROFF-Chars.tsv -> The pre-defined character list;

Important thing to note is, these are the listings as defined by Ossanna and Kernighan. GNU additions have not been accounted for. Whatever Heirloom DocTools adds neither. This is pure ROFF!

@Chubek
Chubek / README.md
Created May 27, 2024 22:16
SML's "implode" and "explode" in OCaml

In Standard ML, we have two built-in functions called 'explode' and 'implode':

fun explode: string -> char list
fun implode: char list -> string

So, you get it, 'explode' makes a list of characters from a string and 'implode' does the inverse.

However, OCaml does not have these functions. Regardless; you may derive them like so:

@Chubek
Chubek / README.md
Last active December 31, 2025 13:27
Tokenizer for EBNF in Scheme

Tokenizer for EBNF in Scheme

tokenize-ebnf.scm defines in it a tokenizer (aka lexer, or scanner) for EBNF. This is compliant to ISO but several other meta-structures such as RegExp (/.../) are also consumed. Comments starting withg # are tokenized, consumed and appended to the token stream. Do with them as you wish!

This was an excercise at Scheme --- and so much more, an excercise at hand-rollling lexers in an stateless language with functional paradigm built in.

You can use this to, for example, translate EBNF to LaTEx, HTML, PostScript, ROFF --- or maybe define a parser for it, and convert it to Yacc, PEG, ANTLR, Flex, Re2C, etc.

What is EBNF?

@Chubek
Chubek / README.md
Created May 1, 2024 14:01
A tokenizer for EBNF in Scheme (need parser!)

tokenize-ebnf.scm is a tokenizer for EBNF in Scheme. Although it is [almost] useless without a parser --- and that is what I have issue arriving at!

I want this to be an educational experience, so I don't wish to resort to define-sytax macros. Otherwise it would have been much simpler. Scheme's macros are a cheatcode tbqh. In fact, CLisp's macros are cheatcode too. Read 'Let Over Lambda' by Doug Hoyte. If I use macros here, I have doomed myself to be a Scheme Simp (Scsimp?) forever. I just don't want that.

So what I want is your help in creating a parser for EBNF that keeps in mind the recursive, context-free nature of it. EBNF was not meant to be parser, it was never created as an applicable language. I have loooked around and there are not that many parsers for EBNF around. It's a meta-grammar meant to be leared at and hooted at. Not parsed.

And I don't really need to parse it. I wanna write an ebnf2ps program. So this is enough really.

The problem is the 'nested' or 'recursive' nature of EBNF. For

@Chubek
Chubek / README.md
Last active May 1, 2024 10:31
Hummingbot Gateway

1- wget setup_gateway.py:

wget -qO- https://gist.githubusercontent.com/Chubek/5137a0b75a76d5f9f38d1e768d56d591/raw/c4b8c8c25e6991f01367d9ed5a5fa2be7627d83d/setup_gateway.py > setup_gateway.py

2- Preprocess it with m4, using your credentials and pass it to python:

# For example
@Chubek
Chubek / controller.yml
Created April 27, 2024 12:45
Controller
########################################################
### Pure market making strategy config ###
########################################################
template_version: 24
strategy: pure_market_making
# Exchange and token parameters.
exchange: gate_io
@Chubek
Chubek / README.md
Last active April 27, 2024 06:47
Hummingbot Scripts

generate-volume.py

This script can be used with Hummingbot to:

1- Download latest books from specified exchange,

2- Subtrct/add delta from latest buy/sell,

3- Sell back based on order amount,

@Chubek
Chubek / README.md
Last active August 9, 2025 01:36
Semantics: Denotational vs. Operational

Semantics: Operational vs. Denotational

In this document I wish to explain the difference between operational and denotational semantics. It may sound like a dry subject but you and I both will learn plenty from it.

Semantics of a language defines how the language behaves, where as the syntax of a programming language defines how it is formed.

  • Syntax is the foundation of a language;
  • Semantics give purpose to the syntax;
  • Syntax errors often lead to semantic errors, but they don't have much of a 'causual' relationship;
@Chubek
Chubek / README.md
Last active April 19, 2024 06:13
Xeph Grammar -> Draft 1

Xeph.ebnf contains the first draft of the Xeph non-pure functional language. A prototype of Xeph, compiled targeting GNU C, is at works.

EDIT: It is currently the second revision. I have added meta programming, and a lot of other imporvements.

However, the definition is weak, and it needs your feedback to be refined.

The ADTs in Xeph are taken from Zephyr ASDL (which there are many implementations of, like mine) and the rest are 'original', that is, taken from ML, Haskell, and Scheme.

This is not the final version of the grammar. The implementation at the moment is focusing on the backend and semantics. The grammar of a functional language is its most important aspect, and it can't be taken lightly.