Skip to content

Instantly share code, notes, and snippets.

@ponyatov
ponyatov / ESD.peg
Created Feb 8, 2019
ESD parser grammar
View ESD.peg
splitter "parse words divided by spaces"
= _? x:(y:word _? { return y } )* { return x }
word
= number
/ w:[^ \t\n\r]+ { return w.join('') }
_ "space"
= s:[ \t\n\r]+ { return s.join('') }
View Rply_compiler.py
# for https://www.youtube.com/watch?v=v6y-57zw3zg
src = '''
nop
nop
.
1 + 2 * 3
.
bye
'''
@ponyatov
ponyatov / RPython_FORTH.py
Created Mar 25, 2017
Using PLY with RPython (FORTH-like VM)
View RPython_FORTH.py
src = '''
nop
nop
.
1 2 3
.
bye
'''
D = [] # data stack
@ponyatov
ponyatov / hpp.hpp
Last active Aug 18, 2016
parser-enabled program required #includes
View hpp.hpp
#ifndef _H_HPP
#define _H_HPP
// required includes
#include <iostream>
#include <cstdlib>
#include <vector>
#include <map>
using namespace std;
#include "meta.hpp"
// algebraic data type (base class)
@ponyatov
ponyatov / hpp.hpp
Created Aug 18, 2016
.hpp include once
View hpp.hpp
#ifndef _H_HPP
#define _H_HPP
...
#endif // _H_HPP
View bat.bat
@start .
@gvim -p src.src log.log ypp.ypp lpp.lpp hpp.hpp cpp.cpp
@rem Makefile .gitignore bat.bat README.md
View mk_lexical_project.bat
rem first create your project on github & clone it locally
git clone -o gh git@github.com:ponyatov/skelex.git
rem create project files
cd skelex
touch src.src log.log ypp.ypp lpp.lpp hpp.hpp cpp.cpp Makefile .gitignore bat.bat
rem create (g)vim helper for windows
echo @gvim -p src.src log.log ypp.ypp lpp.lpp hpp.hpp cpp.cpp Makefile .gitignore bat.bat >> bat.bat
View .gitignore
*~
*.swp
*.exe
*.log
ypp.tab.?pp
lex.yy.c
View meta.hpp
#define TITLE "skelex"
#define ABOUT "lexical program skeleton"
#define LICENSE "GNU Lesser GPL"
#define AUTHOR "Dmitry Ponyatov <<dponyatov@gmail.com>>"
#define COPYRIGHT "(c) " AUTHOR " , " LICENSE
#define GITHUB "https://github.com/ponyatov/sym" TITLE
View Makefile
log.log: src.src ./exe.exe
./exe.exe < $< > $@ && tail $(TAIL) $@
C = cpp.cpp $(OS).cpp ypp.tab.cpp lex.yy.c
H = hpp.hpp $(OS).hpp ypp.tab.hpp meta.hpp
CXXFLAGS += -std=gnu++11
./exe.exe: $(C) $(H)
$(CXX) $(CXXFLAGS) -o $@ $(C) $(L)
ypp.tab.cpp: ypp.ypp
bison $<
lex.yy.c: lpp.lpp