You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minor code changes: add comment to tiny_parser.py explaining function_call expression optimization, and reformat listed functions to easily read them in sorted name order; general rewrite/reword of sections of the TINY README.md
Copy file name to clipboardExpand all lines: examples/tiny/README.md
+46-12Lines changed: 46 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ illustrative scripts, using the TINY language.
11
11
12
12
## Running the REPL
13
13
14
-
The TINY project also includes an interactive Read–Eval–Print Loop (REPL) for quickly
14
+
The TINY project includes an interactive Read–Eval–Print Loop (REPL) for quickly
15
15
trying out statements and functions.
16
16
17
17
- Start the REPL:
@@ -26,7 +26,6 @@ trying out statements and functions.
26
26
- Useful keys/behavior:
27
27
- Press Ctrl-C while typing to cancel the current partial input and return to a fresh prompt.
28
28
- Press Ctrl-C during a long-running execution to interrupt it and return to the prompt.
29
-
- The REPL always prints a newline after executing a statement block.
30
29
31
30
- Built-in REPL commands (typed at an empty prompt):
32
31
-`quit` — exit the REPL
@@ -51,12 +50,36 @@ trying out statements and functions.
51
50
>>> int x := 5;
52
51
>>> write factorial(x);
53
52
120
53
+
>>> list
54
+
[variables]
55
+
x = 5 : int
56
+
[functions]
57
+
abs(float a) : float
58
+
cos(float rad_) : float
59
+
deg(float rad) : float
60
+
div(int a, int b) : int
61
+
exp(float x) : float
62
+
factorial(int n) : int
63
+
hypot(float x, float y) : float
64
+
mod(int a, int b) : int
65
+
pi() : float
66
+
pow(float x, int y) : float
67
+
rad(float deg) : float
68
+
round(float a, int n) : float
69
+
sgn(float x) : int
70
+
sin(float rad_) : float
71
+
sqrt(float a) : float
72
+
tan(float rad_) : float
73
+
>>> quit
54
74
```
55
75
56
76
- Errors and debugging:
57
-
- By default, non-runtime exceptions raised while executing TINY statements are shown concisely as `ExceptionType: message` without a traceback.
58
-
- The same concise behavior applies when importing files with `import`/`reimport` (I/O and other errors print `ExceptionType: message`).
59
-
- Turn on verbose debugging with `debug on` to display full Python tracebacks for exceptions during execution. Use `debug off` to return to concise error messages.
77
+
- By default, exceptions raised while executing TINY statements are shown concisely as
78
+
`ExceptionType: message` without a traceback.
79
+
- The same concise behavior applies when importing files with `import`/`reimport` (I/O and other errors
80
+
print `ExceptionType: message`).
81
+
- Turn on verbose debugging with `debug on` to display full Python tracebacks for exceptions during execution.
82
+
Use `debug off` to return to concise error messages.
60
83
- In debug mode, file import errors will also show full Python tracebacks.
61
84
62
85
For a fuller walkthrough of REPL features and development notes, see
@@ -65,23 +88,33 @@ For a fuller walkthrough of REPL features and development notes, see
65
88
## Project Structure
66
89
67
90
- tiny_parser.py
68
-
- Defines the TINY language grammar using pyparsing and exposes `parse_tiny(text)` to parse source into `ParseResults`.
91
+
- Defines the TINY language grammar using pyparsing and exposes `parse_tiny(text)` to parse source into internal
92
+
parser results.
93
+
- The parser tags each statement group with a `type` tag (for example: `main_decl`, `decl_stmt`, `assign_stmt`,
94
+
`if_stmt`, `repeat_stmt`, `read_stmt`, `write_stmt`, `return_stmt`, `call_stmt`), which is used in `tiny_ast.py`
95
+
to instantiate the appropriate executable AST node subclass.
69
96
- Independent of execution; focused purely on syntax and result structuring.
70
-
- Allows for testing the parser in isolation from any integration or implementation
71
-
components.
97
+
- Allows for testing the parser in isolation from any integration or implementation components.
72
98
73
99
- tiny_ast.py
74
-
- Declares the abstract base `TinyNode` and node subclasses for each TINY statement type (for example: `main_decl`, `decl_stmt`, `assign_stmt`, `if_stmt`, `repeat_stmt`, `read_stmt`, `write_stmt`, `return_stmt`, `call_stmt`).
100
+
- Declares the abstract base `TinyNode` and node subclasses for each TINY statement type.
75
101
- Nodes wrap parser results and implement `execute(engine)`; nodes that contain bodies pre-build their child nodes.
76
102
77
103
- tiny_engine.py
78
-
- Implements `TinyEngine`, the runtime responsible for variable scopes (stack frames plus globals), text I/O, expression evaluation, and function invocation.
104
+
- Implements `TinyEngine`, the runtime responsible for variable scopes (stack frames plus globals), text I/O,
105
+
expression evaluation, and function invocation.
79
106
- Provides APIs used by AST nodes: declare/assign variables, evaluate expressions, read/write output, call functions.
80
107
81
108
- tiny_run.py
82
109
- CLI entry point to parse and run a `.tiny` program.
83
110
- Registers top-level functions/globals, builds the `main` function node, and executes it using `TinyEngine`.
84
-
- Converts the parser's `ParseResults` into an executable hierarchy of `TinyNode` objects, using each statement group's `type` tag to instantiate the correct `TinyNode` subclass.
111
+
- Converts the parser's internal results into an executable hierarchy of `TinyNode` objects, using each statement
112
+
group's `type` tag to instantiate the correct `TinyNode` subclass.
113
+
114
+
- tiny_repl.py
115
+
- CLI entry point to start the interactive TINY REPL.
116
+
- Implements the REPL's command-line interface and REPL-specific logic.
117
+
- Uses `tiny_parser.py`, `tiny_ast.py`, and `tiny_engine.py` to parse and execute TINY statements.
@@ -102,7 +135,8 @@ For a fuller walkthrough of REPL features and development notes, see
102
135
103
136
Grammar outline: see `docs/grammar.md` and `docs/tiny_parser_diagram.html`
104
137
105
-
Pyparsing best practices were used to prompt the AI on preferred usages of pyparsing. Accessible using the command `python -m pyparsing.ai.show_best_practices`
138
+
Pyparsing best practices were used to prompt the AI on preferred usages of pyparsing. Accessible using the command
139
+
`python -m pyparsing.ai.show_best_practices`
106
140
107
141
## Reference
108
142
- TINY language definition: https://a7medayman6.github.io/Tiny-Compiler/Language-Description.html
0 commit comments