Skip to content

Instantly share code, notes, and snippets.

@mattmcd
mattmcd / print_sympy_expr.py
Created January 24, 2021 15:41
Printing a SymPy LaTeX expression to png e.g. for Markdown or Medium
from subprocess import run
import sympy as sp
def print_to_file(fname, expr):
# See https://tex.stackexchange.com/questions/34054/tex-to-image-over-command-line/34058#34058
t_start = r"""\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\usepackage{varwidth}
\begin{document}
@mattmcd
mattmcd / CFunction.g4
Created April 21, 2013 12:26
ANTLR4 version of Wrapper Generator
grammar CFunction;
function : retType name args ;
args : '(' arg (',' arg)* ')' ;
arg
: 'double' name # SCALAR_ARG
| 'double' '*' name # ARRAY_ARG
@mattmcd
mattmcd / Expr.g4
Created March 30, 2013 18:46
ANTLR4 simple expression grammar. Note that left recursion is now allowed and operator precedence is just order of definition.
grammar Expr;
// Need to call recursive rule expr from non-recursive rule
r : expr+ ;
// ANTLR4 : Left recursion!
// Operator precedence matches order of definition
expr : '-' expr // Unary minus
| expr ('*' | '/' ) expr
| expr ('+' | '-' ) expr
@mattmcd
mattmcd / Hello.g4
Last active April 19, 2024 08:04
Simple ANTLR4 grammar example
// define a grammar called Hello
grammar Hello;
r : 'hello' ID;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;