Skip to content

Commit 379ec42

Browse files
committed
update README: add detailed PHP Script language syntax reference and examples
1 parent dd665e9 commit 379ec42

1 file changed

Lines changed: 212 additions & 0 deletions

File tree

README.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,218 @@ Access granted!
136136
App Version: 1.2.3
137137
```
138138

139+
## PHP Script Language Reference
140+
141+
This section provides a comprehensive overview of the PHP Script language syntax, including all supported statements, expressions, and their variations.
142+
143+
### 1. Basic Statements and Expressions
144+
145+
#### Echo Statement
146+
147+
The `echo` statement is used to output values.
148+
149+
```javascript
150+
echo 'Hello World!';
151+
echo 123;
152+
echo true;
153+
echo LINEBREAK; // Outputs a new line
154+
```
155+
156+
#### Variable Assignment
157+
158+
Variables can be assigned values using the `=` operator. Variables are dynamically typed.
159+
160+
```javascript
161+
myVariable = 10;
162+
anotherVariable = 'some text';
163+
booleanVariable = true;
164+
```
165+
166+
#### Literals
167+
168+
PHP Script supports the following literal types:
169+
170+
- **Numbers:** Integers and floating-point numbers.
171+
```javascript
172+
number = 123;
173+
floatNumber = 3.14;
174+
```
175+
- **Strings:** Enclosed in single or double quotes.
176+
```javascript
177+
singleQuoteString = 'Hello';
178+
doubleQuoteString = "World";
179+
```
180+
- **Booleans:** `true` and `false`.
181+
```javascript
182+
isTrue = true;
183+
isFalse = false;
184+
```
185+
- **Null:** `null`.
186+
```javascript
187+
emptyValue = null;
188+
```
189+
- **LINEBREAK:** A special keyword representing a new line character.
190+
```javascript
191+
echo 'Line 1' ~ LINEBREAK ~ 'Line 2';
192+
```
193+
194+
### 2. Operators
195+
196+
#### Arithmetic Operators
197+
198+
Standard arithmetic operations are supported.
199+
200+
- **Addition:** `+`
201+
- **Subtraction:** `-`
202+
- **Multiplication:** `*`
203+
- **Division:** `/`
204+
205+
```javascript
206+
result = 10 + 5; // 15
207+
result = 20 - 7; // 13
208+
result = 4 * 6; // 24
209+
result = 100 / 10; // 10
210+
```
211+
212+
#### Concatenation Operator
213+
214+
The `~` operator is used for string concatenation.
215+
216+
```javascript
217+
greeting = 'Hello' ~ ' ' ~ 'World!'; // "Hello World!"
218+
```
219+
220+
#### Comparison Operators
221+
222+
Used for comparing values.
223+
224+
- **Equal to:** `==` (loose comparison)
225+
- **Strictly equal to:** `===` (strict comparison, checks value and type)
226+
- **Not equal to:** `!=` (loose comparison)
227+
- **Strictly not equal to:** `!==` (strict comparison)
228+
- **Greater than:** `>`
229+
- **Less than:** `<`
230+
231+
```javascript
232+
isEqual = (10 == '10'); // true
233+
isStrictlyEqual = (10 === '10'); // false
234+
isNotEqual = (10 != 5); // true
235+
isStrictlyNotEqual = (10 !== '10'); // true
236+
isGreater = (20 > 10); // true
237+
isLess = (5 < 10); // true
238+
```
239+
240+
#### Unary Operators
241+
242+
Operators that operate on a single operand.
243+
244+
- **Negation:** `-` (for numbers)
245+
- **Logical NOT:** `!` (for booleans)
246+
247+
```javascript
248+
negativeNumber = -10;
249+
isNotTrue = !true; // false
250+
```
251+
252+
#### Postfix Operators
253+
254+
Operators that appear after their operand.
255+
256+
- **Increment:** `++`
257+
- **Decrement:** `--`
258+
259+
```javascript
260+
count = 0;
261+
count++; // count is now 1
262+
count--; // count is now 0
263+
```
264+
265+
### 3. Control Flow
266+
267+
#### If-Else Statement
268+
269+
Executes a block of code if a condition is true. An optional `else` block can be provided for when the condition is false.
270+
271+
```javascript
272+
// Basic if statement
273+
if (user.hasPermission('admin')) {
274+
echo 'Access granted!';
275+
}
276+
277+
// If-else statement
278+
if (totalLogins > 100) {
279+
echo 'High activity!';
280+
} else {
281+
echo 'Normal activity.';
282+
}
283+
```
284+
285+
#### For Loop
286+
287+
Executes a block of code a specified number of times. It consists of an initializer, a condition, and an increment expression, all of which are optional.
288+
289+
```javascript
290+
// Standard for loop
291+
for (i = 0; i < 5; i++) {
292+
echo 'Iteration: ' ~ i ~ LINEBREAK;
293+
}
294+
295+
// For loop with optional parts
296+
for (; count < 10;) { // No initializer, no increment
297+
echo 'Count: ' ~ count ~ LINEBREAK;
298+
count++;
299+
}
300+
301+
for (;;) { // Infinite loop (use with caution, requires a break condition inside the body)
302+
// Note: Break statement is not yet supported.
303+
}
304+
```
305+
306+
#### Foreach Loop
307+
308+
Iterates over elements of an array or iterable object.
309+
310+
```javascript
311+
// Foreach loop over values
312+
foreach (users_list as u) {
313+
echo '- ' ~ u ~ LINEBREAK;
314+
}
315+
316+
// Foreach loop over key-value pairs (key is optional)
317+
foreach (users_map as key, value) {
318+
echo key ~ ': ' ~ value ~ LINEBREAK;
319+
}
320+
```
321+
322+
### 4. Object and Array Interaction
323+
324+
#### Member Access
325+
326+
Access properties or methods of an object using the `.` operator.
327+
328+
```javascript
329+
userName = user.name;
330+
loginCount = user.logins.count();
331+
```
332+
333+
#### Array Access
334+
335+
Access elements of an array using square brackets `[]`.
336+
337+
```javascript
338+
firstUser = users_list[0];
339+
secondUser = users_list[1];
340+
```
341+
342+
#### Function Calls
343+
344+
Call functions or methods with arguments.
345+
346+
```javascript
347+
echo 'Hello World!'; // Calling a global function (if exposed)
348+
user.hasPermission('admin'); // Calling a method on an object
349+
```
350+
139351
## Features
140352

141353
- Abstract Syntax Tree (AST) is in use

0 commit comments

Comments
 (0)