Members
To have a higher learning curve and to decrease dependency on external tools, this is language is completely developed from scratch using only C++.
- Lexer: This takes in the program as input and creates tokens out of the program.
- This analyzes the input program to create tokens.
- Parser: Tokens from the Lexer is fed as input to Parser which generates Parse Tree and Symbol table. 1. This is a recursive descent parser with look ahead. 2. This part takes care of semantic analysis and generating the parse tree. 3. This generates symbol table which is a doubly linked N-ary tree structure. 4. This throws an error if the given program has syntax errors.
- Intermediate Code: This generates the bytecode based on the parse tree in which is in agreement with the runtime.
- This part recursively walks through the tree and generates the byte code using the opcodes.
- Runtime Environment: This takes the bytecode and does the execution of the program written. This gives out the output after completing the execution.
- Stack Model is used for execution.
- Bytecode is traversed and executed with the stack holding current values.
program ::= (stmt)+
letter ::= [a-zA-Z]
digit ::= [0-9]
identifier ::= (letter|"_") (letter | digit | "_")*
funcname ::= identifier
integer ::= "-"?digit(digit)*
stmt ::= assignment_stmt NEWLINE
| print_stmt NEWLINE
| return_stmt NEWLINE
| break_stmt NEWLINE
| continue_stmt NEWLINE
| exec_stmt NEWLINE
| if_stmt
| while_stmt
| func_def
block ::= NEWLINE INDENT (stmt )+ DEDENT
if_stmt ::= "if" expression block
( "elif" expression block )*
("else" block)?
while_stmt ::= "while" expression block
funcdef ::= "function" funcname "(" parameters ")" block
parameters ::= identifier (',' identifier)*
print ::= “print” expression
assignment_stmt ::= identifier "=" expression
return ::= “return” expression
break ::= “break”
continue ::= “continue”
arguments ::= expression (‘,’expression)*
exec_stmt ::= funcname "(" arguments ")"
expression ::= or_expr
or_expr ::= and_expr | and_expr "or" or_expr
and_expr ::= not_expr | not_expr "and" and_expr
not_expr ::= comp_expr | "not" not_expr
comp_expr ::= a_expr | a_expr comp_opr comp_expr
a_expr ::= m_expr | m_expr "+" a_expr | m_expr "-" a_expr
m_expr ::= unit| unit "*" m_expr | unit "/" m_expr | unit "%" m_expr
unit ::= integer | identifier | “(” expression“)” | exec_stmt
comp_opr ::=
"<" | ">" | "==" | ">=" | "<=" | "<>"
YouTube Video Link : https://youtu.be/xsFWnLc8laA
This video talks gives an overview about the development and abilities of this programming language.
Platform Windows(Mingw required) Mac OS (cmake required) Linux (cmake required)
Cmake : CMake is an open-source, cross-platform family of tools designed to build, test and package software.
~$ git clone https://github.com/ej-z/SER502-Spring2018-Team15.git
~$ cd SER502-Spring2018-Team15; mkdir bin; cd bin;
~$ cmake ../
~$ make
~$ ./melloc "../data/<input source code file.mlw>"
~$ ./mello "../data/<input bytecode file.o>"
a = 5
i = 1
if (a%2 == 0)
print (a)
else
while (i<a)
print(i)
i = i+1
0 PUSH 5
2 STORE #0
4 PUSH 1
6 STORE #1
8 PUSH 0
10 PUSH 2
12 LOAD #0
14 MOD
15 EQ
16 BRF $22
18 LOAD #0
20 PRINT
21 BR $40
23 PUSH 10
25 LOAD #1
27 LT
28 BRF $40
30 LOAD #1
32 PRINT
33 PUSH 1
35 LOAD #1
37 ADD
38 STORE #1
40 EXIT
1
2
3
4
Boolean
Int
-
a = 10
-
- "+", "-", "*", "/", "%" - modulo
b = 4 + 8
-
- or
- and
- not
-
- "<", "<=", ">", ">=", "==", "<>"
-
- Global variables
- Local variables
-
print 100
-
continue
-
Example 1:
return 10
Example 2:
return a
-
break
-
- if-elif-else
if ( a % 5 == 0 )
print 5
elif ( a % 2 == 0 )
print 2
else
print 0
-
- while
a = 10
while(a > 0)
print a
a = a - 1
-
- Simple function execution
- Function execution with return values
- Recursion
- Operations on return values
function mangle(n)
d = 5
if 2 < 3
n = 2 * 3 + 5 - 8 / 2
else
g = 4
return n
Recursion Example:
function fib(n)
if n <= 1
return n
return fib(n - 1) + fib(n - 2)
ans = fib(7)
print ans
-
- Handling block scopes, with different symbol table for each scope.
- Handling scopes inside a functions.
- Handling scopes inside conditional and Loop Statements.
Implemented the following extra features:
- Functions - Recursion, Nested
- Variable Scope
- Recursive Descent Parser from scratch
- Lexer from Scratch
- Symbol Table Implementation to manage scope
- Nested Conditions
- Print statement
- Return Statement
- Break Statement
- Continue Statement