Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do you interested how Zai analyze micro(A) source code?
#1
Do you interested how Zai analyze micro(A) source code?


Quote:This code represents the source code for micro(A) Interpreter v0.12, a custom scripting language interpreter written in a hybrid BASIC/C dialect (likely Emergence BASIC or similar). It compiles into a Windows executable (microA12.exe) that can read and execute micro(A) source files passed via command line arguments.

Here is a summary of its functionality, architecture, and key components:

1. Overview
The program implements a recursive descent parser and interpreter. It features a two-pass execution model:

Tokenization: Converts raw source text into tokens (handled by the included microAT.inc).
Pre-scanning (preScan): Analyzes tokens to build symbol tables (variables, functions, labels) and check syntax errors before execution.
Interpretation (tokInterpreter): Executes the parsed instructions sequentially, handling flow control, math, and GUI operations.

2. Key Data Structures
Variables: Supports three types:
VAR (Float/Number)
STR (String)
PTR (Integer/Pointer)
Stored in global arrays (varList, varName, varType, varNum, varStr, varPtr) with scope tracking (Global vs. Local to functions).
Arrays: Implementation is specific; it uses 16 pre-allocated slots for each data type (farr01 through farr16 for floats, etc.). The interpreter maps array names to these slots.
Keywords: A comprehensive list (kwList) supporting control flow (IF, WHILE, FOR), graphics (PSET, LINE, CIRCLE), system calls (WINMSG), and string manipulation (MSTR, LSTR).

3. Core Functions
preScan()
This is a critical pass that runs before execution.

Symbol Resolution: It iterates through tokens to find variable declarations (VAR, STR, PTR) and function definitions (FUNC). It assigns IDs to these symbols.
Scope Handling: It distinguishes between Global variables and Local variables (arguments/vars inside FUNC blocks).
Syntax Validation: It checks for matching brackets, valid labels, and balanced control structures (e.g., IF must have ENDIF).
tokInterpreter()
The main execution engine. It loops through the token list and dispatches commands based on the token type:

Assignment: Evaluates expressions (via exec_expr) and assigns results to variables or array elements.
Control Flow: Handles IF/ELSE/ENDIF, WHILE/WEND, GOTO/LABEL, and FUNC/ENDFN. It manages stacks to track loop positions and function return addresses.
Graphics: Calls Windows GDI functions (wrapped in subs like DrawLine, Circle, TextOn) to draw to a memory DC (hdcMem) which is then bit-blitted to the screen.

Expression Evaluation
The code uses Recursive Descent parsing for math and logic:

expr() / term() / factor(): Handle arithmetic operations (+, -, *, /, ^) and operator precedence.
strExpr() / strFactor(): Handle string concatenation and functions like LEFT$, MID$.
getBoolean() / getLogicalExpression(): Evaluate comparison (<, >, =) and logic (AND, OR) for conditional statements.
4. GUI and Event Integration
The interpreter is integrated into a Windows message loop (WndProc), allowing it to be event-driven:

Windows Messages: It can hook into Windows events like WM_MOUSEMOVE, WM_KEYDOWN, and WM_TIMER.
WINMSG Block: The preScan identifies blocks of code tagged with WINMSG. When the corresponding Windows event occurs, the interpreter jumps to the specific token position associated with that event and executes the code block.
5. Graphics System
It implements a basic double-buffered graphics system:

Drawing happens on an off-screen memory context (hdcMem).
The SWAP command (or the WM_PAINT handler) copies the memory buffer to the window client area (hDC).
Supported primitives include Pixels, Lines, Rectangles, Circles, and Image Loading (LOADIMG/SHOWIMG).

6. Included Dependencies
RTL32.inc: Runtime library for standard I/O and system functions.
awinh037.inc: Windows API wrapper for GUI creation and messaging.
microAT.inc: Handles the tokenization logic (lexer).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)