eelco-visser-compiler-const.../lab/1b.html

975 lines
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="Eelco Visser">
<meta name="generator" content="Jekyll v3.8.5">
<title>Lab 1(b): Creating Syntax Tests</title>
<!-- <base href="/2021"> -->
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
<!-- Bootstrap core CSS -->
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<!-- Custom styles for this template -->
<link href="../css/main.css" rel="stylesheet">
<link href="../css/borders-responsive.css" rel="stylesheet">
<link rel="stylesheet" href="../css/pl.css">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="../index.html">
TU Delft | CS4200
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
<a href="https://tudelft-cs4200.github.io/2021">
<img class="border border-dark" width="100%" src="../project/2021/00-lab1b/spt.png"/>
</a>
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
<div class="text-dark font-weight-bold">
<h1>
Lab 1(b): Creating Syntax Tests
</h1>
</div>
<div>
</div>
<div>
Project
</div>
<div>
September 07, 2021
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
<p>Before getting started with your syntax definition, you set up a test suite for syntax analysis.
Develop the test suite in tandem with the development of your syntax definition.
The test suite consists of positive and negative test cases.
We will <em>not</em> grade this test suite, but you should develop one to get confidence in the quality of your syntax definition.
When you are asking for help from the course staff, we will first ask what tests you have written to demonstrate the problem.</p>
<h3 id="objectives">Objectives</h3>
<p>Develop a test suite for syntax analysis.
The test suite should provide</p>
<ol>
<li>Syntactically valid and invalid test cases for the <code class="language-plaintext highlighter-rouge">Start</code> sort</li>
<li>Disambiguation tests for associativity and precedence in expressions.</li>
<li>Test cases for layout-sensitive language constructs</li>
<li>Test cases for mandatory and optional whitespace.</li>
</ol>
<h3 id="anatomy-of-a-test-suite">Anatomy of a Test Suite</h3>
<p>In Spoofax, a test suite consists of one or more <code class="language-plaintext highlighter-rouge">.spt</code> files.
Consider the following example file:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module example
test FUN composite [[func(1+1, 3*2)]] parse succeeds
test FUN only comma [[func(,)]] parse fails
</code></pre></div></div>
<p>The first line specifies the name of the test <code class="language-plaintext highlighter-rouge">module</code>,
In this <code class="language-plaintext highlighter-rouge">example</code> module, we test syntax of the <code class="language-plaintext highlighter-rouge">ChocoPy</code> language.</p>
<p>The last two lines specify a positive and a negative test case.
Each test case consists of
a name,
a code fragment in double square brackets, and
a condition which determines
what kind of test should be performed (parsing) and
what the expected outcome is (success or failure).</p>
<p>You get instant feedback while editing a test suite.
Since you have not yet implemented the ChocoPy editor, all your positive test cases fail.
You will work on this during the next lab.
To read more on SPT, visit the documentation.</p>
<h4 id="chocopy-syntax-definition">ChocoPy Syntax Definition</h4>
<p>To write your own test cases, you need to understand ChocoPys syntax.
You can find the definitive ChocoPy syntax definition in the <a href="0b.html">Reference Manual</a>.</p>
<h3 id="test-cases">Test Cases</h3>
<p>You can now start writing your own test cases.</p>
<h4 id="lexical-and-context-free-syntax">Lexical and Context-free Syntax</h4>
<p>Start with the lexical syntax and think about valid and invalid identifiers.
Try to focus on corner cases such as</p>
<ul>
<li>identifiers made of a single character,</li>
<li>mixings of letters and digits (Which kinds of mixing are allowed? Which are not?),</li>
<li>underscores in identifiers.</li>
</ul>
<p class="notice notice-warning">The content for the tests for lexical symbols should not be surrounded by layout.</p>
<p>Next, you should walk through the whole syntax definition.
Keep thinking of valid and invalid code fragments.
Identify interesting corner cases and turn them into positive and negative test cases.</p>
<p>Try to keep your test cases small.
Each test case should focus on a single aspect.
For example, a negative test case should only contain one error.
The name of a test case should reflect the aspect it addresses.</p>
<p>You can organise test cases which focus on similar aspects in test modules.
Again, the name of a test module should reflect these aspects.
Finally, you can organise test suites in folders.</p>
<p class="notice notice-warning">When writing tests that target the differences between Python and ChocoPy, only consider the syntactic differences.
For example, identifiers in Python are limited to a certain size.
This <strong>should not</strong> be checked by your tests as this limitation is not specified in the context-free grammar of Python.</p>
<h4 id="disambiguation">Disambiguation</h4>
<p>Next, you need to focus on disambiguation.
Come up with positive test cases which specify the correct ASTs for nested expressions.
As an alternative, you can also specify two fragments in concrete syntax, which should result in the same AST:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>test left associative addition [[21 + 14 + 14]] parse to [[(21 + 14) + 14]]
</code></pre></div></div>
<p>You can find a table listing the associativity and priorities of operators in the reference manual.
Do not focus only on binary expressions.</p>
<p class="notice notice-warning">You <strong>do not</strong> have to test for constructs that are non-associative. In lab 2, <code class="language-plaintext highlighter-rouge">non-assoc</code> leads to semantic errors rather than syntactic errors during parse time. Since our language does not have analysis at that point, we cannot test the semantic errors and thus they are also not required for this lab.</p>
<h4 id="layout">Layout</h4>
<p>Finally, you can focus on layout.
Think about places where whitespace is not optional but mandatory and define corresponding positive and negative test cases.
Finish with test cases for single-line comments.
Single-line comments cannot only end with a newline character, but also at the end of file.</p>
<ul class="list-group list-group-flush pb-3">
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-primary pl-3">
<div>
<a name="KatsVV11"></a>
<a class="font-weight-bold text-dark" target="_blank" href="http://doi.acm.org/10.1145/2048066.2048080">Integrated language definition testing: enabling test-driven language development</a>
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="http://www.lclnet.nl/">Lennart C. L. Kats</a>, <a class="text-secondary" href="https://researchr.org/profile/robvermaas/publications">Rob Vermaas</a>, <a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
OOPSLA 2011
[<a href="../publications/2011/KatsVV11.pdf" class="text-secondary" target="_blank">pdf</a>, <a class="text-secondary" href="http://doi.acm.org/10.1145/2048066.2048080" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/KatsVV11/bibtex">bib</a>, <a href="https://researchr.org/publication/KatsVV11" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="1b.html#AbstractKatsVV11" role="button" aria-expanded="false" aria-controls="AbstractKatsVV11"">abstract</a>]
<!-- -->
</div>
<div class="collapse mt-1 mb-2" id="AbstractKatsVV11">
<div class="">
The reliability of compilers, interpreters, and development environments for programming languages is essential for effective software development and maintenance. They are often tested only as an afterthought. Languages with a smaller scope, such as domain-specific languages, often remain untested. General-purpose testing techniques and test case generation methods fall short in providing a low-threshold solution for test-driven language development. In this paper we introduce the notion of a language-parametric testing language (LPTL) that provides a reusable, generic basis for declaratively specifying language definition tests. We integrate the syntax, semantics, and editor services of a language under test into the LPTL for writing test inputs. This paper describes the design of an LPTL and the tool support provided for it, shows use cases using examples, and describes our implementation in the form of the Spoofax testing language.
</div>
</div>
</div>
</li>
</ul>
</div>
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
<div class="pb4 mb3 border-bottom border-grey ">
<nav>
<ul class="pagination justify-content-left">
<li class="page-item">
<a class="page-link" href="1a.html">
&laquo;
</a>
</li>
<li class="page-item">
<a class="page-link" href="../project/index.html">
^
</a>
</li>
<li class="page-item">
<a class="page-link" href="1c.html">&raquo;</a>
</li>
</ul>
</nav>
</div>
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#objectives">Objectives</a></li>
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#anatomy-of-a-test-suite">Anatomy of a Test Suite</a>
<ul class="toc-sub pl-0">
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#chocopy-syntax-definition">ChocoPy Syntax Definition</a></li>
</ul>
</li>
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#test-cases">Test Cases</a>
<ul class="toc-sub pl-0">
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#lexical-and-context-free-syntax">Lexical and Context-free Syntax</a></li>
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#disambiguation">Disambiguation</a></li>
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="1b.html#layout">Layout</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="border-top border-bottom border-grey mt-3 pt-3">
<nav>
<ul class="pagination justify-content-center">
<li class="page-item">
<a class="page-link" href="1a.html">
Previous
</a>
</li>
<li class="page-item">
<a class="page-link" href="1c.html">Next</a>
</li>
<li class="page-item">
<a class="page-link" href="../project/index.html">
Index
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>