download 2021 site
This commit is contained in:
commit
dd6e4afb13
138 changed files with 37730 additions and 0 deletions
485
lab/1c.html
Normal file
485
lab/1c.html
Normal file
|
|
@ -0,0 +1,485 @@
|
|||
<!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(c): Syntax Definition</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-lab1c/grammar.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(c): Syntax Definition
|
||||
|
||||
</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>In this lab, you define the concrete and abstract syntax of ChocoPy in Spoofax.
|
||||
From this definition, you generate an Eclipse editor, which provides syntax checking, error recovery, and syntax highlighting.</p>
|
||||
|
||||
<p>In this lab, focus on translating the grammar in Figure 3 of the ChocoPy Reference Manual to an <em>idiomatic</em> context-free syntax definition with constructors.
|
||||
In the <a href="2.html">next lab</a>, you extend this definition with <em>disambiguation rules</em> for associativity, priority, and layout constraints.</p>
|
||||
|
||||
<h3 id="objectives">Objectives</h3>
|
||||
|
||||
<p>Develop a syntax definition for ChocoPy in SDF3 and generate an Eclipse editor from it.
|
||||
The definition should include:</p>
|
||||
|
||||
<ol>
|
||||
<li>The start symbol <code class="language-plaintext highlighter-rouge">Start</code></li>
|
||||
<li>A lexical syntax definition for all ChocoPy lexemes</li>
|
||||
<li>A context-free syntax definition ChocoPy complying with the grammar in Figure 3 of the reference manual</li>
|
||||
<li>Constructor names for context-free syntax productions</li>
|
||||
</ol>
|
||||
|
||||
<h3 id="syntax-definition">Syntax Definition</h3>
|
||||
|
||||
<p>You should define your syntax in SDF3.
|
||||
You can start by opening the file <code class="language-plaintext highlighter-rouge">src/start.sdf3</code> in your chocopy project.
|
||||
You can also split your syntax definition over several modules in <code class="language-plaintext highlighter-rouge">src/</code> and import modules into module <code class="language-plaintext highlighter-rouge">start</code>.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module start
|
||||
imports lex
|
||||
imports expressions
|
||||
imports statements
|
||||
// etc.
|
||||
context-free start symbols Start
|
||||
</code></pre></div></div>
|
||||
|
||||
<!-- The module already imports a module `Common.sdf3`, which you can find in any initial Spoofax editor project.
|
||||
This module provides syntax definitions for common lexical sorts such as identifiers, integers, strings, whitespace, and comments. -->
|
||||
|
||||
<!-- For more information on how to write SDF3 syntax definitions, also check the documentation on how to define a language in Spoofax.
|
||||
{: .notice .notice-warning} -->
|
||||
|
||||
<p>For more information on how to write SDF3 syntax definitions, you can also review the <a href="http://www.metaborg.org/en/latest/source/langdev/meta/lang/sdf3/index.html">old SDF3 reference manual</a> and the new <a href="https://www.spoofax.dev/references/syntax/">SDF3 reference</a>.</p>
|
||||
|
||||
<p class="notice notice-warning"><strong>Note that both of these are written for Spoofax 2, and that not all information may still be correct in Spoofax 3!</strong></p>
|
||||
|
||||
<h4 id="context-free-syntax">Context-free Syntax</h4>
|
||||
|
||||
<p>Start with the context-free syntax of the language.
|
||||
Use the context-free grammar in the <em>ChocoPy Language Reference Manual</em> as a reference.</p>
|
||||
|
||||
<!-- When you define your syntax definition bottom-up, you start with sorts such as `Type` and `VarDecl`.
|
||||
This allows you to run your tests frequently and check your progress. -->
|
||||
|
||||
<p>We recommend to use <em>template productions</em> for your context-free syntax definition, since they help when generating artifacts other than just the parser.
|
||||
When you use template productions, you need to make sure that templates are correctly tokenised.
|
||||
Otherwise, the parser would reject layout in certain positions, for example between <code class="language-plaintext highlighter-rouge">[</code> and <code class="language-plaintext highlighter-rouge">]</code> in an array type.
|
||||
Check the SDF3 documentation for details.
|
||||
In case you want to use <code class="language-plaintext highlighter-rouge"><</code> or <code class="language-plaintext highlighter-rouge">></code> as symbols inside a template, you can use alternate template brackets <code class="language-plaintext highlighter-rouge">[...]</code>.</p>
|
||||
|
||||
<h4 id="lexical-syntax">Lexical Syntax</h4>
|
||||
|
||||
<p>Continue with the lexical syntax definition including identifiers, integer, and simple layout.
|
||||
<!-- The `Common` module in `syntax/Common.sdf3` already provides definitions, but these do not necessarily comply with the lexical syntax of ChocoPy. -->
|
||||
<!-- You can either fix these definitions in `Common`, or define and import your own module and use `Common` only for inspiration. --></p>
|
||||
|
||||
<p>First, define lexical syntax rules:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lexical syntax
|
||||
ID = ...
|
||||
INT = ...
|
||||
LAYOUT = ...
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Second, define follow restrictions to ensure longest match:</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lexical restrictions
|
||||
ID -/- ...
|
||||
INT -/- ...
|
||||
context-free restrictions
|
||||
LAYOUT? -/- ...
|
||||
</code></pre></div></div>
|
||||
|
||||
<p>Finally, use rejection rules to rule out reserved words.</p>
|
||||
|
||||
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lexical syntax
|
||||
ID = ... {reject}
|
||||
</code></pre></div></div>
|
||||
|
||||
<h4 id="testing-your-syntax-definition">Testing Your Syntax Definition</h4>
|
||||
|
||||
<p>You now can check your tests.</p>
|
||||
|
||||
<p class="notice notice-danger">It is important to get your grammar working at this stage. Do not move on if you have issues here, since there is a high chance that these issues influence your other tests as well. If you experience weird behaviour on your tests or a large amount of ambiguity, this is most likely caused by an erroneous definition of <code class="language-plaintext highlighter-rouge">LAYOUT</code>.</p>
|
||||
|
||||
<p>Finally, you should add lexical syntax rules for comments to your syntax definition.
|
||||
Start with single line comments.
|
||||
Do not forget to define follow restrictions.</p>
|
||||
|
||||
<!-- ### Editor Services
|
||||
|
||||
When developing a language in Spoofax, the syntax definition written in SDF3 does not only produce a parser but other editor services as well.
|
||||
|
||||
#### Pretty Printing
|
||||
|
||||
Spoofax generates pretty-printing rules from your syntax definition.
|
||||
|
||||
In order to test the pretty-print builder, you need to build your project.
|
||||
Your ChocoPy editor provides a menu entry named `Format` that uses these generated rules to pretty-print a ChocoPy file.
|
||||
Create or open a `.cpy` test file with a valid program, go to the *Spoofax* -> *Syntax* menu and choose `Format`.
|
||||
This will apply `Format` to the current file and show the result in a new editor.
|
||||
|
||||
Typically, the pretty-printed code lacks proper indentation and line breaks.
|
||||
You can fix this by improving your templates in the syntax definition.
|
||||
The pretty-printer follows the indentation and line breaks from the syntax definition.
|
||||
|
||||
You should improve your syntax definition in order to get readable code with a consistent indentation.
|
||||
You might read on [indent styles](http://en.wikipedia.org/wiki/Indent_style) for some inspiration.
|
||||
|
||||
Make sure that your altered syntax definition is still correct and can be used to parse ChocoPy programs.
|
||||
{: .notice .notice-warning}
|
||||
|
||||
#### Syntactic Code Completion
|
||||
|
||||
Together with a pretty-printer, Spoofax also automatically derives syntactic code completion from the syntax definition. This feature allows for example, for new users to discover the language's syntax while editing the program. To know more details about syntactic code completion in Spoofax, check the documentation. -->
|
||||
|
||||
|
||||
</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="1b.html">
|
||||
«
|
||||
</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="1d.html">»</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="1c.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="1c.html#syntax-definition">Syntax Definition</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="1c.html#context-free-syntax">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="1c.html#lexical-syntax">Lexical 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="1c.html#testing-your-syntax-definition">Testing Your Syntax Definition</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="1b.html">
|
||||
Previous
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="1d.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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue