Skip to content

Commit

Permalink
fixp arser partially
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed Oct 15, 2024
1 parent 6c48177 commit a5530f2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions irparser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static Operation parse_op(char * line, size_t line_len)
while (isspace(*line)) line ++;

char * comma = strchr(line, ',');
char * last = comma ? comma : (assign - 1);
char * last = comma ? comma : assign;
size_t count = last - line;

char* buf = malloc(count + 1);
Expand All @@ -79,6 +79,9 @@ static Operation parse_op(char * line, size_t line_len)
op.outputs.items = realloc(op.outputs.items, (op.outputs.count + 1) * sizeof(char*));
op.outputs.items[op.outputs.count ++] = buf;

if (comma > assign)
break;

if (comma)
line = comma + 1;
else
Expand Down Expand Up @@ -113,6 +116,7 @@ static Operation parse_op(char * line, size_t line_len)
{
char * eqsign = strchr(line, '=');
assert(eqsign);
assert(eqsign < close);
*eqsign = '\0';
char * space = strchr(line, ' ');
if (space) *space = '\0';
Expand Down Expand Up @@ -145,12 +149,13 @@ static Operation parse_op(char * line, size_t line_len)
op.operands.items = realloc(op.operands.items, sizeof(Operand) * (op.operands.count + 1));
op.operands.items[op.operands.count ++] = operand;

if (comma)
line = comma + 1;
else
line = last + 1;
if (!comma)
break;
}

while (isspace(*line)) line ++;

assert(*line == ')'); line ++; assert(*line == '\0');

return op;
Expand Down Expand Up @@ -281,12 +286,12 @@ CompPattern Pattern_compile(const char * source)
size_t line_len = nt_ptr - source;
if (line_len + 1 > linebuf_len)
{
linebuf_len = line_len + 1;
linebuf_len = line_len;
linebuf = realloc(linebuf, linebuf_len);
memcpy(linebuf, source, line_len);
linebuf[line_len] = '\0';
}
source += line_len;
memcpy(linebuf, source, line_len);
linebuf[line_len-1] = '\0';
source += line_len + 1;
Operation op = parse_op(linebuf, line_len);
out.operations.items = realloc(out.operations.items, (out.operations.count + 1) * sizeof(Operation));
out.operations.items[out.operations.count ++] = op;
Expand Down

0 comments on commit a5530f2

Please sign in to comment.