Просмотр исходного кода

handle assignment to variables

master
Ian Piumarta 3 месяцев назад
Родитель
Сommit
560fe0d6b8
2 измененных файлов: 8 добавлений и 1 удалений
  1. +6
    -1
      main.leg
  2. +2
    -0
      test.txt

+ 6
- 1
main.leg Просмотреть файл

@ -1,6 +1,6 @@
# main.leg -- C parser + interpreter
#
# Last edited: 2025-01-22 21:08:24 by piumarta on zora
# Last edited: 2025-01-22 23:32:08 by piumarta on zora
%{
;
@ -1922,6 +1922,11 @@ oop eval(oop exp, oop env)
oop lhs = get(exp, Assign,lhs);
oop rhs = eval(get(exp, Assign,rhs), nil);
switch (getType(lhs)) {
case Symbol: {
lhs = Scope_lookup(lhs);
if (Variable != getType(lhs)) break;
return set(lhs, Variable,value, rhs);
}
case Dereference: {
lhs = eval(get(lhs, Dereference,rhs), nil);
switch (getType(lhs)) {

+ 2
- 0
test.txt Просмотреть файл

@ -15,6 +15,8 @@ int main(int argc, char **argv)
printf("x is %d p is %p\n", *p, p);
*p = 666;
printf("x is %d %d\n", x, *p);
x = 123;
printf("x is %d %d\n", x, *p);
return 0;
}

Загрузка…
Отмена
Сохранить