Comments added
This commit is contained in:
parent
f1aba7c217
commit
a057f8e72c
1 changed files with 50 additions and 19 deletions
|
@ -1,14 +1,40 @@
|
|||
#include <stdio.h>
|
||||
|
||||
FILE *infile = stdin;
|
||||
/* This file contains the scanner for mylex(), the following functions and
|
||||
* variables are exported :
|
||||
*
|
||||
* int yylineno; - The current line number.
|
||||
*
|
||||
* char scanc(); - Return next character.
|
||||
*
|
||||
* backc( c); - Push back one character.
|
||||
* char c;
|
||||
*
|
||||
* FILE *switch_input( new); - Scanner will from now on read from
|
||||
* FILE *new; - 'new', old input-file is returned.
|
||||
*
|
||||
* The scanner must perform a lookahead of more than one character, so it uses
|
||||
* it's own internal buffer.
|
||||
*/
|
||||
|
||||
|
||||
#define BUF_SIZE 16
|
||||
char buf[BUF_SIZE], /* Bufer to save backc()-characters */
|
||||
*bufptr = buf; /* Pointer to space for backc()-character */
|
||||
int yylineno = 1;
|
||||
|
||||
|
||||
char nextc()
|
||||
/********* Internal variables + functions ***********************/
|
||||
|
||||
|
||||
#define BUF_SIZE 16
|
||||
|
||||
static char buf[BUF_SIZE], /* Bufer to save backc()-characters */
|
||||
*bufptr = buf; /* Pointer to space for backc()-character */
|
||||
|
||||
static FILE *infile = stdin;
|
||||
|
||||
|
||||
|
||||
|
||||
static char nextc()
|
||||
{
|
||||
if ( bufptr > buf)
|
||||
return( *--bufptr);
|
||||
|
@ -17,25 +43,15 @@ char nextc()
|
|||
}
|
||||
|
||||
|
||||
backc( c)
|
||||
char c;
|
||||
{
|
||||
if ( bufptr > buf + BUF_SIZE)
|
||||
error( "backc(), no space in buffer left!");
|
||||
else {
|
||||
if ( c == '\n')
|
||||
yylineno--;
|
||||
*bufptr++ = c;
|
||||
}
|
||||
}
|
||||
/***************************************************************/
|
||||
|
||||
|
||||
char scanc()
|
||||
|
||||
/* Get next character, but delete al C-comments */
|
||||
/* Get next character, but delete al C-comments and count lines */
|
||||
|
||||
{
|
||||
char c;
|
||||
char c, nextc();
|
||||
|
||||
c = nextc();
|
||||
while ( c == '/') {
|
||||
|
@ -56,10 +72,25 @@ char scanc()
|
|||
}
|
||||
|
||||
|
||||
backc( c)
|
||||
char c;
|
||||
{
|
||||
if ( bufptr >= buf + BUF_SIZE)
|
||||
error( "backc(), no space in buffer left!");
|
||||
else {
|
||||
if ( c == '\n')
|
||||
yylineno--;
|
||||
*bufptr++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FILE *switch_input( new)
|
||||
FILE *new;
|
||||
|
||||
/* Return the current FILE, if buf[] can't be cleaned NULL will be returned */
|
||||
/* Switch to a new input file, try to save the lookahead-characters in buf[]
|
||||
* by calling ungetc(). If they can't be saved return NULL.
|
||||
*/
|
||||
|
||||
{
|
||||
char *ptr; FILE *old;
|
||||
|
|
Loading…
Reference in a new issue