Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- expression ADDING expression
- {
- if ($1.type == Language::Type::INT && $3.type == Language::Type::INT)
- {
- $$.value.int_val = $1.value.int_val + $3.value.int_val;
- }
- else if ($1.type == Language::Type::STR && $3.type == Language::Type::STR)
- {
- //Unite both strings "hey" + "mate" = "heymate"
- $$.type == $1.type;
- $$.value.str_val = (char*)calloc(strlen($1.value.str_val) + strlen($3.value.str_val) + 1, sizeof(char));
- strncpy($$.value.str_val, $1.value.str_val, strlen($1.value.str_val));
- strncpy($$.value.str_val + strlen($1.value.str_val), $3.value.str_val, strlen($3.value.str_val));
- $$.value.str_val[strlen($1.value.str_val) + strlen($3.value.str_val)] = '\0';
- }
- else
- {
- yyfmterror("Can't add with this type");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement