Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit 579dcfe

Browse files
Update README.md
1 parent 78645b8 commit 579dcfe

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

‎README.md‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
# Python Regex Based Scanner
22
an implemention of a lexical analyzer that tokenize a program using some regex rules
33

4-
# requirements
4+
# Requirements
55
Python 3.8
66

7-
# how to use
7+
# How to use
88
you can just put your rules in to the compiler_cli.py file and use it for yourself.
99

1010
this is how you can compile your code using compiler_cli.py
1111
```sh
1212
python compiler_cli.py path/to/file
1313
```
14+
15+
# Example rules
16+
```py
17+
rules = [
18+
('IF_KW', r'if'),
19+
('ELSE_KW', r'else'),
20+
('FOR_KW', r'for'),
21+
('CONST_STR', r'".*?"|\'.*?\''),
22+
('CONST_NUMBER', r'\d+'),
23+
24+
('PLUS_OP', r'\+'),
25+
('MINUS_OP', r'\-'),
26+
('MULTIPLY_OP', r'\*'),
27+
('DIVIDE_OP', r'\/'),
28+
('LP', r'\('),
29+
('LCB', r'\{'),
30+
('RP', r'\)'),
31+
('RCB', r'\}'),
32+
33+
('EQUAL_OP', r'=='),
34+
('ASSIGNMENT_OP', r'='),
35+
('SEMICOLON', r';'),
36+
('IDENTIFIER', r'[a-zA-Z_]\w+'),
37+
]
38+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /