Linux Format

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.

More from Linux Format

Linux Format5 min read
Some Ansible Advice For Around The Home!
Of late, this writer has been busy creating new virtual hosts for different things and decided that it would be an ideal time to get stuck into Ansible. Things have evolved in system management since Bash. Ansible is a great way to deploy software c
Linux Format14 min read
Ubuntu at 20
Without Ubuntu, the current Linux landscape would be unrecognisable. Back in October 2004, the first 4.10 (2004.10) release of Ubuntu, with its intriguing Warty Warthog code name, leapt from obscurity to being one of the most downloaded Linux distrib
Linux Format3 min read
Kernel Watch
Linus Torvalds announced the fourth RC (Release Candidate) for what will become Linux 6.9 in another few weeks. In his announcement, he noted that there was “Nothing particularly unusual going on this week – some new hardware mitigations may stand o

Related