Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To expand on Jan's answer, you would have a function like:</p> <pre><code>bool my_parser(const parser_options &amp;options); </code></pre> <p>The <code>parser_options</code> type can be a simple structure, e.g.:</p> <pre><code>struct parser_options { FILE *source_file; bool warnings_as_errors; std::shared_ptr&lt;error_handler&gt; eh; ... }; </code></pre> <p>The <code>error_handler</code> can be defined like this:</p> <pre><code>struct error_handler { virtual void error(int code, const char *message) = 0; virtual void warning(int code, const char *message) = 0; virtual ~error_handler() {} }; </code></pre> <p>The program would then do something like:</p> <pre><code>int main(int argc, const char *argv) { parser_options options; // process argc/argv options here, adding them to options, e.g.: // case WARN_AS_ERROR: options.warnings_as_errors = true; break; return my_parser(options, &amp;error) ? ERROR_SUCCESS : ERROR_FAILURE; } </code></pre> <p>This allows you to write tests that call <code>my_parser</code> directly, setting up <code>parser_options</code> independently of the command line handling and allows for a different <code>error_handler</code> to be specified (e.g. one that formats the information in a form that is machine readable).</p> <p>NOTE: This is not meant to be a perfect design of a parser, it is just an example of how something like this can be designed.</p> <p>NOTE: This design is not strictly necessary for testing, providing that the application can be configured to control the pipeline (e.g. no optimization, printing internal AST, internal representation, assembly code, preprocessor output). However, the design is more flexible as it allows different programs to use it without calling the command line program directly (GUI application/IDE, static analysis tools, etc.).</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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