Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PERL TUTORIALS > THE ROAD TO BETTER PROGRAMMING: CHAPTER 8. THE TOP LEVEL AND COMPOUND CLASS PARSERS


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

The road to better programming: Chapter 8. The top-level and compound-class parsers
By Teodor Zlatanov - 2004-03-22 Page:  1 2 3 4 5 6 7

cfperl learns to talk

In this installment, Ted explains the workings of cfperl's top-level and compound-class parsers and moves us towards a clearer understanding of the important roles parsers play.

This chapter is from Ted's book, At the Helm, being published serially on the Web in the developerWorks column The road to better programming. Catch up on Ted's earlier chapters.

To get the most out of this article, you might first want to read Chapter 6 and Chapter 7, where I describe the impetus for and early coding decisions of the cfperl project.

The top-level cfperl parser processes every configuration line before the line is granted meaning. The distinction is important. The top-level parser gets data in the form of lines of text. Its job is to distill the information from that data. The top-level parser will, for instance, remove all comments on a line by themselves, and all blank lines. All processed, and thus meaningful (to the cfperl interpreter), data is encapsulated for the second-level parsers. It is thus easier to write a second-level parser (for instance, a parser that interprets editing commands) when the top-level parser has taken care of removing conditional execution, blank lines, and other extraneous (to editing) information.

The top-level cfperl parser is the place where cfengine sections, compound classes (a sequence of classes separated by OR ["|"] and AND ["."] symbols, to build a boolean statement), and configuration action lines (anything to be parsed by a second-level parser) are parsed. Each one of those items will be explained in this article. Keep in mind that cfperl is a project in progress, and the cfperl version you see on the cfperl Web site may be different from the static version used in this article (see Resources for links to the Web site and the cfperl.pl download).

To understand the following sections, you must understand the basics of the Parse::RecDescent module. The Resources section has links to previous articles on this very useful module, if you need that background. Also in Resources you will find a link to a sample cfengine configuration, which is essential to understanding the purpose and structure of cfperl.

On another note, I have abstained from actually naming the "#" character the way I name ":" (colon), for instance. The "#" character has at least 10 names, most commonly "pound" and "hash," but use of any particular name is guaranteed to confuse 50 percent of the readers.



View The road to better programming: Chapter 8. The top-level and compound-class parsers Discussion

Page:  1 2 3 4 5 6 7 Next Page: The grammar basics

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.