lexer.h File Reference

Header for tokenizer. More...

#include <stdio.h>
#include <errno.h>
#include <pcre.h>

Include dependency graph for lexer.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Enumerations

enum  elex {
  LEX_RE = 3, LEX_REOFF = 2, LEX_SUB = 5, LEX_TAG = 0,
  LEX_ELEMENT = 1, LEX_PAIRS = 2, LEX_CONTENT = 3, LEX_REGOK = 0,
  LEX_ERR = EINVAL, LEX_REGDEF = 0, LEX_REG = PCRE_CASELESS | PCRE_DOTALL, LEX_BEGIN = 0,
  LEX_END = 1, LEX_OFFSET = 0
}

Functions

int lex (char *, const char *, void(*)(char *))
 Parses source according to mask; gives thence unto arbitrary appellant.
int lexbuf (char *, const char *, void(*)(char *, char **), char **)
 Parses source according to mask; gives thence unto arbitrary appellant and deposits in receptant buffer.


Detailed Description

Header for tokenizer.

Definition in file lexer.h.


Enumeration Type Documentation

enum elex
 

PCRE constants

Enumeration values:
LEX_RE  PCRE vector constant
LEX_REOFF  PCRE offset
LEX_SUB  sub expressions
LEX_TAG  tag subexpression
LEX_ELEMENT  element subexpression
LEX_PAIRS  pair subexpression
LEX_CONTENT  content subexpression
LEX_REGOK  PCRE match
LEX_ERR  default errno
LEX_REGDEF  PCRE compile parameters
LEX_REG  PCRE execution parameters
LEX_BEGIN  begin offset
LEX_END  end offset
LEX_OFFSET  string offset

Definition at line 11 of file lexer.h.

00011           {
00012   LEX_RE = 3,                   
00013   LEX_REOFF = 2,                
00014   LEX_SUB = 5,                  
00015   LEX_TAG = 0,                  
00016   LEX_ELEMENT = 1,              
00017   LEX_PAIRS = 2,                
00018   LEX_CONTENT = 3,              
00019   LEX_REGOK = 0,                
00020   LEX_ERR = EINVAL,             
00021   LEX_REGDEF = 0,               
00022   LEX_REG = PCRE_CASELESS | PCRE_DOTALL, 
00023   LEX_BEGIN = 0,                
00024   LEX_END = 1,                  
00025   LEX_OFFSET = 0                
00026 };


Function Documentation

int lex char *  pcin,
const char *  pcmask,
void(*)(char *)  pfcallback
 

Parses source according to mask; gives thence unto arbitrary appellant.

Parameters:
pcin lectand
pcmask lectant
pfcallback lector
Returns:
EXIT_{SUCCESS, FAILURE}

Definition at line 39 of file lexer.c.

References EVAL, LEX_BEGIN, LEX_END, LEX_ERR, LEX_OFFSET, LEX_RE, LEX_REG, LEX_REGDEF, NONE, and STRSUB.

Referenced by parse().

00040 {
00041   pcre *pre;
00042   int icur = 0, aisub[LEX_RE], ire, iret = EXIT_SUCCESS;
00043   const char *pcerr = "lexer.c lex()";
00044   const char *pcprint = "%.*s";
00045   const char *pcre;
00046   char NONE(*pclex);
00047   
00048   /* Compile the expression. */
00049   EVAL((pre = pcre_compile(pcmask, LEX_REG, &pcre, &ire, NULL)) == NULL, LEX_ERR);
00050 
00051   /* Match successively. */
00052   while (pcre_exec(pre, NULL, pcin += icur, strlen(pcin), LEX_OFFSET, LEX_REGDEF, aisub, LEX_RE) >= LEX_REGOK) {
00053     fprintf(stdout, pcprint, aisub[LEX_BEGIN], pcin);
00054     STRSUB(pclex, pcin + aisub[LEX_BEGIN], aisub[LEX_END] - aisub[LEX_BEGIN]);
00055     pfcallback(pclex);
00056     icur = aisub[LEX_END];
00057   }
00058 
00059   /* Make shine the buffer's surplus. */
00060   fputs(pcin, stdout);
00061 
00062  cleanup:
00063   free(pclex);
00064   pcre_free(pre);
00065   return iret;
00066 }

int lexbuf char *  pcin,
const char *  pcmask,
void(*)(char *, char **)  pfcallbackbuf,
char **  ppcbuf
 

Parses source according to mask; gives thence unto arbitrary appellant and deposits in receptant buffer.

Parameters:
pcin lectand
pcmask lectant
pfcallbackbuf lector
ppcbuf lectate
Returns:
EXIT_{SUCCESS, FAILURE}

Definition at line 74 of file lexer.c.

References ALLOC, EVAL, LEX_BEGIN, LEX_END, LEX_ERR, LEX_OFFSET, LEX_RE, LEX_REG, LEX_REGDEF, NONE, and STRSUB.

Referenced by translate().

00075 {
00076   pcre *pre;
00077   int icur = 0, aisub[LEX_RE], ire, iret = EXIT_SUCCESS;
00078   const char *pcerr = "lexer.c lex()";
00079   const char *pcprint = "%.*s";
00080   const char *pcre;
00081   char NONE(*pclex), NONE(*pccallback);
00082   NONE(*ppcbuf);
00083 
00084   /* Compile the expression. */
00085   EVAL((pre = pcre_compile(pcmask, LEX_REG, &pcre, &ire, NULL)) == NULL, LEX_ERR);
00086 
00087   /* Match successively. */
00088   while (pcre_exec(pre, NULL, pcin + icur, strlen(pcin), LEX_OFFSET, LEX_REGDEF, aisub, LEX_RE) >= LEX_REGOK) {
00089     ALLOC(*ppcbuf, strlen(*ppcbuf) + aisub[LEX_BEGIN]);
00090     sprintf(*ppcbuf, pcprint, aisub[LEX_BEGIN], pcin + icur);
00091 
00092     STRSUB(pclex, pcin + icur + aisub[LEX_BEGIN], aisub[LEX_END] - aisub[LEX_BEGIN]);
00093     pfcallbackbuf(pclex, &pccallback);
00094 
00095     ALLOC(*ppcbuf, strlen(*ppcbuf) + strlen(pccallback));
00096     strcat(*ppcbuf, pccallback);
00097     free(pccallback);
00098 
00099     icur = aisub[LEX_END];
00100   }
00101 
00102   /* Make shine the buffer's surplus. */
00103   ALLOC(*ppcbuf, strlen(*ppcbuf) + strlen(pcin + icur));
00104   strcat(*ppcbuf, pcin + icur);
00105 
00106  cleanup:
00107   free(pclex);
00108   pcre_free(pre);
00109   return iret;
00110 }


Generated on Tue Dec 7 06:38:25 2004 for CSCI101:ProjectLatex by  doxygen 1.3.9.1