version 1.7, 2005/01/23 02:41:17 |
version 1.10, 2020/10/06 11:33:47 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/scanner2.c,v 1.6 2004/09/12 00:26:21 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/scanner2.c,v 1.9 2005/07/18 10:55:16 takayama Exp $ */ |
/* scanner2.c (SM StackMachine) */ |
/* scanner2.c (SM StackMachine) */ |
/* export: struct tokens decompostToTokens(char *str,int *sizep); |
/* export: struct tokens decompostToTokens(char *str,int *sizep); |
scanner2.c is for getting tokens from a string. |
scanner2.c is for getting tokens from a string. |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "stackm.h" |
#include "stackm.h" |
struct tokens lookupTokens(struct tokens t); |
struct tokens lookupTokens(struct tokens t); |
Line 47 static int TypeSM = ID; |
|
Line 49 static int TypeSM = ID; |
|
/**************** end of declaration part of lexical analizer ******/ |
/**************** end of declaration part of lexical analizer ******/ |
|
|
static int getSM(); |
static int getSM(); |
static putSM(); |
static void putSM(); |
static struct tokens flushSM(); |
static struct tokens flushSM(); |
static isSpaceSM(); |
static int isSpaceSM(); |
static isDollarSM(); |
static int isDollarSM(); |
static isBraceSM(); |
static int isBraceSM(); |
static isKakkoSM(); |
static int isKakkoSM(); |
static isSymbolSM(); |
static int isSymbolSM(); |
static struct tokens getokenSM2(); |
static struct tokens getokenSM2(); |
|
|
|
void errorScanner2(char *str); |
|
|
|
extern int ScannerWhich; |
|
extern unsigned char ScannerBuf[]; |
|
extern int ScannerPt; |
|
|
/**************** code part of lexical analizer ********************/ |
/**************** code part of lexical analizer ********************/ |
|
|
struct tokens *decomposeToTokens(str,sizep) |
struct tokens *decomposeToTokens(str,sizep) |
Line 107 static int getSM() |
|
Line 115 static int getSM() |
|
} |
} |
|
|
c = (unsigned char) StringSM[StrpSM++]; |
c = (unsigned char) StringSM[StrpSM++]; |
|
if (c != 0) { |
|
ScannerPt++; if (ScannerPt >= SCANNERBUF_SIZE) ScannerPt = 0; |
|
ScannerBuf[ScannerPt] = c; |
|
} |
if (c == '\0') { |
if (c == '\0') { |
StrpSM--;return(EOF); |
StrpSM--;return(EOF); |
} else return(c); |
} else return(c); |
} |
} |
|
|
static putSM(c) |
static void putSM(c) |
int c; |
int c; |
/* put a letter on BufSM */ |
/* put a letter on BufSM */ |
{ |
{ |
Line 158 static struct tokens flushSM() |
|
Line 170 static struct tokens flushSM() |
|
return(r); |
return(r); |
} |
} |
|
|
static isSpaceSM(c) |
static int isSpaceSM(c) |
int c; |
int c; |
{ |
{ |
if (((c <= ' ') || c == ',') && (c!= EOF)) return(1); |
if (((c <= ' ') || c == ',') && (c!= EOF)) return(1); |
else return(0); |
else return(0); |
} |
} |
|
|
static isDollarSM(c) |
static int isDollarSM(c) |
int c; |
int c; |
{ |
{ |
if (c == '$') return(1); |
if (c == '$') return(1); |
else return(0); |
else return(0); |
} |
} |
|
|
static isBraceSM(c) |
static int isBraceSM(c) |
int c; |
int c; |
{ |
{ |
if (c == '{') return(1); |
if (c == '{') return(1); |
else return(0); |
else return(0); |
} |
} |
|
|
static isKakkoSM(c) |
static int isKakkoSM(c) |
int c; |
int c; |
{ |
{ |
if (c == '(') return(1); |
if (c == '(') return(1); |
else return(0); |
else return(0); |
} |
} |
|
|
static isSymbolSM(c) |
static int isSymbolSM(c) |
int c; |
int c; |
{ |
{ |
if ((c == '{') || |
if ((c == '{') || |
Line 208 static struct tokens getokenSM2(kind,str) |
|
Line 220 static struct tokens getokenSM2(kind,str) |
|
int level; |
int level; |
|
|
if (kind == INIT) { |
if (kind == INIT) { |
|
ScannerWhich = 2; |
|
ScannerPt = 0; |
|
ScannerBuf[0] = 0; |
|
|
StrpSM = 0; |
StrpSM = 0; |
ExistSM = 0; |
ExistSM = 0; |
|
|
Line 313 static struct tokens getokenSM2(kind,str) |
|
Line 329 static struct tokens getokenSM2(kind,str) |
|
/*********** end of code part of lexical analizer ********************/ |
/*********** end of code part of lexical analizer ********************/ |
|
|
|
|
errorScanner2(str) |
void errorScanner2(str) |
char *str; |
char *str; |
{ |
{ |
fprintf(stderr,"Error (scanner2.c): %s\n",str); |
fprintf(stderr,"Error (scanner2.c): %s\n",str); |