View difference between Paste ID: kJ62q4bb and 52bN38LR
SHOW: | | - or go back to the newest paste.
1
#include <cstdio>
2
#include <cstdlib>
3
#include <cstring>
4
#include <ctype.h>
5
6
struct FParseSymbol
7
{
8
	int Value;
9
	char Sym[80];
10
};
11
12
union FParseToken
13
{
14
	int val;
15
	double fval;
16
	char sym[80];
17
	char string[80];
18
	FParseSymbol *symval;
19
};
20
21
static FParseSymbol symbols[10];
22
bool FindSym (char *sym, FParseSymbol **val)
23
{
24
	// Remove loop or if here to fix
25
	for(unsigned i=0;i<10; i++)
26
	{
27
		if (strcmp (symbols[i].Sym, sym) == 0)
28
		{
29
			*val = &symbols[i];
30
			return true;
31
		}
32
	}
33
	return false;
34
}
35
36
int GetToken (char *&sourcep, FParseToken *yylval)
37
{
38
	char token[80];
39
	int toksize;
40-
	int c;
40+
41
	memset(token, 'a', 10);
42-
loop:
42+
	toksize = 10;
43-
	while (isspace (c = *sourcep++) && c != 0)
43+
	token[toksize] = 0;
44
45
	// Remove this if line to fix
46
	if (FindSym (token, &yylval->symval)) return 0;
47-
	if (isalpha (c))
47+
	strcpy (yylval->sym, token);
48-
	{       
48+
49-
		token[0] = c;
49+
	// Replacing above strcpy with this works
50-
		token[1] = c;
50+
	//memcpy(yylval->sym, token, 80);
51-
		token[2] = c;
51+
52-
		token[3] = c;
52+
53-
		token[4] = c;
53+
54-
		token[5] = c;
54+
55-
		token[6] = c;
55+
56-
		token[7] = c;
56+
	char* test = NULL;
57-
		token[8] = c;
57+
58-
		token[9] = c;
58+
59-
		token[10] = c;
59+
60-
		toksize = 10;
60+
61-
		token[toksize] = 0;
61+