Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLOBAL #4

Open
6 tasks
JosefKuchar opened this issue Oct 20, 2022 · 0 comments
Open
6 tasks

GLOBAL #4

JosefKuchar opened this issue Oct 20, 2022 · 0 comments
Assignees

Comments

@JosefKuchar
Copy link
Owner

JosefKuchar commented Oct 20, 2022

Podporujte globální proměnné s využitím klíčového slova global. Kolize jmen proměnných řešte analogicky jako PHP (+0,5 bodu).

Je potřeba

  • Přidat global token (TOK_GLOBAL)
  • Přidat detekci global tokenu do scanneru (keywords)
  • Upravit LL gramatiku pro podporu global
  • Implementovat global v parseru
  • Implementovat generování kódu pro global
  • Přidat alespoň základní testy

Zkoušky

<?php
$x = 0;
function foo() {
	print_r($x);
}
foo();

Warning: Undefined variable $x in /home/user/scripts/code.php on line 4

<?php
$x = 0;
function foo() {
	global $x;
	print_r($x);
}
foo();

0

<?php
$x = 0;
function foo() {
	global $x;
        global $x;
	print_r($x);
}
foo();

0

<?php
$x = 0;
function foo($x) {
	global $x;
	print_r($x);
}
foo(1);

0

<?php
$x = 0;
function foo() {
	$x = 1;
	global $x;
	print_r($x);
}
foo();
print_r($x);

00

<?php
$x = 0;
function foo() {
	global $x;
	$x = 1;
	print_r($x);
}
foo();
print_r($x);

11

<?php
function foo() {
	global $x;
	print_r($x);
}
$x = 1;
foo();

1

<?php
function foo() {
	global $x;
	print_r($x);
}
foo();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants