Skip to content

Farreeda/Compiler-with-Julia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler with Julia

Automata and compiler design using julia language. The language was designed to support basic programming constructs as variable declaration, assignment statements, conditional statements, and loops. Julia was chosen for its ease of use, flexibility, and compatibility with other programming languages.

Lexer.jl

Lexer identifies each word such as integer, floar, string, left curly bracket, keyword,...etc (for all token types documentation, check the attached report). The lexer then creates a list of tokens including their position and passes them to the parser.

Parser

We used ParserCombinator.jl and PEG.jl packages in the implementation of our parser. PEG.jl is easy in in creating rules for generating an Abstract Syntax Tree (AST) such as IF statements, for loops, while loop, Assignment stamtements ...etc. But we couldn't find a method to parse mathmetical equation. ParserCombinator.jl solved the mathmetical equations problem instantly! It is a package used in Haskel programming language. disclaimer: I couldn't create assignment statement with equation, I look for a way that links both packages together, ping me if you got an idea! (JuliaSlack: Fareeda Abdelazeez, Email: [email protected])

Semantic analyzer

when parser gives no errors, we identify scopes and monitor them to check the grammar of the code for example if a variable is being identified twice in one scope or a variable being called without being declared in its scope or parent scope or error as changing the type of variable as mentioned here: image Variables are stored in the Symbol table with their scopes to help the semantic analyzer do its job! image This example illustrates how scopes and symbol table work simultinously (but this is with disabling the parser for sure hahahahaha!) The Input: c {v {g} y }k {o} The outputs: it generated 4 scopes in the symbol table

  1. “g”
  2. “V ” & “y”
  3. “O”
  4. “C” & “K” in the global symbol table

Code generation

image

In this step we are sure about the validity of the given code, now we are in an early stage of translating the peice of code to the machine, we are generating quadruples (bytecode) image

About

Automata and compiler design using julia language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages