Skip to content

Instantly share code, notes, and snippets.

View Chubek's full-sized avatar

Chubak Bidpaa Chubek

View GitHub Profile
@Chubek
Chubek / README.md
Last active May 4, 2024 17:22
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 April 20, 2024 18:59
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.

@Chubek
Chubek / allocppx.1
Last active April 16, 2024 15:02
AllocPPx.pl -> A C preprocessor that adds garbage collection
LLOCPPX(1) User Contributed Perl Documentation ALLOCPPX(1)
NAME
allocppx.pl - A Perl script for preprocessing C files with specific
annotations.
SYNOPSIS
perl allocppx.pl [options] [input_file]
@Chubek
Chubek / README.md
Created April 7, 2024 21:30
Introduction to Zephyr ASDL

I wrote an implementation of Zephyr ASDL which you can install from here:

https:///github.com/Chubek/ZephyrASDL

In this document I wanna write a short intro to ASDL and you you can utilize it.

ASDL is in use in CPython's source code. Not my implementation of course, an implementation called 'PyASDL' which parses it, and it's up to you to provide the semantics and code generation. CPython's source code uses ASDL to build the Abstract Syntax Tree for Python in C++. My implementation of ASDL translates the syntax description directly to C. You can specify the types to be also emitted in an extra header file (via the -s flag).

Zephyr ASDL is not an standard, it's just a short paper written in 1997, by Wang, Appel, Korn and Serra, all Princeton alumni.

@Chubek
Chubek / POSIX-Shell.ebnf
Last active April 6, 2024 18:48
The POSIX Shell Grammar
# Lexical and Syntactic EBNF Grammar for POSIX Shell (Non-Attributed)
# Authored by Chubak Bidpaa (chubakbidpaa@riseup.net)
# Written For the Marsh Shell (https://github.com/Chubek/Marsh)
# This grammar is based on POSIX specs (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
# This document is released under `Unlicense` Public Domain License Agreement | (C) 2024 Chubak Bidpaa | No Warranty
# A: Lexical Grammar for POSIX Shell