Command Line Options

The ring language takes source code file (.ring) or the object file (.ringo) as input to execute, also the language provide other options like

Option Description
-tokens Print a list of tokens in the source code file
-rules Print grammar rules applied on the tokens
-ic Print the intermediate byte code (before execution)
-icfinal Print the final byte code (after execution)
-cgi Print http response header before error messages
-norun Don’t run the program after compiling
-ins Print instruction operation code before execution
-performance Print clock before and after program execution
-go Generate Object File

Printing Tokens

Example:

Func Main
        See "Hello World" + nl
        for x = 1 to 10
                see x + nl
        next
        test()

func test
        see "welcome" + nl
        o1 = new point { x=10 y=20 z=30 }
        see o1

class point x y z

Command:

ring test.ring -tokens -norun

Output:

===================================================
Tokens - Generated by the Scanner
===================================================

   Keyword : FUNC
Identifier : main
   EndLine
   Keyword : SEE
   Literal : Hello World
  Operator : +
Identifier : nl
   EndLine
   Keyword : FOR
Identifier : x
  Operator : =
    Number : 1
   Keyword : TO
    Number : 10
   EndLine
   Keyword : SEE
Identifier : x
  Operator : +
Identifier : nl
   EndLine
   Keyword : NEXT
   EndLine
Identifier : test
  Operator : (
  Operator : )
   EndLine
   Keyword : FUNC
Identifier : test
   EndLine
   Keyword : SEE
   Literal : welcome
  Operator : +
Identifier : nl
   EndLine
Identifier : o1
  Operator : =
   Keyword : NEW
Identifier : point
  Operator : {
Identifier : x
  Operator : =
    Number : 10
Identifier : y
  Operator : =
    Number : 20
Identifier : z
  Operator : =
    Number : 30
  Operator : }
   EndLine
   Keyword : SEE
Identifier : o1
   EndLine
   Keyword : CLASS
Identifier : point
Identifier : x
Identifier : y
Identifier : z
   EndLine

===================================================

Printing Rules

Command:

ring test.ring -rules -norun

Output:

===================================================
Grammar Rules Used by The Parser
===================================================

Rule : Program --> {Statement}

Line 1
Rule : Statement  --> 'Func' Identifier [ParaList]

Line 2
Rule : Factor --> Literal
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : Arithmetic --> Arithmetic + Arithmetic
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> 'See' Expr

Line 3
Rule : Factor --> Number
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Factor --> Number
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> 'For' Identifier '=' Expr to Expr ['step' Expr]

Line 4
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : Arithmetic --> Arithmetic + Arithmetic
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> 'See' Expr

Line 5
Rule : Next --> 'Next'

Line 6
Rule : Mixer -> '(' [Expr { ',' Expr} ] ')'

Line 8
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr
Rule : Statement  --> 'Func' Identifier [ParaList]

Line 9
Rule : Factor --> Literal
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : Arithmetic --> Arithmetic + Arithmetic
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> 'See' Expr

Line 10
Rule : Factor --> New Identifier {'.' Identifier }
Rule : Mixer --> '{' {Statement} BraceEnd
Rule : Factor --> Number
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Assignment -> '=' Expr
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr
Rule : Factor --> Number
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Assignment -> '=' Expr
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr
Rule : Factor --> Number
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Assignment -> '=' Expr
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr
Rule : BraceEnd --> '}'
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Assignment -> '=' Expr
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr

Line 11
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> 'See' Expr

Line 13
Rule : Statement  --> 'Class' Identifier
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr
Rule : Factor --> Identifier [ {Mixer} | Assignment | PlusPlus | MinusMinus]
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
Rule : BitOrXOR -->  BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement  --> Expr

===================================================

Printing Intermediate Code

Command:

ring test.ring -ic -norun

Output:

===================================================
Byte Code - Before Execution by the VM
===================================================

         PC      OPCode        Data

          1  ReturnNull
          2        Func    main
          3     NewLine       2
          4     FuncExE
          5       PushC   Hello World
          6       LoadA      nl      0
          7       PushV
          8         SUM       0
          9       Print
         10     NewLine       3
         11    ExitMark      29     28
         12  LoadAFirst       x
         13       PushN   1.000000
         14  BeforeEqual       0
         15  Assignment
         16       PushN   1.000000
         17  StepNumber
         18  JumpVarLENum       x  10.000000    29
         19     NewLine       4
         20     FuncExE
         21       LoadA       x      0
         22       PushV
         23       LoadA      nl      0
         24       PushV
         25         SUM       0
         26       Print
         27     NewLine       5
         28     IncJump       x     18
         29  POPExitMark
         30     POPStep
         31     NewLine       6
         32    LoadFunc    test
         33        Call       0
         34  NoOperation
         35     NewLine       8
         36       PushV
         37   FreeStack
         38  ReturnNull
         39        Func    test
         40     NewLine       9
         41     FuncExE
         42       PushC   welcome
         43       LoadA      nl      0
         44       PushV
         45         SUM       0
         46       Print
         47     NewLine      10
         48       LoadA      o1      0
         49  AssignmentPointer
         50         New   point
         51    SetScope
         52       PushV
         53  BraceStart
         54       LoadA       x      0     58
         55  AssignmentPointer
         56       PushN   10.000000
         57  BeforeEqual       0
         58  Assignment       0      0
         59   FreeStack
         60       LoadA       y      0     64
         61  AssignmentPointer
         62       PushN   20.000000
         63  BeforeEqual       0
         64  Assignment       0      0
         65   FreeStack
         66       LoadA       z      0     70
         67  AssignmentPointer
         68       PushN   30.000000
         69  BeforeEqual       0
         70  Assignment       0      0
         71   FreeStack
         72    LoadFunc   ismethod
         73       LoadA    self      0
         74       PushV
         75       PushC   braceend
         76        Call
         77  NoOperation
         78       PushV
         79       JumpZ      85
         80    LoadFunc   braceend
         81        Call
         82  NoOperation
         83       PushV
         84   FreeStack
         85    BraceEnd
         86   FreeStack
         87     NewLine      11
         88     FuncExE
         89       LoadA      o1      0
         90       PushV
         91       Print
         92     NewLine      13
         93  ReturnNull
         94       Class   point  006E8BC0
         95    NewLabel
         96       LoadA       x      0
         97       PushV
         98   FreeStack
         99       LoadA       y      0
        100       PushV
        101   FreeStack
        102       LoadA       z      0
        103       PushV
        104   FreeStack
        105  ReturnNull

===================================================

Printing Final Intermediate Code

Command:

ring test.ring -icfinal

Output:

Hello World
1
2
3
4
5
6
7
8
9
10
welcome
x: 10.000000
y: 20.000000
z: 30.000000


===================================================
Byte Code - After Execution by the VM
===================================================

         PC      OPCode        Data

          1  ReturnNull
          2        Func    main
          3     NewLine       2
          4     FuncExE
          5       PushC   Hello World
          6       PushP   007D3670      0
          7       PushV
          8         SUM       0
          9       Print
         10     NewLine       3
         11    ExitMark      29     28
         12  LoadAFirst       x
         13       PushN   1.000000
         14  BeforeEqual       0
         15  Assignment
         16       PushN   1.000000
         17  StepNumber
         18  JumpVarLPLENum       x  10.000000    29
         19     NewLine       4
         20     FuncExE
         21  PushPLocal       x      0
         22       PushV
         23       PushP   007D3670      0
         24       PushV
         25         SUM       0
         26       Print
         27     NewLine       5
         28   IncLPJump       x     18
         29  POPExitMark
         30     POPStep
         31     NewLine       6
         32   LoadFuncP    test
         33        Call       0
         34  NoOperation
         35     NewLine       8
         36       PushV
         37   FreeStack
         38  ReturnNull
         39        Func    test
         40     NewLine       9
         41     FuncExE
         42       PushC   welcome
         43       PushP   007D3670      0
         44       PushV
         45         SUM       0
         46       Print
         47     NewLine      10
         48  PushPLocal      o1      0
         49  AssignmentPointer
         50         New   point
         51    SetScope
         52       PushV
         53  BraceStart
         54       LoadA       x      0     58
         55  AssignmentPointer
         56       PushN   10.000000
         57  BeforeEqual       0
         58  SetProperty       0    106
         59   FreeStack
         60       LoadA       y      0     64
         61  AssignmentPointer
         62       PushN   20.000000
         63  BeforeEqual       0
         64  SetProperty       0    141
         65   FreeStack
         66       LoadA       z      0     70
         67  AssignmentPointer
         68       PushN   30.000000
         69  BeforeEqual       0
         70  SetProperty       0    176
         71   FreeStack
         72    LoadFunc   ismethod
         73       LoadA    self      0
         74       PushV
         75       PushC   braceend
         76        Call
         77  NoOperation
         78       PushV
         79       JumpZ      85
         80    LoadFunc   braceend
         81        Call
         82  NoOperation
         83       PushV
         84   FreeStack
         85    BraceEnd
         86   FreeStack
         87     NewLine      11
         88     FuncExE
         89  PushPLocal      o1      0
         90       PushV
         91       Print
         92     NewLine      13
         93  ReturnNull
         94       Class   point  007D8470
         95    NewLabel
         96       LoadA       x      0
         97       PushV
         98   FreeStack
         99       LoadA       y      0
        100       PushV
        101   FreeStack
        102       LoadA       z      0
        103       PushV
        104   FreeStack
        105  ReturnNull
        106    LoadFunc   ismethod
        107       LoadA   ring_gettemp_var      0
        108       PushV
        109       PushC    setx
        110        Call       0
        111  NoOperation
        112       PushV
        113       JumpZ     132
        114     NewLine       2
        115       LoadA   ring_gettemp_var      0
        116  LoadMethod    setx
        117       LoadA   ring_settemp_var      0
        118       PushV
        119        Call       0      1
        120  AfterCallMethod
        121       PushV
        122   FreeStack
        123     NewLine       3
        124       LoadA   ring_tempflag_var      0    128
        125  AssignmentPointer
        126       PushN   0.000000
        127  BeforeEqual       0
        128  Assignment       0      0
        129   FreeStack
        130     NewLine       4
        131        Jump     140
        132     NewLine       5
        133       PushP   007D37D8      0    137
        134  AssignmentPointer
        135       PushN   1.000000
        136  BeforeEqual       0
        137  Assignment       0      0
        138   FreeStack
        139     NewLine       6
        140      Return
        141    LoadFunc   ismethod
        142       LoadA   ring_gettemp_var      0
        143       PushV
        144       PushC    sety
        145        Call       0
        146  NoOperation
        147       PushV
        148       JumpZ     167
        149     NewLine       2
        150       LoadA   ring_gettemp_var      0
        151  LoadMethod    sety
        152       LoadA   ring_settemp_var      0
        153       PushV
        154        Call       0      1
        155  AfterCallMethod
        156       PushV
        157   FreeStack
        158     NewLine       3
        159       LoadA   ring_tempflag_var      0    163
        160  AssignmentPointer
        161       PushN   0.000000
        162  BeforeEqual       0
        163  Assignment       0      0
        164   FreeStack
        165     NewLine       4
        166        Jump     175
        167     NewLine       5
        168       PushP   007D37D8      0    172
        169  AssignmentPointer
        170       PushN   1.000000
        171  BeforeEqual       0
        172  Assignment       0      0
        173   FreeStack
        174     NewLine       6
        175      Return
        176    LoadFunc   ismethod
        177       LoadA   ring_gettemp_var      0
        178       PushV
        179       PushC    setz
        180        Call       0
        181  NoOperation
        182       PushV
        183       JumpZ     202
        184     NewLine       2
        185       LoadA   ring_gettemp_var      0
        186  LoadMethod    setz
        187       LoadA   ring_settemp_var      0
        188       PushV
        189        Call       0      1
        190  AfterCallMethod
        191       PushV
        192   FreeStack
        193     NewLine       3
        194       LoadA   ring_tempflag_var      0    198
        195  AssignmentPointer
        196       PushN   0.000000
        197  BeforeEqual       0
        198  Assignment       0      0
        199   FreeStack
        200     NewLine       4
        201        Jump     210
        202     NewLine       5
        203       PushP   007D37D8      0    207
        204  AssignmentPointer
        205       PushN   1.000000
        206  BeforeEqual       0
        207  Assignment       0      0
        208   FreeStack
        209     NewLine       6
        210      Return

===================================================

CGI Support

Command:

ring test.ring -cgi

No Run

Command:

ring test.ring -norun

Printing Instruction Operation Code

Command:

ring test.ring -ins

Output:

===================================================

Operation  : ReturnNull
PC         : 1
Line Number    : 1  , File test.ring

SP (After) : 0  - FuncSP : 0
 LineNumber 1
===================================================
.....
.....
.....

Tip

Output removed from the previous example because it’s very large!

Performance

Command:

ring test.ring -performance

Output:

===================================================
Date  : 2015/09/15 Time : 15:56:17
Clock : 0
===================================================
Hello World
1
2
3
4
5
6
7
8
9
10
welcome
x: 10.000000
y: 20.000000
z: 30.000000

===================================================
Date  : 2015/09/15 Time : 15:56:17
Clock : 0
===================================================

Generate Object File

You can generate object file (.ringo) from your source code file (.ring) using -go option

Tip

You will get one object file to use for distributing/running your application which may contains one or many ring source files that you can keep or distribute based on the application (commercial or open source).

Command:

ring test.ring -go

To run the compiled object file

ring test.ringo