GO Inside Parsing – how Go handles the code
This tutorial has two aspects: a theoretical one and a practical one. In the theoretical part, you will learn about parsing, grammar and regular expressions; this is how languages are built and therefore understood in terms of construction and usage. In the practical part you will see how the Go programming language parses its code, and how you can use the related Go packages to explore your Go code and reveal handy information from it.
Get regular
The term ‘regular expression’ (regex) comes from computational theory. Something called a Deterministic Finite Automaton (DFA) can implement such expressions. A DFA is a finite state machine that does not use backtracking. What? Well, backtracking occurs when the regular expression engine encounters a regex token that does not match the next character in the string. The regex engine will then back up part of what it has matched so far to try other alternatives.
In other words, the regex engine knows it can backtrack to where it selected the option and can continue with the match by trying a different option. Perl regular expressions are implemented using a Nondeterministic Finite Automaton (NFA) and therefore can use backtracking. Without the use of regular expressions and grammars, it would be impossible to specify all the valid programs of a programming language.
Figure 1 shows the
You’re reading a preview, subscribe to read more.
Start your free 30 days