Skip to content

Commit

Permalink
feat: Add documentation for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
FallenDeity committed Apr 29, 2023
1 parent c454871 commit e736909
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion __main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import PyLox

if __name__ == "__main__":
PyLox().run_prompt()
PyLox("test.lox").run()
6 changes: 1 addition & 5 deletions docs/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,7 @@ For now standard libraries in `Lox` will be limited to the default `clock()` met

### TODO

- [ ] Add `IO` methods
- [ ] Add `Math` methods
- [ ] Add `String` methods
- [ ] Add `Network` methods
- [ ] Add `File` methods
Look for the complete list of methods [here](tasks.html)

## `PyLox` our Interpreter

Expand Down
3 changes: 0 additions & 3 deletions docs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,6 @@ For example `1` is a primary expression. It cannot be broken down further. It is

Now that we have completed our parser we can test it out.

```python
```

```
>>> var x = 7;
[2023-04-30 00:18:48,991] | ~\src\interpreter\lox.py:39 | INFO | Running PyLox...
Expand Down
1 change: 0 additions & 1 deletion src/interpreter/lox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def run_prompt(self) -> None:
tokens = self.lexer.scan_tokens()
parser = Parser(self, tokens, self.logger, self._source)
statements = parser.parse()
print(statements)
if parser._has_error:
continue
resolver = Resolver(self.interpreter)
Expand Down
19 changes: 19 additions & 0 deletions src/interpreter/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ class LoopyType(enum.Enum):


class Resolver(StmtProtocol, VisitorProtocol):
"""Resolve names in the AST.
For example, the following code is valid:
```
var a = "global";
{
fun showA() {
print a;
}
showA(); // prints "global"
var a = "block";
showA(); // prints "block"
}
print a; // prints "global"
```
Hence, resolver creates a new scope for each block, function, and class.
"""
def __init__(self, interpreter: "Interpreter") -> None:
self._interpreter = interpreter
self.scopes: list[dict[str, bool]] = []
Expand Down
6 changes: 1 addition & 5 deletions test.lox
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
class Foo {
}

class Bar < Foo {
}
return 1;

0 comments on commit e736909

Please sign in to comment.