Compare commits
2 Commits
9e68c529bf
...
a77da74da5
Author | SHA1 | Date | |
---|---|---|---|
a77da74da5 | |||
5c02a9f858 |
10
dump_tokens.py
Normal file
10
dump_tokens.py
Normal 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
5
examples/fib.ppp
Normal 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
1
examples/hello.ppp
Normal file
@ -0,0 +1 @@
|
||||
print("Hello, World!\n");
|
@ -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
|
||||
|
@ -106,3 +106,6 @@ class Token:
|
||||
loc: Location
|
||||
value: str
|
||||
contents: TokenContents
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.loc}: {self.contents}"
|
||||
|
Loading…
Reference in New Issue
Block a user