# W3C PICS Simple Parser Example

Following is example output from the LablPars program:

    (PICS-1.1
     "http://www.ages.org/our-service/v1.0/"           1
     labels   2
      for "http://www.w3.org/pub/WWW/"   3   5
      generic true
      by "abaird@w3.org"
      ratings (age 11)         6  -6  -5  -3

      for "http://www.w3.org/pub/WWW/"   3   5
      generic true
      by "abaird@w3.org"
      ratings (age 11)         6  -6  -5  -3
      error (not-labeled "http://www.w3.org/unknown")    3  11 -11  -3

     "http://www.rsac.org/v1.0"
     labels  -2   2
      for "http://www.w3.org/pub/WWW"   3   5
      generic true
      by "abaird@w3.org"
      ratings (v 0 s 0 n 0 l 0)   6  -6   6  -6   6  -6   6  -6  -5  -3
      for "http://www.w3.org/pub/WWW"   3   5
      generic true
      by "abaird@w3.org"
      ratings (v 0 s 0 n 0 l 0)   6  -6   6  -6   6  -6   6  -6  -5  -3
      error (not-labeled "http://www.w3.org/unknown")   3  11 -11  -3

     error (no-ratings "unknown service"))  -2   2   9  -9  -2  -1 = 0 - parsing end

## What you see

LablPars reads each line of its input and displays it before passing it to the parser. As the parser is reading the line, it makes callbacks to LablPars to notify when a new data type is being started or finished. This callback displays the enumerated value for the data type being processed.

    LabelTargetCallback_t targetCallback;
    StateRet_t targetCallback(CSLabel_t * pCSMR, CSParse_t * pCSParse,
    			  CSLLTC_t target, BOOL closed, void * pVoid)
    {
        int change = closed ? -target : target;

        Total += change;
        printf("%3d ", change);
        return StateRet_OK;
    }

These values are defined in CSLL.html.

    typedef enum {
    	CSLLTC_LIST = 1,
    	CSLLTC_SERVICE,
    	CSLLTC_LABEL,
    	CSLLTC_LABTREE,
    	CSLLTC_SINGLE,
    	CSLLTC_RATING,
    	CSLLTC_RANGE,
    	CSLLTC_AWKWARD,
    	CSLLTC_NORAT,
    	CSLLTC_SRVERR,
    	CSLLTC_LABERR,
    	CSLLTC_EXTEN,
    	CSLLTC_EXTDATA,
    	CSLLTC_COUNT
    } CSLLTC_t;

We can see from the lines

     labels   2
      for "http://www.w3.org/pub/WWW/"   3   5

that the labels keyword told the parser that it had started a service, and the for keyword denoted a single-label within a label. As the parser finishes a data type, it calls the callback again to say that the data is finished:

     error (no-ratings "unknown service"))  -2   2   9  -9  -2  -1 = 0 - parsing end

"-2 -1" closes the service and the list. The sum of 0 shows that each data type entered was exited appropriately. "parsing end" shows that the parser had closed all data types and assumed that the input would be finished.