SlideShare a Scribd company logo
Ring Documentation, Release 1.5.3
97.6 Language Grammar
Program —> {statement}
Statement —> ‘package’ <Identifier> { ‘.’ <Identifier> } [’{‘ {statement} ‘}’] [’end’|’endpackage’]
Statement —> ‘class’ <Identifier> [ ‘from’|’:’|’<’ <Identifier> ] [’{‘ {statement} ‘}’][’end’|’endclass’]
Statement —> ‘func’|’def’ <Identifier> [ParaList] [’{‘ {statement} ‘}’][’end’|’endfunc’]
Statement —> ‘import’ <Identifier> { ‘.’ <Identifier> }
Statement —> ‘private’
Statement —> ‘load’ <Literal>
Statement —> ‘loadsyntax’ <Literal>
Statement —> ‘changeringkeyword’ <OldKeyword> <NewKeyword>
Statement —> ‘changeringoperator’ <OldOperator> <NewOperator>
Statement —> ‘see’|’put’ <Expr>
Statement —> ‘give’|’get’ <Identifier>
Statement —> ‘if’ <Expr> [’{‘] {statement} [ {‘but’|’elseif’ <Expr> {Statement} } ] [’else’ {Statement} ]
‘ok’|’end’|’}’
Statement —> ‘Switch’ <Expr> [’{‘] { ‘on’|’case’ <Expr> {statement} } [’other’ {Statement} ] ‘off’|’end’|’}’
Statement —> ‘for’ <Identifier> ‘=’ <Expr> ‘to’ <Expr> [ ‘step’ <Expr> ] [’{‘] {Statement} ‘next’|’end’|’}’
Statement —> ‘for’ <Identifier> ‘in’ <Expr> [ ‘step’ <Expr> ] [’{‘] {statement} ‘next’|’end’|’}’
Statement —> ‘while’ <Expr> [’{‘] {statement} ‘end’|’}’
Statement —> ‘do’ {statement} ‘again’ <Expr>
Statement —> ‘try’ {statement} [’{‘] ‘catch’ {statement} ‘done’|’end’|’}’
Statement —> ‘return’ <Expr>
Statement —> ‘bye’
Statement —> ‘exit’
Statement —> ‘loop’
Statement —> <Expr>
Statement —> epslion
ParaList —> epslion
ParaList —> [’(‘] <Identifier> [{ ‘,’ <Identifier> }] [’)’]
Expr —> <LogicNot> [{ ‘and’|’or’ <LogicNot> }]
LogicNot –> [’not’] <EqualOrNot>
EqualOrNot –> [ ‘=’|’!=’ ] <Compare>
Compare —> <BitOrXor> [ { ‘<’ | ‘>’ | ‘<=’ | ‘>=’ <BitOrXor> } ]
BitOrXor —> <BitAnd> [ { ‘|’ | ‘^’ <BitAnd> } ]
BitAnd —> <BitShift> [ { ‘&’ <BitShift> } ]
BitShift —> <Arithmetic> [ { ‘<<’ | ‘>>’ <Arithmetic> } ]
97.6. Language Grammar 1765
Ring Documentation, Release 1.5.3
Arithmetic —> <Term> [ { ‘+’ | ‘-‘ <Term> } ]
Term —> <Range> [ { ‘*’ | ‘/’ | ‘%’ <Range> } ]
Range —> <Factor> [ ‘:’ <Factor> ]
Factor —> <Identifier> [ {Mixer} ] [ ‘=’ <Expr> ]
Factor —> <Number>
Factor —> <Literal>
Factor —> ‘:’ <Identifier>
Factor —> ‘-‘ <Expr>
Factor —> ‘(‘ <Expr> ‘)’
Factor —> <List>
Factor —> ‘new’ <Identifier>
Factor —> <AnonymousFunction>
Factor —> ‘call’ <identifier> { ‘.’ <Identifier> } ‘(‘ <Parameters> ‘)’
List —> ‘[’ [ <Expr> { ‘,’ <Expr> } ] ‘]’
Mixer —> { ‘.’ <Identifier> }
Mixer —> ‘[’ <Expr> ‘]’
Mixer —> ‘(‘ [ <Expr> [ { ‘,’ <Expr> }] ] ‘)’
Mixer —> ‘{‘ {Statement} ‘}’
AnonymousFunction —> ‘func’|’def’| [<ParaList>] ‘{‘ {Statement} ‘}’
97.7 Virtual Machine (VM) Instructions
Definitions :-
• VM : Virtual Machine
• Stack : VM Stack
• IR : Instruction Register
• PC : Program Counter
• VP : Variable Pointer
• Stack[nSize] : Last Item in the Stack (Last In - First Out)
• VV : Variable Value (We have a Pointer to a variable, And we access this variable value)
(Stack and Variables)
97.7. Virtual Machine (VM) Instructions 1766
Ring Documentation, Release 1.5.3
Operation Description
• ICO_PUSHC
Add string from the IR to the stack
• ICO_PUSHN
Add number from the IR to the stack
• ICO_PUSHV
Replace VP in the stack[nSize] with the variable value
• ICO_LOADADDRESS
Read variable name from the IR, push VP to the stack
• ICO_ASSIGNMENT
Stack[nSize-1] VV = Stack[nSize] VV , POP
Stack[nSize]
• ICO_INC
Increment Number in Stack[nSize] by 1
• ICO_LOADAPUSHV
The same as ICO_LOADADDRESS then ICO_PUSHV
• ICO_NEWLINE
Store new line number (debug info)
• ICO_FREESTACK
Remove all items from the stack , nSize = 0
• ICO_FILENAME
Store the source code file name (debug info)
• ICO_FREELOADASCOPE
Free the Scope List of the current Expression
(Jump)
Operation Description
• ICO_JUMP
Set PC to new value from the IR
• ICO_JUMPZERO
If Stack[nSize] is a number = 0 then Set PC to new value
from the IR
• ICO_JUMPFOR
End of for loop
• ICO_JUMPONE
If Stack[nSize] is a number = 1 then Set PC to new value
from the IR
• ICO_JUMPZERO2
As ICO_JUMPZERO but add 1 to the stack (required
for many ‘AND’ conditions)
• ICO_JUMPONE2
As ICO_JUMPONE but add 1 to the stack (required for
many ‘OR’ conditions)
(Compare)
97.7. Virtual Machine (VM) Instructions 1767
Ring Documentation, Release 1.5.3
Operation Description
• ICO_LESSEQUAL
If stack[nSize-1] <= stack[nSize] , POP stack[nSize], set
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
• ICO_EQUAL
If stack[nSize-1] = stack[nSize] , POP stack[nSize], set
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
• ICO_LESS
If stack[nSize-1] < stack[nSize] , POP stack[nSize], set
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
• ICO_GREATER
If stack[nSize-1] > stack[nSize] , POP stack[nSize], set
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
• ICO_GREATEREQUAL
If stack[nSize-1] >= stack[nSize] , POP stack[nSize], set
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
• ICO_NOTEQUAL
If stack[nSize-1] != stack[nSize] , POP stack[nSize], set
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
(Math)
Operation Description
• ICO_SUM
Stack[nSize-1] = Stack[nSize-1] + Stack[nSize] , POP
stack[nSize]
• ICO_SUB
Stack[nSize-1] = Stack[nSize-1] - Stack[nSize] , POP
stack[nSize]
• ICO_MUL
Stack[nSize-1] = Stack[nSize-1] * Stack[nSize] , POP
stack[nSize]
• ICO_DIV
Stack[nSize-1] = Stack[nSize-1] / Stack[nSize] , POP
stack[nSize]
• ICO_MOD
Stack[nSize-1] = Stack[nSize-1] % Stack[nSize] , POP
stack[nSize]
• ICO_NEG
Stack[nSize] = - Stack[nSize-1]
• ICO_PLUSPLUS
Stack[nSize] = Stack[nSize] + 1
• ICO_MINUSMINUS
Stack[nSize] = Stack[nSize] - 1
(Logic)
Operation Description
• ICO_AND
Stack[nSize-1] = Stack[nSize-1] && Stack[nSize] ,
POP stack[nSize]
• ICO_OR
Stack[nSize-1] = Stack[nSize-1] || Stack[nSize] , POP
stack[nSize]
• ICO_NOT
Stack[nSize] = ! Stack[nSize]
(Lists)
97.7. Virtual Machine (VM) Instructions 1768
Ring Documentation, Release 1.5.3
Operation Description
• ICO_LISTSTART
Start New List in Temp. Memory
• ICO_LISTITEM
Add List Item
• ICO_LISTEND
End List
• ICO_LOADINDEXADDRESS
Stack[nSize-1] = Stack[nSize-1] VV [ Stack[nSize] ] ,
POP stack[nSize]
(Functions)
Operation Description
• ICO_LOADFUNC
Find function
• ICO_CALL
Call function
• ICO_RETURN
Return from function
• ICO_RETNULL
Return NULl from function
• ICO_RETFROMEVAL
Return after eval()
• ICO_RETITEMREF
Return the list item reference - not the value
• ICO_NEWFUNC
Start new function
• ICO_BLOCKFLAG
Flag to determine where to jump later (after
ICO_RETURN)
• ICO_FUNCEXE
Start executing function
• ICO_ENDFUNCEXE
End function execution
• ICO_ANONYMOUS
Anonymous function
(User Interface)
Operation Description
• ICO_PRINT
Print value to the standard output
• ICO_GIVE
Get input from the keyboard
(End Program/Loop)
97.7. Virtual Machine (VM) Instructions 1769
Ring Documentation, Release 1.5.3
Operation Description
• ICO_BYE
End execution of VM
• ICO_EXITMARK
Place to exit to from a loop
• ICO_POPEXITMARK
Remove exit mark
• ICO_EXIT
Break from one loop or more
• ICO_LOOP
Continue to next loop
(For Better Performance)
Operation Description
• ICO_PUSHP
Push pointer to the stack
• ICO_INCP
Increment variable value using pointer
• ICO_PUSHPV
Push value of variable using variable pointer
• ICO_INCJUMP
Increment then jump
• ICO_INCPJUMP
Increment using pointer then jump
• ICO_JUMPVARLENUM
Jump if variable value is <= numeric value
• ICO_JUMPVARPLENUM
Jump if variable value (using pointer) <= numeric value
• ICO_LOADFUNCP
Push function pointer
• ICO_PUSHPLOCAL
Push pointer to local variable
• ICO_INCLPJUMP
Increment value using pointer to local variable then
jump
• ICO_JUMPVARLPLENUM
Jump if the variable value (using pointer) <= numeric
value
• ICO_INCPJUMPSTEP1
Increment value using variable pointer then jump (for
loop step = 1)
• ICO_JUMPVARPLENUMSTEP1
Increment value using variable pointer then jump (for
loop step = 1)
(Try-Catch-Done)
97.7. Virtual Machine (VM) Instructions 1770
Ring Documentation, Release 1.5.3
Operation Description
• ICO_TRY
Start try region
• ICO_DONE
End try region
(Duplicate and Range)
Operation Description
• ICO_DUPLICATE
Duplicate stack value
• ICO_RANGE
Create list from value to value
(OOP)
Operation Description
• ICO_NEWOBJ
Create new object, get class name from the IR, push ob-
ject pointer to the stack.
• ICO_SETSCOPE
Called after creating new object, set the active scope to
be the object scope.
• ICO_LOADSUBADDRESS
Get object attribute, push the pointer to the stack.
• ICO_LOADMETHOD
Find object method
• ICO_AFTERCALLMETHOD
Used after calling a method - normal case
• ICO_AFTERCALLMETHOD2
Used after calling a method - second case
• ICO_NEWCLASS
Start new class region
• ICO_BRACESTART
Open brace
• ICO_BRACEEND
End brace
• ICO_IMPORT
Import package
• ICO_PRIVATE
start private attributes region
• ICO_SETPROPERTY
set attribute value - check for setter.
• ICO_CALLCLASSINIT
call call init() method.
(Other)
97.7. Virtual Machine (VM) Instructions 1771
Ring Documentation, Release 1.5.3
Operation Description
• ICO_SETREFERENCE
Copy by reference
• ICO_KILLREFERENCE
Remove reference
• ICO_ASSIGNMENTPOINTER
Determine the left side variable
• ICO_BEFOREEQUAL
Determine operators like += , -= , ... etc
(Bitwise Operators)
Operation Description
• ICO_BITAND
Stack[nSize-1] = Stack[nSize-1] & Stack[nSize] , POP
stack[nSize]
• ICO_BITOR
Stack[nSize-1] = Stack[nSize-1] | Stack[nSize] , POP
stack[nSize]
• ICO_BITXOR
Stack[nSize-1] = Stack[nSize-1] ^ Stack[nSize] , POP
stack[nSize]
• ICO_BITNOT
Stack[nSize] = ! Stack[nSize]
• ICO_BITSHL
Stack[nSize-1] = Stack[nSize-1] << Stack[nSize] , POP
stack[nSize]
• ICO_BITSHR
Stack[nSize-1] = Stack[nSize-1] >> Stack[nSize] , POP
stack[nSize]
(For Step)
Operation Description
• ICO_STEPNUMBER
Determine step number in for loop
• ICO_POPSTEP
POP step number from steps stack
• ICO_LOADAFIRST
Load the first address of variable name
97.7. Virtual Machine (VM) Instructions 1772
CHAPTER
NINETYEIGHT
RESOURCES
In this section you will find resources about the language
98.1 Ring Language Website
For news about the language check the website
http://ring-lang.net
http://ring-lang.sf.net
98.2 Ring Group
For questions use the Ring Group (English)
https://groups.google.com/forum/#!forum/ring-lang
98.3 Contact the Authors
Name : Eng. Mahmoud Samir Fayed
Country : Egypt
Email : msfclipper@yahoo.com
Facebook : https://facebook.com/mahmoudfayed1986
LinkedIn : https://sa.linkedin.com/in/mahmoudfayed1986
Name : Dr. Atif M. Alamri
Country : Saudi Arabia
Email : atif@ksu.edu.sa
LinkedIn : https://sa.linkedin.com/in/dr-atif-alamri-8b341747
Ring Team : http://ring-lang.sourceforge.net/team.html
1773
INDEX
3D Cube and Texture
Using RingOpenGL and RingAllegro for 3D Graph-
ics, 548
Access List Items by String Index
Lists, 193
Access Objects Using Braces
Object Oriented Programming, 270
Access String Letters
Strings, 195
Accessing the class attributes from braces inside class
methods
Scope Rules, 695
Add Items
Lists, 187
addattribute()
Reflection and Meta-programming, 297
AddDays()
Date and Time, 203
Adding code to the generated code
Code Generator, 780
Adding Hyperlink to QLabel
Desktop and Mobile Development, 599
addmethod()
Reflection and Meta-programming, 297
Analog Clock
Applications developed in little hours, 6
Animate Class
Game Engine for 2D Games, 451
Animate Events
Game Engine for 2D Games, 462
Animation
Game Engine for 2D Games, 456
Animation and Functions
Game Engine for 2D Games, 457
Anonymous and Nested Functions
Functional Programming, 283
Application Class
Web Development (CGI Library), 414
Applications
How to contribute?, 128
Applications developed in little hours
Analog Clock, 6
Calculator Application, 10
FetchStockData Application, 3
Fifteen Puzzle Game 2, 4
Google API Shortener Application, 5
Innovative, 19
Introduction, 1
Practical, 20
Quotes about Ring, 1
Samples in this book, 13
Squares Puzzle Game, 8
TicTacToe Game, 7
Video-Music-Player Application, 9
Werdy Application, 12
Windows StartUp Manager Application, 11
apppath()
Stdlib Functions, 304
Arithmetic Operators
Operators, 154
Ascii()
Data Type, 211
Assert()
Eval() and Debugging, 237
Assignment Operators
Operators, 155
attributes()
Reflection and Meta-programming, 294
Better Call Command
What is new in Ring 1.2?, 108
Better Code Generator for Extensions
What is new in Ring 1.1?, 118
What is new in Ring 1.5?, 60
Better Documentation
What is new in Ring 1.1?, 118
Better Documentation Generator for Extensions
What is new in Ring 1.5?, 61
Better Functions
What is new in Ring 1.2?, 105
Better Loop|Exit Command
What is new in Ring 1.3?, 99
Better Natural Language Programming Support
What is new in Ring 1.1?, 110
Better Objects Library
1774

More Related Content

PDF
The Ring programming language version 1.7 book - Part 93 of 196
PDF
The Ring programming language version 1.6 book - Part 185 of 189
PDF
The Ring programming language version 1.9 book - Part 101 of 210
PDF
[131]해커의 관점에서 바라보기
PDF
The Ring programming language version 1.8 book - Part 30 of 202
PDF
The Ring programming language version 1.8 book - Part 31 of 202
PDF
The Ring programming language version 1.5.2 book - Part 26 of 181
PDF
JavaScript ∩ WebAssembly
The Ring programming language version 1.7 book - Part 93 of 196
The Ring programming language version 1.6 book - Part 185 of 189
The Ring programming language version 1.9 book - Part 101 of 210
[131]해커의 관점에서 바라보기
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.5.2 book - Part 26 of 181
JavaScript ∩ WebAssembly

What's hot (20)

PDF
The Ring programming language version 1.5.2 book - Part 45 of 181
PDF
The Ring programming language version 1.6 book - Part 28 of 189
PDF
The Ring programming language version 1.5.3 book - Part 26 of 184
PDF
The Ring programming language version 1.7 book - Part 30 of 196
PDF
The Ring programming language version 1.9 book - Part 48 of 210
PDF
GenServer in action
PDF
The Ring programming language version 1.5.2 book - Part 13 of 181
PDF
The Ring programming language version 1.6 book - Part 27 of 189
PDF
The Ring programming language version 1.2 book - Part 16 of 84
PDF
The Ring programming language version 1.5.3 book - Part 40 of 184
PDF
The Ring programming language version 1.6 book - Part 55 of 189
PDF
The Ring programming language version 1.8 book - Part 96 of 202
PDF
The Ring programming language version 1.5.2 book - Part 177 of 181
PDF
Solr @ Etsy - Apache Lucene Eurocon
PDF
Kotlin Coroutines - the new async
PDF
The Ring programming language version 1.6 book - Part 15 of 189
PDF
Grails/Groovyによる開発事例紹介
PDF
The Ring programming language version 1.5.3 book - Part 25 of 184
PDF
The Ring programming language version 1.7 book - Part 29 of 196
PDF
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.5.3 book - Part 26 of 184
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.9 book - Part 48 of 210
GenServer in action
The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.8 book - Part 96 of 202
The Ring programming language version 1.5.2 book - Part 177 of 181
Solr @ Etsy - Apache Lucene Eurocon
Kotlin Coroutines - the new async
The Ring programming language version 1.6 book - Part 15 of 189
Grails/Groovyによる開発事例紹介
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.7 book - Part 29 of 196
The Ring programming language version 1.5.1 book - Part 24 of 180
Ad

Similar to The Ring programming language version 1.5.3 book - Part 19 of 194 (20)

PDF
The Ring programming language version 1.3 book - Part 85 of 88
PDF
The Ring programming language version 1.4.1 book - Part 30 of 31
PDF
The Ring programming language version 1.5.4 book - Part 181 of 185
PPTX
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
PPT
Lec2&3 data structure
PDF
Node Boot Camp
PDF
The Ring programming language version 1.4.1 book - Part 3 of 31
PDF
The Ring programming language version 1.7 book - Part 16 of 196
PDF
verilog HDL introduction - beginners guide
PDF
Tame cloud complexity with F# powered DSLs (build stuff)
PDF
The Ring programming language version 1.5.1 book - Part 12 of 180
PDF
GenServer in Action – Yurii Bodarev
KEY
Agile Iphone Development
PDF
groovy databases
PPTX
Getting started with Elasticsearch and .NET
PDF
Pdxpugday2010 pg90
PDF
The Ring programming language version 1.5.3 book - Part 15 of 184
PPTX
The uniform interface is 42
PDF
how to reuse code
The Ring programming language version 1.3 book - Part 85 of 88
The Ring programming language version 1.4.1 book - Part 30 of 31
The Ring programming language version 1.5.4 book - Part 181 of 185
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Lec2&3 data structure
Node Boot Camp
The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.7 book - Part 16 of 196
verilog HDL introduction - beginners guide
Tame cloud complexity with F# powered DSLs (build stuff)
The Ring programming language version 1.5.1 book - Part 12 of 180
GenServer in Action – Yurii Bodarev
Agile Iphone Development
groovy databases
Getting started with Elasticsearch and .NET
Pdxpugday2010 pg90
The Ring programming language version 1.5.3 book - Part 15 of 184
The uniform interface is 42
how to reuse code
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
Spectroscopy.pptx food analysis technology
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.

The Ring programming language version 1.5.3 book - Part 19 of 194

  • 1. Ring Documentation, Release 1.5.3 97.6 Language Grammar Program —> {statement} Statement —> ‘package’ <Identifier> { ‘.’ <Identifier> } [’{‘ {statement} ‘}’] [’end’|’endpackage’] Statement —> ‘class’ <Identifier> [ ‘from’|’:’|’<’ <Identifier> ] [’{‘ {statement} ‘}’][’end’|’endclass’] Statement —> ‘func’|’def’ <Identifier> [ParaList] [’{‘ {statement} ‘}’][’end’|’endfunc’] Statement —> ‘import’ <Identifier> { ‘.’ <Identifier> } Statement —> ‘private’ Statement —> ‘load’ <Literal> Statement —> ‘loadsyntax’ <Literal> Statement —> ‘changeringkeyword’ <OldKeyword> <NewKeyword> Statement —> ‘changeringoperator’ <OldOperator> <NewOperator> Statement —> ‘see’|’put’ <Expr> Statement —> ‘give’|’get’ <Identifier> Statement —> ‘if’ <Expr> [’{‘] {statement} [ {‘but’|’elseif’ <Expr> {Statement} } ] [’else’ {Statement} ] ‘ok’|’end’|’}’ Statement —> ‘Switch’ <Expr> [’{‘] { ‘on’|’case’ <Expr> {statement} } [’other’ {Statement} ] ‘off’|’end’|’}’ Statement —> ‘for’ <Identifier> ‘=’ <Expr> ‘to’ <Expr> [ ‘step’ <Expr> ] [’{‘] {Statement} ‘next’|’end’|’}’ Statement —> ‘for’ <Identifier> ‘in’ <Expr> [ ‘step’ <Expr> ] [’{‘] {statement} ‘next’|’end’|’}’ Statement —> ‘while’ <Expr> [’{‘] {statement} ‘end’|’}’ Statement —> ‘do’ {statement} ‘again’ <Expr> Statement —> ‘try’ {statement} [’{‘] ‘catch’ {statement} ‘done’|’end’|’}’ Statement —> ‘return’ <Expr> Statement —> ‘bye’ Statement —> ‘exit’ Statement —> ‘loop’ Statement —> <Expr> Statement —> epslion ParaList —> epslion ParaList —> [’(‘] <Identifier> [{ ‘,’ <Identifier> }] [’)’] Expr —> <LogicNot> [{ ‘and’|’or’ <LogicNot> }] LogicNot –> [’not’] <EqualOrNot> EqualOrNot –> [ ‘=’|’!=’ ] <Compare> Compare —> <BitOrXor> [ { ‘<’ | ‘>’ | ‘<=’ | ‘>=’ <BitOrXor> } ] BitOrXor —> <BitAnd> [ { ‘|’ | ‘^’ <BitAnd> } ] BitAnd —> <BitShift> [ { ‘&’ <BitShift> } ] BitShift —> <Arithmetic> [ { ‘<<’ | ‘>>’ <Arithmetic> } ] 97.6. Language Grammar 1765
  • 2. Ring Documentation, Release 1.5.3 Arithmetic —> <Term> [ { ‘+’ | ‘-‘ <Term> } ] Term —> <Range> [ { ‘*’ | ‘/’ | ‘%’ <Range> } ] Range —> <Factor> [ ‘:’ <Factor> ] Factor —> <Identifier> [ {Mixer} ] [ ‘=’ <Expr> ] Factor —> <Number> Factor —> <Literal> Factor —> ‘:’ <Identifier> Factor —> ‘-‘ <Expr> Factor —> ‘(‘ <Expr> ‘)’ Factor —> <List> Factor —> ‘new’ <Identifier> Factor —> <AnonymousFunction> Factor —> ‘call’ <identifier> { ‘.’ <Identifier> } ‘(‘ <Parameters> ‘)’ List —> ‘[’ [ <Expr> { ‘,’ <Expr> } ] ‘]’ Mixer —> { ‘.’ <Identifier> } Mixer —> ‘[’ <Expr> ‘]’ Mixer —> ‘(‘ [ <Expr> [ { ‘,’ <Expr> }] ] ‘)’ Mixer —> ‘{‘ {Statement} ‘}’ AnonymousFunction —> ‘func’|’def’| [<ParaList>] ‘{‘ {Statement} ‘}’ 97.7 Virtual Machine (VM) Instructions Definitions :- • VM : Virtual Machine • Stack : VM Stack • IR : Instruction Register • PC : Program Counter • VP : Variable Pointer • Stack[nSize] : Last Item in the Stack (Last In - First Out) • VV : Variable Value (We have a Pointer to a variable, And we access this variable value) (Stack and Variables) 97.7. Virtual Machine (VM) Instructions 1766
  • 3. Ring Documentation, Release 1.5.3 Operation Description • ICO_PUSHC Add string from the IR to the stack • ICO_PUSHN Add number from the IR to the stack • ICO_PUSHV Replace VP in the stack[nSize] with the variable value • ICO_LOADADDRESS Read variable name from the IR, push VP to the stack • ICO_ASSIGNMENT Stack[nSize-1] VV = Stack[nSize] VV , POP Stack[nSize] • ICO_INC Increment Number in Stack[nSize] by 1 • ICO_LOADAPUSHV The same as ICO_LOADADDRESS then ICO_PUSHV • ICO_NEWLINE Store new line number (debug info) • ICO_FREESTACK Remove all items from the stack , nSize = 0 • ICO_FILENAME Store the source code file name (debug info) • ICO_FREELOADASCOPE Free the Scope List of the current Expression (Jump) Operation Description • ICO_JUMP Set PC to new value from the IR • ICO_JUMPZERO If Stack[nSize] is a number = 0 then Set PC to new value from the IR • ICO_JUMPFOR End of for loop • ICO_JUMPONE If Stack[nSize] is a number = 1 then Set PC to new value from the IR • ICO_JUMPZERO2 As ICO_JUMPZERO but add 1 to the stack (required for many ‘AND’ conditions) • ICO_JUMPONE2 As ICO_JUMPONE but add 1 to the stack (required for many ‘OR’ conditions) (Compare) 97.7. Virtual Machine (VM) Instructions 1767
  • 4. Ring Documentation, Release 1.5.3 Operation Description • ICO_LESSEQUAL If stack[nSize-1] <= stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0 • ICO_EQUAL If stack[nSize-1] = stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0 • ICO_LESS If stack[nSize-1] < stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0 • ICO_GREATER If stack[nSize-1] > stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0 • ICO_GREATEREQUAL If stack[nSize-1] >= stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0 • ICO_NOTEQUAL If stack[nSize-1] != stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0 (Math) Operation Description • ICO_SUM Stack[nSize-1] = Stack[nSize-1] + Stack[nSize] , POP stack[nSize] • ICO_SUB Stack[nSize-1] = Stack[nSize-1] - Stack[nSize] , POP stack[nSize] • ICO_MUL Stack[nSize-1] = Stack[nSize-1] * Stack[nSize] , POP stack[nSize] • ICO_DIV Stack[nSize-1] = Stack[nSize-1] / Stack[nSize] , POP stack[nSize] • ICO_MOD Stack[nSize-1] = Stack[nSize-1] % Stack[nSize] , POP stack[nSize] • ICO_NEG Stack[nSize] = - Stack[nSize-1] • ICO_PLUSPLUS Stack[nSize] = Stack[nSize] + 1 • ICO_MINUSMINUS Stack[nSize] = Stack[nSize] - 1 (Logic) Operation Description • ICO_AND Stack[nSize-1] = Stack[nSize-1] && Stack[nSize] , POP stack[nSize] • ICO_OR Stack[nSize-1] = Stack[nSize-1] || Stack[nSize] , POP stack[nSize] • ICO_NOT Stack[nSize] = ! Stack[nSize] (Lists) 97.7. Virtual Machine (VM) Instructions 1768
  • 5. Ring Documentation, Release 1.5.3 Operation Description • ICO_LISTSTART Start New List in Temp. Memory • ICO_LISTITEM Add List Item • ICO_LISTEND End List • ICO_LOADINDEXADDRESS Stack[nSize-1] = Stack[nSize-1] VV [ Stack[nSize] ] , POP stack[nSize] (Functions) Operation Description • ICO_LOADFUNC Find function • ICO_CALL Call function • ICO_RETURN Return from function • ICO_RETNULL Return NULl from function • ICO_RETFROMEVAL Return after eval() • ICO_RETITEMREF Return the list item reference - not the value • ICO_NEWFUNC Start new function • ICO_BLOCKFLAG Flag to determine where to jump later (after ICO_RETURN) • ICO_FUNCEXE Start executing function • ICO_ENDFUNCEXE End function execution • ICO_ANONYMOUS Anonymous function (User Interface) Operation Description • ICO_PRINT Print value to the standard output • ICO_GIVE Get input from the keyboard (End Program/Loop) 97.7. Virtual Machine (VM) Instructions 1769
  • 6. Ring Documentation, Release 1.5.3 Operation Description • ICO_BYE End execution of VM • ICO_EXITMARK Place to exit to from a loop • ICO_POPEXITMARK Remove exit mark • ICO_EXIT Break from one loop or more • ICO_LOOP Continue to next loop (For Better Performance) Operation Description • ICO_PUSHP Push pointer to the stack • ICO_INCP Increment variable value using pointer • ICO_PUSHPV Push value of variable using variable pointer • ICO_INCJUMP Increment then jump • ICO_INCPJUMP Increment using pointer then jump • ICO_JUMPVARLENUM Jump if variable value is <= numeric value • ICO_JUMPVARPLENUM Jump if variable value (using pointer) <= numeric value • ICO_LOADFUNCP Push function pointer • ICO_PUSHPLOCAL Push pointer to local variable • ICO_INCLPJUMP Increment value using pointer to local variable then jump • ICO_JUMPVARLPLENUM Jump if the variable value (using pointer) <= numeric value • ICO_INCPJUMPSTEP1 Increment value using variable pointer then jump (for loop step = 1) • ICO_JUMPVARPLENUMSTEP1 Increment value using variable pointer then jump (for loop step = 1) (Try-Catch-Done) 97.7. Virtual Machine (VM) Instructions 1770
  • 7. Ring Documentation, Release 1.5.3 Operation Description • ICO_TRY Start try region • ICO_DONE End try region (Duplicate and Range) Operation Description • ICO_DUPLICATE Duplicate stack value • ICO_RANGE Create list from value to value (OOP) Operation Description • ICO_NEWOBJ Create new object, get class name from the IR, push ob- ject pointer to the stack. • ICO_SETSCOPE Called after creating new object, set the active scope to be the object scope. • ICO_LOADSUBADDRESS Get object attribute, push the pointer to the stack. • ICO_LOADMETHOD Find object method • ICO_AFTERCALLMETHOD Used after calling a method - normal case • ICO_AFTERCALLMETHOD2 Used after calling a method - second case • ICO_NEWCLASS Start new class region • ICO_BRACESTART Open brace • ICO_BRACEEND End brace • ICO_IMPORT Import package • ICO_PRIVATE start private attributes region • ICO_SETPROPERTY set attribute value - check for setter. • ICO_CALLCLASSINIT call call init() method. (Other) 97.7. Virtual Machine (VM) Instructions 1771
  • 8. Ring Documentation, Release 1.5.3 Operation Description • ICO_SETREFERENCE Copy by reference • ICO_KILLREFERENCE Remove reference • ICO_ASSIGNMENTPOINTER Determine the left side variable • ICO_BEFOREEQUAL Determine operators like += , -= , ... etc (Bitwise Operators) Operation Description • ICO_BITAND Stack[nSize-1] = Stack[nSize-1] & Stack[nSize] , POP stack[nSize] • ICO_BITOR Stack[nSize-1] = Stack[nSize-1] | Stack[nSize] , POP stack[nSize] • ICO_BITXOR Stack[nSize-1] = Stack[nSize-1] ^ Stack[nSize] , POP stack[nSize] • ICO_BITNOT Stack[nSize] = ! Stack[nSize] • ICO_BITSHL Stack[nSize-1] = Stack[nSize-1] << Stack[nSize] , POP stack[nSize] • ICO_BITSHR Stack[nSize-1] = Stack[nSize-1] >> Stack[nSize] , POP stack[nSize] (For Step) Operation Description • ICO_STEPNUMBER Determine step number in for loop • ICO_POPSTEP POP step number from steps stack • ICO_LOADAFIRST Load the first address of variable name 97.7. Virtual Machine (VM) Instructions 1772
  • 9. CHAPTER NINETYEIGHT RESOURCES In this section you will find resources about the language 98.1 Ring Language Website For news about the language check the website http://ring-lang.net http://ring-lang.sf.net 98.2 Ring Group For questions use the Ring Group (English) https://groups.google.com/forum/#!forum/ring-lang 98.3 Contact the Authors Name : Eng. Mahmoud Samir Fayed Country : Egypt Email : msfclipper@yahoo.com Facebook : https://facebook.com/mahmoudfayed1986 LinkedIn : https://sa.linkedin.com/in/mahmoudfayed1986 Name : Dr. Atif M. Alamri Country : Saudi Arabia Email : atif@ksu.edu.sa LinkedIn : https://sa.linkedin.com/in/dr-atif-alamri-8b341747 Ring Team : http://ring-lang.sourceforge.net/team.html 1773
  • 10. INDEX 3D Cube and Texture Using RingOpenGL and RingAllegro for 3D Graph- ics, 548 Access List Items by String Index Lists, 193 Access Objects Using Braces Object Oriented Programming, 270 Access String Letters Strings, 195 Accessing the class attributes from braces inside class methods Scope Rules, 695 Add Items Lists, 187 addattribute() Reflection and Meta-programming, 297 AddDays() Date and Time, 203 Adding code to the generated code Code Generator, 780 Adding Hyperlink to QLabel Desktop and Mobile Development, 599 addmethod() Reflection and Meta-programming, 297 Analog Clock Applications developed in little hours, 6 Animate Class Game Engine for 2D Games, 451 Animate Events Game Engine for 2D Games, 462 Animation Game Engine for 2D Games, 456 Animation and Functions Game Engine for 2D Games, 457 Anonymous and Nested Functions Functional Programming, 283 Application Class Web Development (CGI Library), 414 Applications How to contribute?, 128 Applications developed in little hours Analog Clock, 6 Calculator Application, 10 FetchStockData Application, 3 Fifteen Puzzle Game 2, 4 Google API Shortener Application, 5 Innovative, 19 Introduction, 1 Practical, 20 Quotes about Ring, 1 Samples in this book, 13 Squares Puzzle Game, 8 TicTacToe Game, 7 Video-Music-Player Application, 9 Werdy Application, 12 Windows StartUp Manager Application, 11 apppath() Stdlib Functions, 304 Arithmetic Operators Operators, 154 Ascii() Data Type, 211 Assert() Eval() and Debugging, 237 Assignment Operators Operators, 155 attributes() Reflection and Meta-programming, 294 Better Call Command What is new in Ring 1.2?, 108 Better Code Generator for Extensions What is new in Ring 1.1?, 118 What is new in Ring 1.5?, 60 Better Documentation What is new in Ring 1.1?, 118 Better Documentation Generator for Extensions What is new in Ring 1.5?, 61 Better Functions What is new in Ring 1.2?, 105 Better Loop|Exit Command What is new in Ring 1.3?, 99 Better Natural Language Programming Support What is new in Ring 1.1?, 110 Better Objects Library 1774