Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. expression ADDING expression
  2. {
  3. if ($1.type == Language::Type::INT && $3.type == Language::Type::INT)
  4. {
  5. $$.value.int_val = $1.value.int_val + $3.value.int_val;
  6. }
  7. else if ($1.type == Language::Type::STR && $3.type == Language::Type::STR)
  8. {
  9. //Unite both strings "hey" + "mate" = "heymate"
  10. $$.type == $1.type;
  11. $$.value.str_val = (char*)calloc(strlen($1.value.str_val) + strlen($3.value.str_val) + 1, sizeof(char));
  12. strncpy($$.value.str_val, $1.value.str_val, strlen($1.value.str_val));
  13. strncpy($$.value.str_val + strlen($1.value.str_val), $3.value.str_val, strlen($3.value.str_val));
  14. $$.value.str_val[strlen($1.value.str_val) + strlen($3.value.str_val)] = '\0';
  15. }
  16. else
  17. {
  18. yyfmterror("Can't add with this type");
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement