Developing an Interpreter Using GO and C# with Roslyn SDK
Exploring the process of creating an interpreter in GO and C# with the help of the Roslyn SDK, focusing on templates, syntax visualization, building a simple interpreter, and implementing code fixes and analyzers. The journey covers essential aspects such as the Roslyn SDK, template utilization, and enhancing code quality through fixes and analyzers.
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
Writing an Interpreter in GO C# Tim Boyle .Net Oxford 14thMay 2019 interpreterbook.com
Roslyn API Template Syntax Visualizer Simple Interpreter Code Fixes Overview
Syntax Visualizer
Interpreter Abstract Syntax Tree (AST) Source Code Tokens Evaluation Lexical Analysis Parsing
Chop up text into pieces which are more meaningful to the parser These pieces are called tokens Lexical Analysis
Lexing let answer = 40 + 2;
Lexing let answer = 40 + 2;
Lexing let answer = 40 + 2;
Lexing LET let answer = 40 + 2;
Lexing LET let answer = 40 + 2;
Lexing LET let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF let answer = 40 + 2;
Lexing LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF let answer = 40 + 2;
Parser takes input data and builds a data structure giving a structural representation of the input, checking for correct syntax in the process. Parsing Wikipedia
Parsing let answer = 40 + 2;
Parsing let answer = 40 + 2; LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value Identifier Value
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value Identifier Value : "answer"
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value Identifier Value : "answer"
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value Identifier Value : "answer" IntegerLiteral Value: 40
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value InfixExpression LHS RHS Identifier Value : "answer" IntegerLiteral Value: 40
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value InfixExpression LHS RHS Identifier Value : "answer" IntegerLiteral Value: 40
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value InfixExpression LHS RHS Identifier Value : "answer" IntegerLiteral IntegerLiteral Value: 40 Value: 2
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value InfixExpression LHS RHS Identifier Value : "answer" IntegerLiteral IntegerLiteral Value: 40 Value: 2
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value InfixExpression LHS RHS Identifier Value : "answer" IntegerLiteral IntegerLiteral Value: 40 Value: 2
Parsing let answer = 40 + 2; Program Statements[] LET IDENTIFIER("answer") EQUAL_SIGN INTEGER(40) PLUS_SIGN INTEGER(2) SEMICOLON EOF LetStatement Name Value InfixExpression LHS RHS Identifier Value : "answer" IntegerLiteral IntegerLiteral Value: 40 Value: 2