Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Syntax highlighters typically don't go beyond lexical analysis, which means you don't have to parse the whole language into statements and declarations and expressions and whatnot. You only have to write a lexer, which is fairly easy with regular expressions. I recommend you start by learning regular expressions, if you haven't already. It'll take all of 30 minutes.</p> <p>You may want to consider toying with Flex ( the lexical analyzer generator; <a href="https://github.com/westes/flex" rel="nofollow noreferrer">https://github.com/westes/flex</a> ) as a learning exercise. It should be quite easy to implement a basic syntax highlighter in Flex that outputs highlighted HTML or something.</p> <p>In short, you would give Flex a set of regular expressions and what to do with matching text, and the generator will greedily match against your expressions. You can make your lexer transition among exclusive states (e.g. in and out of string literals, comments, etc.) as shown in <a href="http://westes.github.io/flex/manual/How-can-I-match-C_002dstyle-comments_003f.html" rel="nofollow noreferrer">the flex FAQ</a>. Here's a canonical example of a lexer for C written in Flex: <a href="http://www.lysator.liu.se/c/ANSI-C-grammar-l.html" rel="nofollow noreferrer">http://www.lysator.liu.se/c/ANSI-C-grammar-l.html</a> .</p> <p>Making an extensible syntax highlighter would be the next part of your journey. Although I am by no means a fan of XML, take a look at how Kate syntax highlighting files are defined, such as <a href="http://constellationmedia.com/~funsite/static/cpp.xml.html" rel="nofollow noreferrer">this one for C++</a> . Your task would be to figure out how you want to define syntax highlighters, then make a program that uses those definitions to generate HTML or whatever you please.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload