Skip to content

swayam0322/simplelang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simplelang

Simple compiler

Grammar:

Program := Statement*

Statement := Declaration
           | Assignment
           | Conditional

Declaration := TOK_INT TOK_IDENTIFIER TOK_SEMICOLON

Assignment := TOK_IDENTIFIER TOK_ASSIGN Expression TOK_SEMICOLON

Expression := Term (+|-) Term | Term

Conditional := TOK_IF TOK_LEFT_PAREN Condition TOK_RIGHT_PAREN Block

Condition := Term (=|!) Term

Term := TOK_IDENTIIFIER | TERM_NUMBER

Block := TOK_LEFT_BRACE Statement* TOK_RIGHT_BRACE

Sample program:

var a;
var b; 
var c; 

a : 10; 
b : 20; 
c : a + b; 

if (c = 30) {  
 c : c + 1; 
 a : a - 2;
 if(c ! 20) {
   a : a + 10;
 }
}

References:

https://craftinginterpreters.com/scanning.html https://lesleylai.info/en/ast-in-cpp-part-1-variant/ https://en.wikipedia.org/wiki/Abstract_syntax_tree https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl02.html

https://youtu.be/pupdmHjzrTI?feature=shared

About

Simple compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published