L Scripting language Grammar Handbook
Version 0.02
Zhao
Introduction
The scripting language is a lightweight programming language designed to approach natural languages and currently supports programming on a Chinese and English basis. And can be extended to any language. The syntax structure of scripting language is simple, the program structure is relatively loose, easy to learn and use.
At present, L scripting language is still in the early development, the function is not perfect. The source code Editor is currently not available, and it is recommended to use notepad++ or UltraEdit for source code editing.
Interpreter engine CSDN Resourceshttp://download.csdn.net/detail/itmes/8656133
Directory
First, note: 2
Second, object definition and reference: 2
Three, integers, and floating-point numbers: 3
Four, numerical calculation, logical operation, bit operation. 3
V. Branches and loops: 5
Six, string and regular expression: 6
Seven, Function: 8
Viii. Files and directories: 9
Ix. Registration Form: 9
Ten, time and date. 10
Xi. table: 11
12. Network. 12
13. Random Number: 12
14. Library. 13
XV, interaction with C + +: 13
16. Interface of user interaction. 14
17. Class: 14
18. Process: 14
19. Threads: 15
20, the debugger uses: 15
21. Other: 15
First, comments
L script language comments are lines preceded by #, comments and empty rows are interpreted by the engine to automatically ignore
When the interpretation engine finds that a line of code contains an error, it provides as much error information as possible and simply ignores the line of code
Ii. object Definitions and references
Any object must be defined before it can be referenced, and the format of the object definition is
Definition: Object type, object name, initial value
For example
Definitions: integers, number1,0
Definitions: integers, number2,1
Definition: floating point, double,1.0
Definition: string, string1, "HelloWorld"
If you want to show the contents of an object, you can
Display: Number1
Display: String1
: is a delimiter used to separate actions and objects
, which is the delimiter used to separate the argument list
In this case, the name of the object can be any string except:, Chinese, English, and Korean are all possible.
Three, integers and floating-point numbers
The scripting language has built-in support for integers and floating-point numbers, allowing for arithmetic, logical operations, and remainder
The integer definition is in the format
Definitions: integers, names of integers, initial values of integers
Floating-point numbers are defined in the format
Definition: Floating-point number, floating-point name, initial value of floating-point numbers
integers and floating point numbers must be initialized when they are defined
Four, numerical calculation, logical operation, bit operation
Numeric calculations and logical operations must conform to a fixed format
Calculation: The contents of an expression
Such as
Calculation: Number1+number2
Calculation: Number1*number2
Calculation: Number1>number2
The result of each line of code is saved to a "result" object, which is a global
So if we want to show the results of numerical calculations, we can write this.
Calculation: number1+number2*100
Display: Results
Subtraction arithmetic
Addition
Calculation: Number+number2
Display: Results
Subtraction
Calculation: Number1-number2
Display: Results
Multiplication
Calculation: Number1*number2
Display: Results
Division
Calculation: Number1/number2
Display: Results
Take the remainder
Calculation: Number1%number2
Display: Results
Assign value
Calculation: number1=number2+1
Display: Results
Calculation: Number1+=number2
Calculation: Number1-=number2
Calculation: Number1*=number2
Calculation: Number1/=number2
Calculation: Number1%=number2
Use of parentheses
Multiplication division takes the remainder operation with precedence over addition and subtraction peers to maintain left-associative, so if you want to change the order of operations, you need to use parentheses, such as
Calculation: (number1+number2) *100
Logical operations
The logical value "true" in the scripting language is equivalent to the value 1, and the logical value "false" is equivalent to the value 0
So the value of the logical operation is only 1 and 2 states
Compare size
Calculation: Number1>number2
Display: Results
Calculation: Number1>=number2
Calculation: Number1<number2
Calculation: Number1<=number2
Calculation: Number1==number2
Logical AND logical OR logical XOR, logical, non-
Bit arithmetic
Includes bitwise inversion, bitwise LEFT SHIFT, bitwise right SHIFT, bitwise AND, bitwise OR, Bitwise XOR
V. Branching and looping
L Support conditional branching in scripting languages, called "if" statements, in the form of
If: conditional expression or logical operation expression, the statement executed when the condition is true
Otherwise: The statement executed when the condition is false
For example
If: Number1>number2, show: "Greater than"
Otherwise: Display: "Less than"
In the L scripting language, loop statements are called "when" statements in the form
When: A conditional expression or a logical operation expression, a statement that is executed repeatedly when the condition is true
For example
When: 1, call: function, function1
Six, string and regular expressions
The string definition can be initialized, if there is no initialization parameter, the default is an empty string
The format of the string definition is
Definition: String, string name, initial value of string
For example
Definition: string, string1, "Hello"
Definition: String, string2, "World"
Connection operations that support strings
Format is
Connection: String, first string, second string
Connection: String, string1,string2
Display: String1
Operations that support string fetching substrings
Format is
Take substring: substring name, original string name, location of substring, length of substring
Such as
Definition: String, string3
Fetch SUBSTRING: string3,string1,1,3
Allows the contents of a string to be emptied
Format is
Empty: String, Name of string
Operations that support string lookup substrings
Format is
Find: String, original string, substring
If a substring is found, the result object is set to a status object whose content is "found" or its contents are "not found"
Such as
Find: Strings, string1,string2
Operations that support string substitution substrings
Format is
Replace: String, original string, substring in string, substituted substring
As with lookups, if a substring is found, the result object is set to a status object whose content is "found" or its contents are "not found"
Such as
Replace: String, String1,string2, "XYZ"
The regular expression itself is a specially formatted string that defines the format as
Definition: Regular expression, the name of the regular expression, the contents of the regular expression
Such as
Definition: Regular expression, REGEXP1, "\d\d\d"
If you want to use a regular expression to match a string, the format is as follows
Definition: String, STR2, "ABC"
Definition: String, str1,123
Matching: Regular expressions, REGEXP1,STR1
Matching: Regular expressions, REGEXP1,STR2
Seven, function
Like other programming languages, a function must be defined before it can be called
The format of the function definition is
Definition: function, name of function, form parameter list
Start: function, name of function
#函数体
End: function, name of function
The parameters of a function can be 0 or more, and the arguments to the function must be objects or static values
The function body can be any valid line of code, but the nested definition of the function is not allowed
The body of the function must be wrapped up by a symmetric "start", "End"
Inside the function body allows the definition of a local object whose lifetime is generated as the function is called and destroyed at the end of the function call
The format of the function call is
Call: function, name of function, actual argument list
The function of the scripting language has no return value, so if we need to save the result of the function running, we can pass the desired result object as a parameter to the function
Viii. Files and directories
L script language, files and directories are built-in objects
A statement that opens a file or directory returns a file object and does not need to be defined
Format is
Open: File, file object name, full path name of file
Open: Directory, directory object name, full path to directory
Such as:
Open: File, File1,c:\1.txt
Open: Directory, dir1,c:\
Operations supported on file objects are copy, move, delete, size, read, write
Operations supported on directory objects have files in the enumeration directory, subdirectories in the enumeration directory, copy, move, delete
Ix. Registration Form
The scripting language has built-in support for accessing the Windows registry
Opening a registry key returns a Registry object that supports read, write, delete operations on this object
The syntax format is
Open: Registry, registry object name, registry path, name of the value
Read: Registry, registry object name, string object name
Write: Registry, registry object name, string object name
Delete: Registry, Registry Object name
Such as
Open: Registry, Reg1,hkey_local_machine\software\microsoft\windows\currentversion\run,httpserver
Read: Registry, reg1,string1
Write: Registry, reg1,string1
Delete: Registry, REG1
Ten, time and date
In the scripting language, the time object is defined in the form
Definition: Name of time, time object
The current time can be read into the time object
READ: The current time, the name of the time object
Time objects can be compared by comparison operators
If you want the script to wait for a while while it is running, you can call the sleep statement
Sleep: The number of milliseconds to sleep
For example:
Definition: Time, time1
READ: Current time, time1
Display: time1
Sleeps: 1000
Definition: Time, time2
READ: Current time, time2
Display: time2
if: ((time1<time2) | | | (time1==time2)), showing: "Time1 is earlier than or equal to Time2"
Xi. table
The concept of a table in the scripting language is similar to the concept of a table in the Lua language, which is actually a mapping between names and objects
The elements in the table can be any legal L script object, the size of the table is dynamic, allowing the deletion of elements to be added dynamically
The syntax format for a table definition is
Definition: Table, name of table
Insert: Table, name of table, object name
Take size, table, Integer variable name
Take elements: Table, alias of element, index of element in table
For example
Definition: String, str1, "Hello"
Definition: String, str2, "World"
Definitions: integers, number1,123456
Definition: floating point, number2,1.75
Definition: Table, table1
Insert: Table, TABLE1,STR1
Insert: Table, TABLE1,STR2
Insert: Table, Table1,number1
Insert: Table, Table1,number2
Definition: function, function1, parameter 1, parameter 2
Start: function, function1
Display: Parameter 1
Display: Parameter 2
End: function, function1
Insert: Table, Table1,function1
Display: table1
12. Network
Currently L scripts support network access for TCP and UDP protocols, using blocking socket implementations in the background
Access to the network is done through network connection objects and address objects
Defines the format of the Address object as
Definition: Address, Name of address object, IP (e.g. 127.0.0.1), port number (e.g. 27015)
Defines the format of the network connection object as
Definition: Network connection, name of the network connection, TCP or UDP
Actions for network connection objects are monitored, connected, sent, and received in the format
Connection: The name of the network connection, the name of the Address object
Send: Name of the network connection, string object name
Receive: Name of the network connection, string object name
For details, please refer to the example code
13. Random Number
We often use random information in our programs.
In the L scripting language, a random number is a class of objects that are actually special integer types
Use the method as
Generate: Random number, the name of the random number object
Refresh: Random number, the name of the random number object
For example
Generate: Random number, random1
Display: Random1
Definitions: integers, count,1000
Definition: function, Genrandom
Start: function, Genrandom
Refresh: Random number, random1
Display: Random1
Calculation: count=count-1
End: function, Genrandom
When: count>0, call: function, Genrandom
14. Library
The scripting language supports the import mechanism of custom libraries and libraries to provide maximum flexibility and allows custom functions to be registered as global actions
A library file is a script file that contains only object definitions and function definitions
The library file must have #scplib as the starting line
objects defined in the library are global user objects and functions as global user functions
The library needs to be imported first, with the syntax formatted as
Import: library, full path name of library file
The normal user function is called when the format is
Call: function, name of function, parameter list of function
Functions registered as global actions can be called directly from the function name, and the syntax format is
Register: function, name of function
Functions: Parameter list of functions
Please refer to the example code
XV, interaction with C + +
Since the API provided by the operating system is a C-language interface, the L scripting language allows direct invocation of the operating system's C-language API functions for extended functionality
Currently, only C-language functions with function calling conventions of __stdcall are supported
16. User interface
17. Class
l scripting language supports user-defined classes to support object-oriented type encapsulation
The syntax format is
Definition: class, Name of Class
Start: Class, Name of the class
Definitions: integers, member variables, initial values
Definition: String, member variable string, initial value
Definitions: Functions, member functions, member function parameters
Start: function, member function
End: function, member function
End: Class, name of the class
Allows the invocation of a member function of a class with a syntax format of
Invocation: Class Name: member function, member function parameter
18. Process
If we want to start an external program in the program, you can
Run: Program, process name, path name of the process executable, startup parameters
If you want to close an external program that you have started, you can
Closed: program, name of process
For example:
Run: Program, Proc1,notepad.exe,c:\hello.txt
Close: Program, Proc1
The script has built-in support for process communication and currently supports two-way communication with Named pipes
The syntax format is
Open: Pipe, Pipe object name, Windows pipeline name
Write: Pipe, Pipe object name, string name
READ: pipe, Pipe object name, string name
Close: Pipe, Pipe object name
For example
Open: Pipe, Pipe1, "\\.\pipe\mypipe1"
Write: Pipe, pipe1,string1
READ: Pipe, pipe1,string2
Display: string2
Close: Pipe, Pipe1
19. Threads
L Scripts support multi-threading, allowing new threads to be derived from scripts to support concurrent operations
The syntax format is
Definition: Thread, thread's name, thread function
Run: The thread, the name of the thread, the parameters of the thread function
Here, the thread function is the action performed by the thread execution body, which is similar to the calling function, but this function is executed in another thread.
The detailed use method can refer to the example code
20. Debugger Use
The scripting language provides a simple debugger for scripting source code debugging, after opening the file in the debugger, select row Right-click to set a breakpoint on the line of code, click the Debug button to start the debugging process, when the script executes to set a breakpoint line will be interrupted, and in the Message Output window display the prompt information. Right-click the line that has the breakpoint set again to clear the breakpoint.
The debugger also supports simple debug commands
BP line number, used to set breakpoints
BC line number, used to clear breakpoints
G, Debug Run script
SD, single-Step debug script
s, continue running the script
21. Cryptography Related
L scripting language built-in cryptography algorithm operation
String hash value (MD5), such as String encryption Decryption (RC4)
The syntax format is
Encryption: String name, key string name
Decryption: String name, key string name
Hash: string name, string that holds the hash value, hash algorithm name
For example
Encryption: STR1,STR2
Display: str1
Decryption: STR1,STR2
Display: str1
Seek hash: STR1,STR3,MD5
22. Other
L Scripting language Grammar Handbook