version 1.5, 2004/09/10 22:21:27 |
version 1.10, 2020/10/06 11:33:47 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/scanner2.c,v 1.4 2004/09/10 13:20:23 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 106 static int getSM() |
|
Line 114 static int getSM() |
|
fprintf(stderr,"\n"); |
fprintf(stderr,"\n"); |
} |
} |
|
|
c = 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 147 static struct tokens flushSM() |
|
Line 159 static struct tokens flushSM() |
|
strcpy(token,BufSM); |
strcpy(token,BufSM); |
r.token = token; |
r.token = token; |
r.kind = TypeSM; |
r.kind = TypeSM; |
|
r.tflag = 0; |
if (r.kind == ID) { |
if (r.kind == ID) { |
if (isLiteral(r.token)) { |
if (isLiteral(r.token)) { |
r.object = lookupLiteralString(r.token); |
r.object = lookupLiteralString(r.token); |
Line 157 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 207 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 312 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); |