[Programmer Lip Lai] Anyone interested in building tokenizer?

nubitol

High Supremacy Member
Joined
Jun 28, 2015
Messages
27,488
Reaction score
632
or I think its called lexer?

the logic is for each character of the content of a file, determine the token, such as
1. matching ) of a ( while inside can contain another (
2. no count for ) that is inside of a string/comment, while comment can be // /* or --
3. when no 2 is inside a string, the string may contain string enclosure such as " or ' that is escaped, the lexer need to know whether it is an escaped enclosure instead of enclosure itself

this kind of programming sounds fun
 

The_Davis

Honorary Member
Deluxe Member
Joined
Mar 31, 2001
Messages
149,953
Reaction score
13,470
I return my tokenizer to school liao :(

Nowadays no chance to use
 

Perisher

Greater Supremacy Member
Deluxe Member
Joined
Jan 5, 2015
Messages
84,184
Reaction score
10,104
i = "siaolang"
HOUGANG_CHALET = ["IMH", "siaolang"]
while i in HOUGANG_CHALET:
print("I must take medicine")
else:
print("Missy will scold")
me no programmer but can understand sia...
 

Perisher

Greater Supremacy Member
Deluxe Member
Joined
Jan 5, 2015
Messages
84,184
Reaction score
10,104
i = "siaolang"
HOUGANG_CHALET = ["IMH", "siaolang"]
while i in HOUGANG_CHALET:
print("I must take medicine")
else:
print("Missy will scold")
Got this whole chunk of error when i try putting whole thing into a python compiler to run...
https://www.w3schools.com/python/trypython.asp?filename=demo_default
Traceback (most recent call last):
File "/usr/lib/python3.8/py_compile.py", line 144, in compile
code = loader.source_to_code(source_bytes, dfile or file,
File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./prog.py", line 5
print("I must take medicine")
^
IndentationError: expected an indented block

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/py_compile.py", line 150, in compile
raise py_exc
py_compile.PyCompileError: Sorry: IndentationError: expected an indented block (prog.py, line 5)
 

*Sisyphus*

Supremacy Member
Joined
Sep 27, 2021
Messages
6,459
Reaction score
3,460
Got these whole chunk of error when i try putting whole thing into a python compiler to run...
https://www.w3schools.com/python/trypython.asp?filename=demo_default
Traceback (most recent call last):
File "/usr/lib/python3.8/py_compile.py", line 144, in compile
code = loader.source_to_code(source_bytes, dfile or file,
File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./prog.py", line 5
print("I must take medicine")
^
IndentationError: expected an indented block

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/py_compile.py", line 150, in compile
raise py_exc
py_compile.PyCompileError: Sorry: IndentationError: expected an indented block (prog.py, line 5)
must indent the print statements...
Code:
i = "siaolang"
HOUGANG_CHALET = ["IMH", "siaolang"]
while i in HOUGANG_CHALET:
          print("I must take medicine")
else:
          print("Missy will scold")

nothing much lah..just loop endlessly like siaolang....
 
Last edited:

Phen8210

High Supremacy Member
Joined
Jul 29, 2011
Messages
28,822
Reaction score
8,196
Got this whole chunk of error when i try putting whole thing into a python compiler to run...
https://www.w3schools.com/python/trypython.asp?filename=demo_default
Traceback (most recent call last):
File "/usr/lib/python3.8/py_compile.py", line 144, in compile
code = loader.source_to_code(source_bytes, dfile or file,
File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./prog.py", line 5
print("I must take medicine")
^
IndentationError: expected an indented block

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/py_compile.py", line 150, in compile
raise py_exc
py_compile.PyCompileError: Sorry: IndentationError: expected an indented block (prog.py, line 5)

dont know u serious or trolling
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Community Guidelines and Standards, Terms of Service and Member T&Cs for more information.
Top