You'll know from the books that two scientists Bakus and Naur invented simple and ingenious way to write down all the rules of a formal language step-by-step and an algorithm for checking any text. This method is called BNF. According to it we should write the rules in form of templates using non-terminals (I would call them macros). Each macro is also a rule. Rules should be written from the most general to the most specific, until all macros are represented as terminals (tokens).
For example, for HTML code, the most general rule looks like this:
|html| |#html content| |/html|
Then we write a rule for the macro
|#html content| = |#head content| |#body content|
Then the most brilliant rule:
|#body content| = |#div tag| |#body content|
And so on...
How do we check a given HTML page? We put our rules to stack - creating a template for the given HTML page and check the page token by token - if it corresponds to our template. First, we put the most general rule, |html| |#html content| |/html| and check if the token |html| is at the beginning of the page. If so, we delete both tokens from the page and the stack. Then we try to unfold the top macro in the stack (|#html content|) so that it started with the next page token. If we succeed - delete these tokens again. If not, there's a syntax error. And so on.
Here are some PDF books about syntactic analysis:
An Introduction to Syntactic Analysis and Theory
2013 by Dominique Sportiche, Hilda Koopman, Edward P. Stabler

Download PDF
Syntax: Basic Concepts and Applications
2012 by Robert Freidin

Download PDF
Natural Language Processing and Computational Linguistics
2024 by Mr. Rohit Manglik

Download PDF
See also: Top 10 eBook Organizers
How to download PDF:
1. Install Gooreader
2. Enter Book ID to the search box and press Enter
3. Click "Download Book" icon and select PDF*
* - note that for yellow books only preview pages are downloaded


