-
-
Notifications
You must be signed in to change notification settings - Fork 163
Language Composition Bestiary
andychu edited this page Oct 3, 2017
·
13 revisions
Languages are generally composed using strings in Unix. This has well-known downsides like escaping problems leading to code injection attacks.
There are two ways that languages are composed using strings.
- One language can accept a string in another language (eval)
- One language can generate another: The most basic form of Metaprogramming
Shell:
-
sh
insh
:eval 'echo hi'
-
sh
inawk
:system('ls | wc -l')
-
sh
inmake
- every single line in the actions in
sh
inmake
!!!.ONESHELL
changes the semantics a bit. -
$(shell find /)
-- capturing it in a variable rather than an action.
- every single line in the actions in
-
sh
in Python/C, etc:os.system()
Make:
-
make
inmake
:$(eval $(mycode))
Other:
- X in
sh
. Shell is special, because more binaries have something like-e
python -c
perl -e
awk '{print $1}'
sed -e
- python in python:
eval('1+2')
,exec 'print "hi"'
-
shell generating shell
-
sed generating C
-
awk generating C: TODO: Python build system had a sed example I rewrote in Awk. Shell
-
C preprocessor generating C
-
cmake generating Makefiles
-
autoconf
- m4 generating things that generate shell, make, C headers (config.h)
-
Makefile.pre.in
,config.h.in
, etc.
- JS in HTML:
<script></script>
<onload="">
- CSS in HTML:
<style></style>
<p style="">
- HTML in JS:
document.innerHTML = '<p>hi</p>'
- special extension: JSX, which is PHP-like
- CSS in JS:
element.style = 'font-size: large;'
document.querySelectorAll('#id')