-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update(backend): made changes to accommodate paser and interpreter
- Loading branch information
1 parent
f36369a
commit d69ffd0
Showing
13 changed files
with
169 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Created by rohith on 26/03/2024 | ||
// | ||
|
||
#include "Token.h" | ||
#include "utls/Object.h" | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
class Environment { | ||
private: | ||
std::unordered_map<std::string, Object> values; | ||
|
||
public: | ||
void define(std::string name, Object value); | ||
void assign(Token *name, Object value); | ||
Object get(Token *name); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ set(Sources Error.cpp | |
AstPrinter.cpp | ||
Interpreter.cpp | ||
Statement.cpp | ||
env/env.cpp | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Created by rohith on 26/03/2024 | ||
// | ||
|
||
#include "env/Env.h" | ||
#include "utls/RuntimeError.h" | ||
|
||
void Environment::define(std::string name, Object value) { | ||
values.insert({name, value}); | ||
} | ||
|
||
void Environment::assign(Token *name, Object value) { | ||
if (values.find(name->lexeme) != values.end()) { | ||
values[name->lexeme] = value; | ||
return; | ||
} | ||
throw new RuntimeError(*name, "Undefined variable " + name->lexeme); | ||
} | ||
|
||
Object Environment::get(Token *name) { | ||
if (values.find(name->lexeme) != values.end()) | ||
return values[name->lexeme]; | ||
else { | ||
throw new RuntimeError(*name, "Unexpected variable " + name->lexeme); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule lib
updated
6 files