Skip to content

Commit

Permalink
Compiler infix math rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
koder77 committed Feb 1, 2024
1 parent 0607741 commit 4161199
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
@@ -1,3 +1,15 @@
L1VM (3.0.0)
NEW: now math expressions can be written like this in Brackets:

{i = xd + yd}

The () brackets are not longer needed for this, to work.
The old way was:

{i = (xd + yd)}

-- Stefan Pietzonke <jay-t@gmx.net> Thur 1 Feb 2024 21:18 +0100

L1VM (2.9.0)
Added "return" to compiler. See "prog/return.l1com".

Expand Down
70 changes: 69 additions & 1 deletion comp/main.c
Expand Up @@ -596,6 +596,74 @@ S2 check_for_normal_brackets (U1 *line)
}
}

S2 check_for_infix_math (U1 *line)
{
U1 buf[MAXSTRLEN];
S4 buf_ind = 0;
S4 ind;
S4 start = 0;
S4 line_len;
U1 found_var = 0;

if (check_for_normal_brackets (line) == 0)
{
return (0);
}

line_len = strlen_safe ((const char *) line, MAXSTRLEN);
for (ind = 0; ind < line_len; ind++)
{
if (line[ind] == '=')
{
start = ind + 2;
break;
}
}
if (start == 0)
{
// error no equal sign found
return (2);
}

for (ind = start; ind < line_len; ind++)
{
if (line[ind] != ' ' && line[ind] != '}')
{
//printf ("check_for_infix_math: char: %c\n", line[ind]);

if (isOperator (line[ind]) == 1)
{
//printf ("check_for_infix_math: found operator: %c\n", line[ind]);
//printf ("check_for_infix_math: found_var: %i\n", found_var);

if (found_var == 1)
{
// infix math found
//printf ("check_for_infix_math: found infix expression!\n");

return (0);
}
found_var = 0;
}
else
{
buf[buf_ind] = line[ind];
buf_ind++;
}
}
else
{
buf[buf_ind] = '\0';
buf_ind = 0;

//printf ("check_for_infix_math: found var: %s\n", buf);

found_var++;
}
}
return (1);
}

S2 parse_line (U1 *line)
{
S4 level, j, last_arg, last_arg_2, t, v, reg, reg2, reg3, reg4, target, e, exp;
Expand Down Expand Up @@ -675,7 +743,7 @@ S2 parse_line (U1 *line)
{
// printf ("DEBUG parse_cont: '%s'\n", line);

normal_brackets = check_for_normal_brackets (line);
normal_brackets = check_for_infix_math (line);
if (normal_brackets == 2)
{
// ERROR
Expand Down
3 changes: 3 additions & 0 deletions comp/main.h
Expand Up @@ -76,4 +76,7 @@
void init_data_info_var (void);
S2 get_unused_var (void);

// parse-rpolish.c
S2 isOperator (char symbol);

#endif
2 changes: 1 addition & 1 deletion include/global.h
Expand Up @@ -141,7 +141,7 @@

// info strings:
#define COPYRIGHT_STR " 2024/winter (C) 2017-2024 Stefan Pietzonke - software research"
#define VM_VERSION_STR "2.9.0 " // version number
#define VM_VERSION_STR "3.0.0 " // version number
#define MOTTO_STR "let it snow!"

// no user defined definitions below this section! ============================
Expand Down

0 comments on commit 4161199

Please sign in to comment.