This script generates test code for the COS 341 Project. Simply run the script, follow the prompts to build your tree, and the code will be generated. When asked for a rule number, input the corresponding number for each production rule listed below.
PROG ::= main GLOBVARS ALGO FUNCTIONS
GLOBVARS ::= // nullableGLOBVARS ::= VTYP VNAME , GLOBVARS // there can be as many global variables as we like
VTYP ::= numVTYP ::= text
VNAME ::= a token of Token-Class V from the Lexer
(See the Appendix below)
ALGO ::= begin INSTRUC end
INSTRUC ::= // nullableINSTRUC ::= COMMAND ; INSTRUC
COMMAND ::= skip // an empty algorithmic step where nothing happensCOMMAND ::= haltCOMMAND ::= print ATOMICCOMMAND ::= ASSIGNCOMMAND ::= CALL // call to a void-function that only updates global variablesCOMMAND ::= BRANCHCOMMAND ::= return ATOMIC
ATOMIC ::= VNAMEATOMIC ::= CONST
CONST ::= a token of Token-Class N from the LexerCONST ::= a token of Token-Class T from the Lexer
ASSIGN ::= VNAME < input // user input during run-timeASSIGN ::= VNAME = TERM // deep nesting of assignment terms is allowed
CALL ::= FNAME( ATOMIC , ATOMIC , ATOMIC ) // un-nested params only
BRANCH ::= if COND then ALGO else ALGO
TERM ::= ATOMICTERM ::= CALLTERM ::= OP
OP ::= UNOP( ARG )OP ::= BINOP( ARG , ARG )
ARG ::= ATOMICARG ::= OP // allows deep-nesting of operations
COND ::= SIMPLECOND ::= COMPOSIT
SIMPLE ::= BINOP( ATOMIC , ATOMIC )
COMPOSIT ::= BINOP( SIMPLE , SIMPLE )COMPOSIT ::= UNOP( SIMPLE )
UNOP ::= notUNOP ::= sqrt // square root of real numbers
BINOP ::= orBINOP ::= andBINOP ::= eqBINOP ::= grt // greater than >BINOP ::= addBINOP ::= subBINOP ::= mulBINOP ::= div
FNAME ::= a token of Token-Class F from the Lexer
FUNCTIONS ::= // nullableFUNCTIONS ::= DECL FUNCTIONS
DECL ::= HEADER BODY
HEADER ::= FTYP FNAME( VNAME , VNAME , VNAME ) // functions have 3 parameters
FTYP ::= numFTYP ::= void
BODY ::= PROLOG LOCVARS ALGO EPILOG SUBFUNCS end
PROLOG ::= { // the prolog
EPILOG ::= } // the epilog
LOCVARS ::= VTYP VNAME , VTYP VNAME , VTYP VNAME
SUBFUNCS ::= FUNCTIONS // functions can have sub-functions
- Token-Class V: Represents variable names, defined by the regular expression:
r'^V_[a-z]([a-z]|[0-9])*$' - Token-Class F: Represents function names, defined by the regular expression:
r'^F_[a-z]([a-z]|[0-9])*$' - Token-Class N: Represents numbers, defined by the regular expression:
r"^-?(0|[1-9][0-9]*)(\.[0-9]*[1-9])?$" - Token-Class T: Represents strings, defined by the regular expression:
r"^\"[A-Z][a-z]{0,7}\"$"