Skip to content

Commit

Permalink
Merge pull request #349 from andrey-terekhov/feature
Browse files Browse the repository at this point in the history
Feature
  • Loading branch information
bugdea1er authored Feb 6, 2023
2 parents 706840b + 235d26b commit 3c7d91f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
cmake-build-default*/

# VSCode
.vscode/*
Expand All @@ -93,6 +94,9 @@ Release/
*.perspectivev3
*.xcodeproj

# CLion
*.idea

# Windows
desktop.ini

Expand Down
6 changes: 4 additions & 2 deletions libs/compiler/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static void ident_init(syntax *const sx)
builtin_add(sx, U"fputc", U"фписать_символ", type_function(sx, TYPE_INTEGER, "iP"));
builtin_add(sx, U"fclose", U"фзакрыть", type_function(sx, TYPE_INTEGER, "P"));
builtin_add(sx, U"exit", U"выход", type_function(sx, TYPE_VOID, "i"));

builtin_add(sx, U"printf", U"печатьф", type_function(sx, TYPE_INTEGER, "s."));
builtin_add(sx, U"print", U"печать", type_function(sx, TYPE_VOID, "."));
builtin_add(sx, U"printid", U"печатьид", type_function(sx, TYPE_VOID, "."));
Expand Down Expand Up @@ -858,8 +858,9 @@ scope scope_block_enter(syntax *const sx)
return (scope){ ITEM_MAX, ITEM_MAX };
}

size_t prev_cur_id = sx->cur_id;
sx->cur_id = vector_size(&sx->identifiers);
return (scope){ sx->displ, sx->lg };
return (scope){ sx->displ, sx->lg, prev_cur_id };
}

int scope_block_exit(syntax *const sx, const scope scp)
Expand All @@ -877,6 +878,7 @@ int scope_block_exit(syntax *const sx, const scope scp)

sx->displ = scp.displ;
sx->lg = scp.lg;
sx->cur_id = scp.cur_id;
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions libs/compiler/syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef struct scope
{
item_t displ;
item_t lg;
size_t cur_id;
} scope;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ void main()

getid(N);
printid(N);
float A[N][N], B[N], X[N];
{
float A[N][N], B[N], X[N];

getid(A);
printid(A);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Use of undeclared identifier.
// More scopes.

void main()
{
int N = 10, i, j, k;
{
float A[N][N], B[N], X[N];
{
float t, S;
}
}

print (X);
}

0 comments on commit 3c7d91f

Please sign in to comment.