update with initial syntaxer implementation

This commit is contained in:
2026-10-04 14:13:14 +03:00
parent 79642d3fd1
commit f00ed50d32
8 changed files with 188 additions and 10 deletions
+49 -3
View File
@@ -97,12 +97,14 @@ public:
void buf_clear(void)
{
memset(buffer, 0, 256);
memset(buffer, 0, MAX_TOKEN_STRING_LEN);
}
void buf_push(char c)
{
buffer[strlen(buffer)] = c;
if (int i = strlen(buffer); i < MAX_TOKEN_STRING_LEN - 1) {
buffer[i] = c;
}
}
int dispatch_to_current(char c)
@@ -140,7 +142,12 @@ public:
}
else
{
pr_debug("Unknown character skipped (" << c << "), still in idle");
// as per requirements (report all wrong symbols)
if (c != ' ' && c != '\0')
{
pr_warn("Unrecognized character: " << c);
}
return 0;
}
}
@@ -167,6 +174,34 @@ public:
}
int leave_rc(void)
{
// additional check as per requirements
{
int i, c;
#if (MAX_TOKEN_STRING_LEN % 8) == 0
for (i = 0, c = 0; i < MAX_TOKEN_STRING_LEN; i += 8)
{
c += (buffer[i+0] == '.')
+ (buffer[i+1] == '.')
+ (buffer[i+2] == '.')
+ (buffer[i+3] == '.')
+ (buffer[i+4] == '.')
+ (buffer[i+5] == '.')
+ (buffer[i+6] == '.')
+ (buffer[i+7] == '.');
}
#else
for (int i = 0, c = 0; i < MAX_TOKEN_STRING_LEN; i++)
{
c += buffer[i] == '.';
}
#endif
if (c > 1)
{
pr_warn("Too many dots in CONST: " << buffer);
return 0;
}
}
double value;
if (!sscanf(buffer, "%lf", &value))
@@ -342,4 +377,15 @@ void print_token_vector(const std::vector<Expression::Token>& tv)
std::cout << "(" << *tv[i].to_str() << ")\n";
}
void print_token_vector(const std::vector<Expression::Token>& tv, const std::vector<unsigned char>& colorcoding)
{
int i, l;
for (i = 0, l = tv.size() - 1; i < l; i++)
{
std::cout << "(" << *tv[i].to_str() << ") ";
}
std::cout << "(" << *tv[i].to_str() << ")\n";
}
}