实时线上存档:
#include <bits/stdc++.h>
using namespace std;
string Line;
const string Names[9] = {"string", "int", "long long", "short", "char", "bool", "unsigned int", "unsigned long long", "unsigned short"}, No_spiltint[8] = {"'", "unsigned", "string", "int", "long", "short", "char", "bool"};
long long ats[9];
bool Error, End;
struct String
{
string Name, Key;
}Stringer[114514];
struct Int
{
string Name;
int Key;
}Inter[114514];
struct Long_long
{
string Name;
long long Key;
}Long_longer[114514];
struct Short
{
string Name;
short Key;
}Shorter[114514];
struct Char
{
string Name;
char Key;
}Charer[114514];
struct Bool
{
string Name;
bool Key;
}Booler[114514];
struct Unsigned_int
{
string Name;
unsigned int Key;
}Unsigned_inter[114514];
struct Unsigned_long_long
{
string Name;
unsigned long long Key;
}Unsigned_long_longer[114514];
struct Unsigned_short
{
string Name;
unsigned short Key;
}Unsigned_shorter[114514];
inline int Get_int(long long Sub, string Getline)
{
int Key = 0;
if (Getline[Sub] == '\'')
{
Sub++;
Key = Getline[Sub];
Sub++;
if (Getline[Sub] == '\'')
{
return Key;
}
else
{
Error = 1;
return 0;
}
}
else if (Getline[Sub] == 't')
{
Sub++;
if (Getline[Sub] == 'r')
{
Sub++;
if (Getline[Sub] == 'u')
{
Sub++;
if (Getline[Sub] == 'e')
{
return 1;
}
else
{
Error = 1;
return 0;
}
}
else
{
Error = 1;
return 0;
}
}
else
{
Error = 1;
return 0;
}
}
else if (Getline[Sub] == 'f')
{
Sub++;
if (Getline[Sub] == 'a')
{
Sub++;
if (Getline[Sub] == 'l')
{
Sub++;
if (Getline[Sub] == 's')
{
Sub++;
if (Getline[Sub] == 'e')
{
return 0;
}
else
{
Error = 1;
return 0;
}
}
else
{
Error = 1;
return 0;
}
}
else
{
Error = 1;
return 0;
}
}
else
{
Error = 1;
return 0;
}
}
else if (Getline[Sub] >= '0' && Getline[Sub] <= '9')
{
while (Getline[Sub] != ',' && Getline[Sub] != ' ' && Getline[Sub] != ';')
{
if (Getline[Sub] >= '0' && Getline[Sub] <= '9')
{
Key = (Key << 3) + (Key << 1) + (Getline[Sub] - '0');
}
else
{
Error = 1;
return 0;
}
Sub++;
}
return Key;
}
Error = 1;
return 0;
}
inline bool Add_value(long long Type, string Value_name)
{
if (Value_name == "")
{
Error = 1;
return 0;
}
for (long long i = 0; i < 8; i++)
{
if (No_spiltint[i] == Value_name)
{
Error = 1;
return 0;
}
}
switch (Type)
{
case 0:
for (long long i = 0; i < ats[0]; i++)
{
if (Stringer[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Stringer[ats[0]++].Name = Value_name;
break;
case 1:
for (long long i = 0; i < ats[1]; i++)
{
if (Inter[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Inter[ats[1]++].Name = Value_name;
break;
case 2:
for (long long i = 0; i < ats[2]; i++)
{
if (Long_longer[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Long_longer[ats[2]++].Name = Value_name;
break;
case 3:
for (long long i = 0; i < ats[3]; i++)
{
if (Shorter[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Shorter[ats[3]++].Name = Value_name;
break;
case 4:
for (long long i = 0; i < ats[4]; i++)
{
if (Charer[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Charer[ats[4]++].Name = Value_name;
break;
case 5:
for (long long i = 0; i < ats[5]; i++)
{
if (Booler[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Booler[ats[5]++].Name = Value_name;
break;
case 6:
for (long long i = 0; i < ats[6]; i++)
{
if (Unsigned_inter[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Unsigned_inter[ats[6]++].Name = Value_name;
break;
case 7:
for (long long i = 0; i < ats[7]; i++)
{
if (Unsigned_long_longer[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Unsigned_long_longer[ats[7]++].Name = Value_name;
break;
case 8:
for (long long i = 0; i < ats[8]; i++)
{
if (Unsigned_shorter[i].Name == Value_name)
{
Error = 1;
return 0;
}
}
Unsigned_shorter[ats[8]++].Name = Value_name;
break;
default:
Error = 1;
return 0;
}
return 1;
}
inline long long Find_l_or_r(string Getline, string Find_string, long long L, long long R, bool Flag)
{
if (Getline.length() < Find_string.length())
{
return -1;
}
bool F = 1;
if (Flag)
{
for (long long i = L; i <= R - Find_string.length() + 1; i++)
{
F = 1;
for (long long j = i; j < i + Find_string.length(); j++)
{
if (Getline[j] != Find_string[j - i])
{
F = 0;
continue;
}
}
if (F)
{
return i;
}
}
}
else
{
for (long long i = R - Find_string.length() + 1; i >= L; i--)
{
F = 1;
for (long long j = i; j < i + Find_string.length(); j++)
{
if (Getline[j] != Find_string[j - i])
{
F = 0;
continue;
}
}
if (F)
{
return i + Find_string.length() - 1;
}
}
}
return -1;
}
inline bool Delete_space(string Getline)
{
for (long long i = 0; i < 8; i++)
{
if (Find_l_or_r(Getline, No_spiltint[i], Getline.length() - No_spiltint[i].length(), Getline.length() - 1, 1) != -1)
{
return 0;
}
}
return 1;
}
inline string Getl()
{
bool Flag = 0;
char C = getchar();
string Getline;
if (C == EOF)
{
End = 1;
return "";
}
while (C == '\n' || C == ' ')
{
C = getchar();
}
while (C != '\n')
{
if (C == '"' && Getline[Getline.length() - 1] != '\\' && Getline[Getline.length() - 1] != '\'')
{
Flag ^= 1;
}
if ((C == ' ' && !(Delete_space(Getline))) || C != ' ' || Flag)
{
Getline += C;
}
C = getchar();
}
return Getline;
}
inline void Find_values(string Getline)
{
long long Sub, Add, j;
string Value_name;
for (long long i = 0; i < 9; i++)
{
Sub = Find_l_or_r(Getline, Names[i], 0, Getline.length(), 1);
while (Sub != -1)
{
Value_name = "";
if (!((Getline[Sub] >= 'a' && Getline[Sub] <= 'z') || (Getline[Sub] >= 'A' && Getline[Sub] <= 'Z') || (Getline[Sub] == '_')))
{
Error = 1;
}
Sub += Names[i].length() + 1;
j = Sub;
for (; (Getline[j] >= 'a' && Getline[j] <= 'z') || (Getline[j] >= 'A' && Getline[j] <= 'Z') || (Getline[j] >= '0' && Getline[j] <= '9') || (Getline[j] == '_'); j++)
{
Value_name += Getline[j];
}
Add = Add_value(i, Value_name);
if (Add)
{
if (Getline[j] == '=')
{
j++;
switch (i)
{
case 0:
//暂未完成
case 1:
Inter[ats[1] - 1].Key = Get_int(j, Getline);
break;
/*
case 2:
//暂未完成
case 3:
//暂未完成
case 4:
//暂未完成
case 5:
//暂未完成
case 6:
//暂未完成
case 7:
//暂未完成
case 8:
//暂未完成
*/
}
while (j != ',' && j != ';')
{
j++;
}
}
else if (Getline[j] == ',')
{
while (Getline[j] == ',')
{
j++;
Value_name = "";
if (!((Getline[j] >= 'a' && Getline[j] <= 'z') || (Getline[j] >= 'A' && Getline[j] <= 'Z') || (Getline[j] == '_')))
{
Error = 1;
}
for (; (Getline[j] >= 'a' && Getline[j] <= 'z') || (Getline[j] >= 'A' && Getline[j] <= 'Z') || (Getline[j] >= '0' && Getline[j] <= '9') || (Getline[j] == '_'); j++)
{
Value_name += Getline[j];
}
Add = Add_value(i, Value_name);
if (Add)
{
if (Getline[j] == '=')
{
j++;
switch (i)
{
case 0:
//暂未完成
case 1:
Inter[ats[1] - 1].Key = Get_int(j, Getline);
break;
/*
case 2:
//暂未完成
case 3:
//暂未完成
case 4:
//暂未完成
case 5:
//暂未完成
case 6:
//暂未完成
case 7:
//暂未完成
case 8:
//暂未完成
*/
}
while (j != ',' && j != ';' && j < Getline.length())
{
j++;
}
}
}
}
}
else if (Getline[j] != ';')
{
Error = 1;
}
}
Sub = Find_l_or_r(Getline, Names[i], Sub, Getline.length(), 1);
}
}
return ;
}
inline bool Do(string Line)
{
//暂未完成
}
signed main()
{
printf("Welcome to use the \"C--24\".\n");
while (!(Error) && !(End))
{
Line = Getl();
Find_values(Line);
//Error = Do(Line);
}
if (Error)
{
printf("Error!\n");
}
else
{
printf("OK!\n");
}
return 0;
}
最后更新时间:
后记:
仍有部分 尚未修复(或暂时无法修复),敬请谅解!
懒得更新了。。。