Вы находитесь на странице: 1из 10

Ring Documentation, Release 1.5.

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
Add string from the IR to the stack
• ICO_PUSHC

Add number from the IR to the stack


• ICO_PUSHN

Replace VP in the stack[nSize] with the variable value


• ICO_PUSHV

Read variable name from the IR, push VP to the stack


• ICO_LOADADDRESS

Stack[nSize-1] VV = Stack[nSize] VV , POP


• ICO_ASSIGNMENT
Stack[nSize]
Increment Number in Stack[nSize] by 1
• ICO_INC

The same as ICO_LOADADDRESS then ICO_PUSHV


• ICO_LOADAPUSHV

Store new line number (debug info)


• ICO_NEWLINE

Remove all items from the stack , nSize = 0


• ICO_FREESTACK

Store the source code file name (debug info)


• ICO_FILENAME

Free the Scope List of the current Expression


• ICO_FREELOADASCOPE

(Jump)
Operation Description
Set PC to new value from the IR
• ICO_JUMP

If Stack[nSize] is a number = 0 then Set PC to new value


• ICO_JUMPZERO
from the IR
End of for loop
• ICO_JUMPFOR

If Stack[nSize] is a number = 1 then Set PC to new value


• ICO_JUMPONE
from the IR
As ICO_JUMPZERO but add 1 to the stack (required
• ICO_JUMPZERO2
for many ‘AND’ conditions)
As ICO_JUMPONE but add 1 to the stack (required for
• ICO_JUMPONE2
many ‘OR’ conditions)

(Compare)

97.7. Virtual Machine (VM) Instructions 1767


Ring Documentation, Release 1.5.3

Operation Description
If stack[nSize-1] <= stack[nSize] , POP stack[nSize], set
• ICO_LESSEQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] = stack[nSize] , POP stack[nSize], set
• ICO_EQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] < stack[nSize] , POP stack[nSize], set
• ICO_LESS
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] > stack[nSize] , POP stack[nSize], set
• ICO_GREATER
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] >= stack[nSize] , POP stack[nSize], set
• ICO_GREATEREQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] != stack[nSize] , POP stack[nSize], set
• ICO_NOTEQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0

(Math)
Operation Description
Stack[nSize-1] = Stack[nSize-1] + Stack[nSize] , POP
• ICO_SUM
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] - Stack[nSize] , POP
• ICO_SUB
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] * Stack[nSize] , POP
• ICO_MUL
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] / Stack[nSize] , POP
• ICO_DIV
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] % Stack[nSize] , POP
• ICO_MOD
stack[nSize]
Stack[nSize] = - Stack[nSize-1]
• ICO_NEG

Stack[nSize] = Stack[nSize] + 1
• ICO_PLUSPLUS

Stack[nSize] = Stack[nSize] - 1
• ICO_MINUSMINUS

(Logic)
Operation Description
Stack[nSize-1] = Stack[nSize-1] && Stack[nSize] ,
• ICO_AND
POP stack[nSize]
Stack[nSize-1] = Stack[nSize-1] || Stack[nSize] , POP
• ICO_OR
stack[nSize]
Stack[nSize] = ! Stack[nSize]
• ICO_NOT

(Lists)

97.7. Virtual Machine (VM) Instructions 1768


Ring Documentation, Release 1.5.3

Operation Description
Start New List in Temp. Memory
• ICO_LISTSTART

Add List Item


• ICO_LISTITEM

End List
• ICO_LISTEND

Stack[nSize-1] = Stack[nSize-1] VV [ Stack[nSize] ] ,


• ICO_LOADINDEXADDRESS
POP stack[nSize]

(Functions)
Operation Description
Find function
• ICO_LOADFUNC

Call function
• ICO_CALL

Return from function


• ICO_RETURN

Return NULl from function


• ICO_RETNULL

Return after eval()


• ICO_RETFROMEVAL

Return the list item reference - not the value


• ICO_RETITEMREF

Start new function


• ICO_NEWFUNC

Flag to determine where to jump later (after


• ICO_BLOCKFLAG
ICO_RETURN)
Start executing function
• ICO_FUNCEXE

End function execution


• ICO_ENDFUNCEXE

Anonymous function
• ICO_ANONYMOUS

(User Interface)
Operation Description
Print value to the standard output
• ICO_PRINT

Get input from the keyboard


• ICO_GIVE

(End Program/Loop)

97.7. Virtual Machine (VM) Instructions 1769


Ring Documentation, Release 1.5.3

Operation Description
End execution of VM
• ICO_BYE

Place to exit to from a loop


• ICO_EXITMARK

Remove exit mark


• ICO_POPEXITMARK

Break from one loop or more


• ICO_EXIT

Continue to next loop


• ICO_LOOP

(For Better Performance)


Operation Description
Push pointer to the stack
• ICO_PUSHP

Increment variable value using pointer


• ICO_INCP

Push value of variable using variable pointer


• ICO_PUSHPV

Increment then jump


• ICO_INCJUMP

Increment using pointer then jump


• ICO_INCPJUMP

Jump if variable value is <= numeric value


• ICO_JUMPVARLENUM

Jump if variable value (using pointer) <= numeric value


• ICO_JUMPVARPLENUM

Push function pointer


• ICO_LOADFUNCP

Push pointer to local variable


• ICO_PUSHPLOCAL

Increment value using pointer to local variable then


• ICO_INCLPJUMP
jump
Jump if the variable value (using pointer) <= numeric
• ICO_JUMPVARLPLENUM
value
Increment value using variable pointer then jump (for
• ICO_INCPJUMPSTEP1
loop step = 1)
Increment value using variable pointer then jump (for
• ICO_JUMPVARPLENUMSTEP1
loop step = 1)

(Try-Catch-Done)

97.7. Virtual Machine (VM) Instructions 1770


Ring Documentation, Release 1.5.3

Operation Description
Start try region
• ICO_TRY

End try region


• ICO_DONE

(Duplicate and Range)


Operation Description
Duplicate stack value
• ICO_DUPLICATE

Create list from value to value


• ICO_RANGE

(OOP)
Operation Description
Create new object, get class name from the IR, push ob-
• ICO_NEWOBJ
ject pointer to the stack.
Called after creating new object, set the active scope to
• ICO_SETSCOPE
be the object scope.
Get object attribute, push the pointer to the stack.
• ICO_LOADSUBADDRESS

Find object method


• ICO_LOADMETHOD

Used after calling a method - normal case


• ICO_AFTERCALLMETHOD

Used after calling a method - second case


• ICO_AFTERCALLMETHOD2

Start new class region


• ICO_NEWCLASS

Open brace
• ICO_BRACESTART

End brace
• ICO_BRACEEND

Import package
• ICO_IMPORT

start private attributes region


• ICO_PRIVATE

set attribute value - check for setter.


• ICO_SETPROPERTY

call call init() method.


• ICO_CALLCLASSINIT

(Other)

97.7. Virtual Machine (VM) Instructions 1771


Ring Documentation, Release 1.5.3

Operation Description
Copy by reference
• ICO_SETREFERENCE

Remove reference
• ICO_KILLREFERENCE

Determine the left side variable


• ICO_ASSIGNMENTPOINTER

Determine operators like += , -= , ... etc


• ICO_BEFOREEQUAL

(Bitwise Operators)
Operation Description
Stack[nSize-1] = Stack[nSize-1] & Stack[nSize] , POP
• ICO_BITAND
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] | Stack[nSize] , POP
• ICO_BITOR
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] ^ Stack[nSize] , POP
• ICO_BITXOR
stack[nSize]
Stack[nSize] = ! Stack[nSize]
• ICO_BITNOT

Stack[nSize-1] = Stack[nSize-1] << Stack[nSize] , POP


• ICO_BITSHL
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] >> Stack[nSize] , POP
• ICO_BITSHR
stack[nSize]

(For Step)
Operation Description
Determine step number in for loop
• ICO_STEPNUMBER

POP step number from steps stack


• ICO_POPSTEP

Load the first address of variable name


• ICO_LOADAFIRST

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 Calculator Application, 10


Using RingOpenGL and RingAllegro for 3D Graph- FetchStockData Application, 3
ics, 548 Fifteen Puzzle Game 2, 4
Google API Shortener Application, 5
Access List Items by String Index Innovative, 19
Lists, 193 Introduction, 1
Access Objects Using Braces Practical, 20
Object Oriented Programming, 270 Quotes about Ring, 1
Access String Letters Samples in this book, 13
Strings, 195 Squares Puzzle Game, 8
Accessing the class attributes from braces inside class TicTacToe Game, 7
methods Video-Music-Player Application, 9
Scope Rules, 695 Werdy Application, 12
Add Items Windows StartUp Manager Application, 11
Lists, 187 apppath()
addattribute() Stdlib Functions, 304
Reflection and Meta-programming, 297 Arithmetic Operators
AddDays() Operators, 154
Date and Time, 203 Ascii()
Adding code to the generated code Data Type, 211
Code Generator, 780 Assert()
Adding Hyperlink to QLabel Eval() and Debugging, 237
Desktop and Mobile Development, 599 Assignment Operators
addmethod() Operators, 155
Reflection and Meta-programming, 297 attributes()
Analog Clock Reflection and Meta-programming, 294
Applications developed in little hours, 6
Animate Class Better Call Command
Game Engine for 2D Games, 451 What is new in Ring 1.2?, 108
Animate Events Better Code Generator for Extensions
Game Engine for 2D Games, 462 What is new in Ring 1.1?, 118
Animation What is new in Ring 1.5?, 60
Game Engine for 2D Games, 456 Better Documentation
Animation and Functions What is new in Ring 1.1?, 118
Game Engine for 2D Games, 457 Better Documentation Generator for Extensions
Anonymous and Nested Functions What is new in Ring 1.5?, 61
Functional Programming, 283 Better Functions
Application Class What is new in Ring 1.2?, 105
Web Development (CGI Library), 414 Better Loop|Exit Command
Applications What is new in Ring 1.3?, 99
How to contribute?, 128 Better Natural Language Programming Support
Applications developed in little hours What is new in Ring 1.1?, 110
Analog Clock, 6 Better Objects Library

1774

Вам также может понравиться