How I built a simple compiler — Markdown to HTML

Image for post
Image for post

An inspiration

How?

Image for post
Image for post
https://gist.github.com/jozefchmelar/ee42ea031d9b04edeb039ecee200d997#file-nonterminaldef-cs

Grammar

Image for post
Image for post
https://gist.github.com/jozefchmelar/8c638b52517363e6093f35ab3d5eca46
Image for post
Image for post
It’s not THAT complicated.
Image for post
Image for post
https://gist.github.com/jozefchmelar/f0c184066ab4824bb6b821a8e974c6cd
Image for post
Image for post

From Abstract Syntax Tree to HTML

Accurate description of visitor pattern
Image for post
Image for post
https://gist.github.com/jozefchmelar/2e3b70a0e84d1fa4fc938556a7743491
Image for post
Image for post
Image for post
Image for post
https://gist.github.com/jozefchmelar/a9f907207ed43043d478ce7dccba6e66
Image for post
Image for post
https://gist.github.com/jozefchmelar/59677f63ae6cec240fbd9c95bac243ab

Voilà!

#"H1 Heading"
#_"H1 undescore heading"_
##"H2 Heading"
*"This is bold text"* "and this is regular text"
"Following three items should be in a list, this is plaintext"
- "Plaintext list item"
- *"Bold List item"*
- _*"Underscore bold list item"*_
- _"Underscore list item"_
#"This is heading again"
<div>
<h1>H1 Heading</h1>
<h1>
<u>H1 undescore heading</u>
</h1>
<h2>H2 Heading</h2>
<b>This is bold text</b>
<p>and this is regular text</p>
<p>Following three items should be in a list, this is plaintext</p>
<ul>
<li>Plaintext list item</li>
<li>
<b>Bold List item</b>
</li>
<li>
<u>
<b>Underscore bold list item</b>
</u>
</li>
<li>
<u>Underscore list item</u>
</li>
</ul>
<h1>This is heading again</h1>
</div>

Conclusion

Image for post
Image for post
I’m just ❤️really curious

Written by

silly person.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store