Compare commits

..

2 Commits

Author SHA1 Message Date
a77da74da5
Add examples/ 2024-10-01 19:06:03 +10:00
5c02a9f858
Add dump_tokens.py 2024-10-01 19:02:20 +10:00
5 changed files with 20 additions and 1 deletions

10
dump_tokens.py Normal file
View File

@ -0,0 +1,10 @@
import sys
from ppp_lexer import Lexer
from ppp_tokens import EofToken
_program, file_path = sys.argv
lexer = Lexer.from_file(file_path)
while not lexer.check_token(EofToken()): print(lexer.next_token())

5
examples/fib.ppp Normal file
View File

@ -0,0 +1,5 @@
a: (int, int) = (0, 1);
for i in range(0, 100) {
a = (a[1], a[0] + a[1]);
print(int_to_str(a[0])+"\n");
}

1
examples/hello.ppp Normal file
View File

@ -0,0 +1 @@
print("Hello, World!\n");

View File

@ -60,9 +60,9 @@ class Lexer:
return self._token(loc, word, IdentifierToken(word))
case '"':
# TODO: Proper escaping
loc = self._loc()
self._advance()
start_location = self._location
loc = self._loc()
escaping = False
while self._location < len(self._source) and (self._source[self._location] != '"' or escaping):
escaping = self._source[self._location] == '\\' if not escaping else False

View File

@ -106,3 +106,6 @@ class Token:
loc: Location
value: str
contents: TokenContents
def __repr__(self) -> str:
return f"{self.loc}: {self.contents}"