Simple programming language implemented (handmade :p) in C++
This language is open to extensions and adding more features. The goal is to make a dead-simple programming language comprehensible for those new to programming.
To run the language
- Go to the same directory as main.cpp
g++ -std=c++11 main.cpp -o exe.out && ./exe.out 'example_programs/filename.cui'
Or
- Go to the same directory as main.cpp
./cui.sh 'example_programs/filename.cui'
Features
- Variable declarations
- Conditional statements (if-else)
- Loops (while)
- Data types: strings and floats
- Prompt input directly from user interactively
- Global State
Other
- Recursive Descent Parsing Algorithm
- Context Free Grammar translation scheme in
Parser.py
- Reads the input file char by char and forms the tokens
- Reads the input file char by char and forms the tokens
- Gets the tokens generated from the Scanner, and forms the Syntax Tree
- Semantic checks are done after successful Parsing.
- Excetuion of he statements and expressions is made while Syntax Tree traversal.
STATEMENT -> EXPRESSION_STATEMENT
| IF_STATEMENT
| WHILE_STATEMENT
| PRINT_STATEMENT
| INITIALIZATION_STATEMENT
EXPRESSION_STATEMENT -> IDENTIFIER "=" TERM;
IF_STATEMENT -> "if" (TERM) "ifbody" STATEMENT_LIST "else" "do" TERM "endif" ;
| "if" (TERM) "ifbody" STATEMENT_LIST "endif" ;
WHILE_STATEMENT -> "while" (TERM) "whilebody" STATEMENT_LIST "endwhile" ;
PRINT_STATEMENT -> "print(TERM)" ;
INITIALIZATION_STATEMENT -> "create" IDENTIFIER "=" TERM ;
TERM -> FACTOR ( ( "+" | "-" ) FACTOR )* ;
FACTOR -> UNARY ( ( "" | "/" | "%" ) UNARY ) ;
UNARY -> ( "not" | "-" ) LITERAL ;
LITERAL -> NUMBER | STRING ;
VALID_CHAR -> "a" ... "z" | "A" ... "Z" | "_" ;
DIGIT -> "0" ... "9" ;
NUMBER -> DIGIT + ( "." (DIGIT)+ )? ;
STRING -> """ """ // Any chars except '' surroundedby ";
IDENTIFIER -> VALID_CHAR | (VALID_CHAR | DIGIT) * ;