Project Fox: A Statically Typed Embeddable Programming Language Overview
Project Fox is a captivating journey into the development of a statically typed, embeddable programming language. Explore how the compiler and interpreters work, from source code to tokens and Abstract Syntax Trees, culminating in code generation. Dive into the nuances of semantic analysis and learn about interoperability with C++. Discover the potential for Fox to be embedded in various applications.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Project Fox A Quest for a Statically Typed Embeddable Programming Language Pierre van Houtryve
Introduction: The Rabbit Hole (Illustration Source: https://bit.ly/2HzuZ2U )
Fox Learning Project Statically Typed End goal: Embeddability in other Applications Fox should be interoperable with C++ (Not an official logo, just an illustration . Source: https://bit.ly/2JBhpyr )
How its Made: Compiler and Interpreters (LLVM Logo)
func foo(y: int) { let x: int = 3; } The Lexer Converts the source code into tokens Source Kind Location func FuncKw 1:1-1-4 foo Identifier 1:6-1:8 ( LParen 1:9-1:9 y Identifier 1:10-1:10 : Colon 1:11-1:11 int IntKw 1:13-1:15 ) RParen 1:16-1:16 { LBrace 1:18-1:18 let LetKw 2:3-2:5
Source Kind Location func FuncKw 1:1-1-4 foo Identifier 1:6-1:8 ( LParen 1:9-1:9 y Identifier 1:10-1:10 : Colon 1:11-1:11 int IntKw 1:13-1:15 ) RParen 1:16-1:16 { LBrace 1:18-1:18 The Parser Consumes the tokens and produces the Abstract Syntax Tree (AST) let LetKw 2:3-2:5 FuncDecl Identifier: foo ParamDecl CompoundStmt Identifier: y Size: 1 VarDecl Type: int Identifier: x IntegerLiteralExpr Value : 3
FuncDecl Identifier: foo Semantic Analysis Checks the language s semantics Optional, mostly done in statically typed languages Analyzes the AST, searching for errors, inconsistencies, etc. ParamDecl CompoundStmt Identifier: y Size: 1 VarDecl Type: int Identifier: x IntegerLiteralExpr Value : 3
FuncDecl Identifier: foo ParamDecl CompoundStmt Identifier: y Size: 1 VarDecl Type: int Identifier: x Code Generation Generates something from the AST IntegerLiteralExpr Value : 3 Another existing programming language E.g. TypeScript (JavaScript) An Intermediate Representation E.g. Clang (LLVM IR), Swift (SIL) Bytecode for a Virtual Machine E.g. Java (JVM BC), Fox (Fox VM BC) Machine Code
FuncDecl Identifier: foo The AST Usually the first representation of the code built by the compiler/interpreter A basic version is trivial to write, but it can get really complicated really fast as new language features are added. ParamDecl CompoundStmt Identifier: y Size: 1 VarDecl Type: int Identifier: x IntegerLiteralExpr Value : 3 How do you write one? Trial and Error of course!
Trial and Error Everywhere! Not the fastest way of doing things, but you learn a lot!
Conclusion Progress on Fox is slow, but I enjoy the journey because I learn a lot! Fox: A statically typed interpreted programming language Learning Project Relatively limited feature set, not really usable in its current state GitHub: https://github.com/Pierre-vh/Fox