LensC Appendix

Quick Links



Opcodes

These are the opcodes the internal lensc processor uses. The debugger shows the current instruction name, and data.

Opcode Definition Param 1 Param 2 Type
START This mostly adds stack space for the globals. The first instruction number is no longer used. Instruction number of program start Number of globals, including the 2 implied Data type of caller
END This signifies the end of the program. Unused Unused Unused
PROC The beginning of a new function. This sets up the stack with return values and a new frame. Compiler Use The number of parameters to this function. The data type returned by the function.
PROCEND The end of a function. Returns to the line the function was called from. Unused Unused Unused
POP Remove the top value from the stack. Unused Unused Unused
POPJMPF Pops the top value from the stack, and, if 0, jumps. Instruction number to jump to Unused Unused
JMP Sets instruction pointer to new instruction location. Instruction number to jump to Unused Unused
JPNE Pops the top of the stack and compares it to the new top. If equal, pops the new top too, otherwise jumps to next code location. Instruction number to jump to Unused Unused
NEG Negates the value on the top of the stack Unused Unused Unused
NOT If the top of the stack is non-zero, sets it to zero, otherwise sets it to 1. Unused Unused Unused
LOADAD Loads the address on the stack of the variable specified by the given scope and offset ScopeNumber Offset within scope Unused
CALL Add a new scope, set IP to function address Address of function Number of parameters Unused
CALLPRE Run a native server function Index of function Number of parameters Unused
VALUE Replace an address with the value at that address. Unused Unused Unused
CONST Load a constant value. Unused Value, or offset in code for a string reference Type of value
SQR Pop two values from the stack, raise the second to the first power, and push the result. Unused Unused Unused
MUL Pop two values from the stack, multiply them and push the result. Unused Unused Unused
DIV Pop two values from the stack, divide the second by the first and push the result. Unused Unused Unused
MOD Pop two values from the stack, divide the second by the first and push the remainder. Unused Unused Unused
ADD Pop two values from the stack, add them, and push the result. When adding to a stack index for arrays, the maximum number of elements in the array. Unused Unused
SUB Pop two values from the stack, subtract the second from the first and push the remainder. Unused Unused Unused
EQ Pop two values and compare. Push 1 if equal otherwise push 0. Unused Unused Unused
LEQ Pop two values and compare. Push 1 if second is less than or equal to the first otherwise push 0. Unused Unused Unused
GEQ Pop two values and compare. Push 1 if second is greater than or equal to the first otherwise push 0. Unused Unused Unused
GTH Pop two values and compare. Push 1 if second is greater than the first otherwise push 0. Unused Unused Unused
LTH Pop two values and compare. Push 1 if second is less than the first otherwise push 0. Unused Unused Unused
NEQ Pop two values and compare. Push 1 if not equal otherwise push 0. Unused Unused Unused
JMP_F_OR_POP Check top stack value. If 0, jump to new code location, otherwise pop the value. Location to jump to. Unused Unused
JMP_T_OR_POP Check top stack value. If non-zero, jump to new code location, otherwise pop the value. Location to jump to Unused Unused
BLK Creates a new frame on the stack, allocating space for local variables. Number local variables Frame Number Unused
BLKEND Return to previous frame Frame Number Unused Unused
INC Increments the variable at location specified by top of stack by amount specified. Amount to increment/decrement 1 if replace address with value before incrememnting, 0 if just increment variable. Unused
ASSIGN Pops the value from the top of the stack and copies that value into the location specified on the new top of the stack, then replacing the top of the stack with the value. Unused Unused Unused
ADDVAL Takes the value at the address on the stack, and adds it to the top of the stack, without removing the address. Unused Unused Unused
INVALIDATE Takes the handle at the address on the stack, and invalidates it, to prevent program termination when handles are rebuilt. Unused Unused Unused
INSTR Waits for input from a subsequent action. Unused Unused String
Top LensC

BNF

This is the BNF for the lensc language. Keywords and symbols are bold, types of characters are in italics. Non-final symbols are CAPS. No identifiers or keywords are case sensitive.

  • COMMENT ==> /*Anything typed.*/
  • ID ==> letter [{letter|number|_}]*
  • NUMBER ==> number [number]*
  • STRING ==> "Anything typed."
  • TYPE ==> {int | string | bool | char | obj | room | exit | area | vehicle }
  • START ==> program ID (TYPE) [{VARDECL | FDECL}]* MAIN
  • MAIN ==> main() BLOCK
  • FDECL ==> function [TYPE] ID ( [TYPE ID[, TYPE ID]* ]) BLOCK
  • VARDECL ==> TYPE ID [= EXPR] [, ID [= EXPR]]* ;
  • BLOCK ==> { [STATEMENT]* }
  • STATEMENT ==> {
    • BLOCK
    • VARDECL; |
    • EXPR; |
    • if (EXPR) STATEMENT [else STATEMENT] |
    • do STATEMENT while (EXPR); |
    • while (EXPR) STATEMENT |
    • for ([EXPR];[EXPR];[EXPR]) STATEMENT |
    • break; |
    • continue; |
    • switch (EXPR) SWITCHBLOCK |
    • end; |
    • return [EXPR];
    • invalidate EXPR;
    }
  • SWITCHBLOCK ==> { [
    • STATEMENT |
    • default: |
    • case EXPR:
    ]* }
  • EXPR ==> {
    • VARIABLE ASSIGN |
    • COND
    }
  • VARIABLE ==> ID[[EXPR]] [.ID]
  • ASSIGN ==> {=|*=|/=|%=|+=|-=|^=} EXPR
  • COND ==> DISJ [? EXPR : EXPR]
  • DISJ ==> CONJ [|| DISJ]
  • CONJ ==> NEGATION [&& CONJ]
  • NEGATION ==> [!] RELATION
  • RELATION ==> SUM [ {== | != | > | < | >= | <= | !> | !< } RELATION ]
  • SUM ==> [{ + | - }] TERM [{+ | -} [{+ | - }] TERM ]*
  • TERM ==> FACTOR [{* | / | % } FACTOR]*
  • FACTOR ==> PRIMARY [^ PRIMARY]*
  • PRIMARY ==> {
    • ( EXPR ) |
    • STRING |
    • NUMBER |
    • instring(NUMBER) |
    • [{++ | --}]VARIABLE [{++ | --}] |
    • ID ( [ EXPR [ ,EXPR ]* ] )
    }

Top LensC