Why Sponsor Oils? | blog | oilshell.org

New Terminology: Static Parsing vs. Dynamic Parsing

2016-10-22

I realized that there's an obvious term for what I wrote about in the last post -- static parsing, as opposed to dynamic parsing.

This is analogous to static typing vs. dynamic typing. This distinction describes whether you know the types of variables before you run the program (at compile-time), or only while you run it (at runtime).

In a statically parsed language, you know the parse tree up front, as well as the presence of parse errors. In a dynamically parsed one, you don't know until runtime.

Java is statically parsed and statically typed. Python and JavaScript are statically parsed but dynamically typed.

I suppose it's impossible to be statically typed and dynamically parsed, because you need a parse tree to check types. But I think this term is fairly obvious and useful, at least for the purposes of talking about the shell language. I will rephrase my previous posts in these terms:

A few more useful applications of this term:

Back to the main point: Intuitively, I would equated "dynamically parsed" with "70's style macro language", and "statically parsed" with "language implemented using a real parser".

What I think is surprising is that, except for an extension introduced with bash 4.0 in 2009, shell is statically parseable. I think many people are under the impression that it's an ugly and unparseable macro language. The syntax is definitely unusual, but it is relatively well defined and statically parseable.

In the next few posts I will show some of the ugly corners of shell syntax that I've hit while developing my parser.