<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matthew Chrobak</title>
    <description>The latest articles on DEV Community by Matthew Chrobak (@matthewchrobak).</description>
    <link>https://dev.to/matthewchrobak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F391417%2F7b4eaf57-a66a-4205-8877-c66e85552661.jpeg</url>
      <title>DEV Community: Matthew Chrobak</title>
      <link>https://dev.to/matthewchrobak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matthewchrobak"/>
    <language>en</language>
    <item>
      <title>Generic Compiler Toolchain</title>
      <dc:creator>Matthew Chrobak</dc:creator>
      <pubDate>Thu, 21 May 2020 01:48:39 +0000</pubDate>
      <link>https://dev.to/matthewchrobak/generic-compiler-toolchain-4ej7</link>
      <guid>https://dev.to/matthewchrobak/generic-compiler-toolchain-4ej7</guid>
      <description>&lt;h4&gt;
  
  
  Background
&lt;/h4&gt;

&lt;p&gt;I've always loved learning about Computer Science and using what I've learned to develop tools that enabled people's creativity. &lt;/p&gt;

&lt;p&gt;I took a university class on compilers in 2018 and loved every grueling minute of it. Upon finishing the course, I realized that the peak of creative tooling and Computer Science is compiler and language design. &lt;/p&gt;

&lt;p&gt;So, in the summer of 2019, I started to outline a project to go beyond what was taught in my compilers class; to develop tools for building compilers.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Motivation
&lt;/h2&gt;

&lt;p&gt;Writing a compiler can be taxing, and intimidating. The goal was to create an ecosystem that not only simplifies and accelerates compiler development, but lowers its barrier to entry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compilation by Configuration
&lt;/h2&gt;

&lt;p&gt;GCT (Generic Compiler Toolchain) is a generalized system. A program is compiled is by feeding in language specification files along with the source program. Language specification files are simple, compact, and are written as plaintext. No fancy tools are needed to create or modify a language's specification - any text editor will do.&lt;/p&gt;

&lt;p&gt;GCT uses the language specification files to generate a tokenizer and parser. Python plugin scripts are used as AST visitors to construct semantics, and output code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tbihsrdg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iktq1a9pz9pxk7rxzpu6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tbihsrdg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iktq1a9pz9pxk7rxzpu6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upon completing compilation, an HTML report is generated containing content collected during the compilation process. This report contains anything from tabular data, to fully-interactive models of the tokenizer or AST.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z6QXvpNW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i2qmy0bn5p11mkjk9m43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6QXvpNW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i2qmy0bn5p11mkjk9m43.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Showcase Language
&lt;/h2&gt;

&lt;p&gt;To demonstrate the capabilities of GCT, I developed a set of configuration files and plugins that can compile a simple high-level programming language to an executable file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;Fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="n"&gt;Fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;print_int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I've always been interested in exploring LLVM IR and figured this would be a great opportunity by using it in the back-end of the compiler.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;The full source code and implementation of the showcase language is available on the Github page.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vWogaON8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-28d89282e0daa1e2496205e2f218a44c755b0dd6536bbadf5ed5a44a7ca54716.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/MatthewChrobak"&gt;
        MatthewChrobak
      &lt;/a&gt; / &lt;a href="https://github.com/MatthewChrobak/GC-Toolchain"&gt;
        GC-Toolchain
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Generic Compiler Toolchain
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Generic Compiler Toolchain&lt;/h1&gt;
&lt;p&gt;GC-Toolchain is a compiler development toolchain that is responsible for front-end validation and analysis, and offers a framework for back-end code-generation. A comprehensive compilation report can be generated on each run to give detailed information of the mechanisms involved in the compilation process.&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://camo.githubusercontent.com/2f13886b2dcca9de6924ca3a72862ea28f4f6cef/68747470733a2f2f692e696d6775722e636f6d2f6c776a4c64486e2e706e67"&gt;&lt;img src="https://camo.githubusercontent.com/2f13886b2dcca9de6924ca3a72862ea28f4f6cef/68747470733a2f2f692e696d6775722e636f6d2f6c776a4c64486e2e706e67" alt="img"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
Building and Using GCT&lt;/h2&gt;
&lt;p&gt;Please visit the Wiki for build and usage instructions.&lt;/p&gt;
&lt;h2&gt;
Lexical Analysis&lt;/h2&gt;
&lt;h3&gt;
Configuration Files&lt;/h3&gt;
&lt;p&gt;Token specification is given through a configuration file. The configuration file is made up of sections, which begin with the section declaration line. The section declaration line begins with the &lt;code&gt;#&lt;/code&gt; symbol, followed by an identifier right next to the section symbol &lt;code&gt;#type&lt;/code&gt;. Some section types require additional information which are usually contained in the remaining trailing whitespace-separated identifiers in the declaration line, or in the section body which are the lines trailing the section declaration line.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#type identifiers
body-line-1
body-line-2
body-line-3
body-line-N
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For lexical…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/MatthewChrobak/GC-Toolchain"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  The Internals
&lt;/h2&gt;

&lt;p&gt;For more information on how GCT handles each phase of compilation, you can take a look at the documentation pages here:&lt;br&gt;
&lt;a href="https://github.com/MatthewChrobak/GC-Toolchain/wiki/Lexical-Analysis"&gt;Lexical Analysis&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/MatthewChrobak/GC-Toolchain/wiki/Syntactic-Analysis"&gt;Syntactic Analysis&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/MatthewChrobak/GC-Toolchain/wiki/Semantic-Analysis---Code-Generation"&gt;Semantic Analysis and Code Generation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For general usage information, you can reference &lt;a href="https://github.com/MatthewChrobak/GC-Toolchain/wiki/Building-and-Using-GCT"&gt;this page&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>compiler</category>
      <category>llvm</category>
    </item>
  </channel>
</rss>
