Hacker News new | ask | show | jobs
by vkazanov 296 days ago
Parsing is almost always a part of a programming language compiler but it doesn't have to be.

When we parse a string, we go up from low-level human-readable strings to intermediate parse trees to a high-level AST.

A process of compilation goes down from some kind of a high-level internal representation through phases to something that is close to the target low-level language.

It can go down from an AST, or LLVM-s internal representation, or whatever.

Problems solved by both processes are different:

1. Parsing is about finding string patterns (using regexps or PEGs or whatever) and representing these using a more strict high-level structure. The structure is usually tree-like but is also often a graph.

2. Compiling takes something high-level (a tree, a graph, etc) and emits something different, usually simplified.

A good example is a typical lisp implementation where the parser is trivial but compilation phases represent numerous simplifying phases.