Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter solution than lex/yacc for parsing a DSL in C?
    primarykey
    data
    text
    <p>One of my programs accepts a commands (like <code>kill foo</code>) at runtime. Think of it as a little domain-specific language. Here are a few examples:</p> <pre><code>kill kill client exit </code></pre> <p>But also, chained commands are allowed and whitespace is not significant before and after commands, so the following examples are also valid:</p> <pre><code>kill ; say "that was fun" kill ; kill ; kill; </code></pre> <p>I have currently implemented this with lex/yacc (flex/bison to be specific) and that caused a lot of headache. The lexer very much depends on the context (for example whitespace tokens are generally not returned, unless after a <code>kill</code> keyword for example) and has many different states. The grammar used to have conflicts and I don’t really like the format in which it has to be specified (especially the $1, $2, $3, … to use arguments for non-terminals). Also, the error messages which bison provides (at parse-time) are sometimes accurate, but often not (the <code>kill</code> command with optional arguments leads to error messages like <code>Unexpected $undefined, expected $end or ;</code> for <code>kill clont</code> instead of <code>kill client</code>). Lastly, the C API for yacc is cruel (external defines all over the place).</p> <p>I am not asking you to solve all the aforementioned questions (I will open separate threads with more specific descriptions and code if there is no way around lex/yacc). Instead, I am interested in alternatives to lex/yacc.</p> <p>My criteria are the following:</p> <ul> <li>Input is a string (const char *), there is no output but instead some code should be called for each different keyword.</li> <li>I want to use this with C (C99).</li> <li>The software should be already included in the major linux distros or at least easy to bundle / package.</li> <li>It should be well-documented.</li> <li>The syntax for describing my language should be easy.</li> <li>It should output meaningful error messages upon parsing errors.</li> <li>Performance is not that important (of course it should be fast, but the typical use case is interactive usage, not processing tons of MB of commands).</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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