123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
- <title>Action Language — Modelverse 0.4.0 documentation</title>
-
- <link rel="stylesheet" href="_static/classic.css" type="text/css" />
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
-
- <script type="text/javascript">
- var DOCUMENTATION_OPTIONS = {
- URL_ROOT: './',
- VERSION: '0.4.0',
- COLLAPSE_INDEX: false,
- FILE_SUFFIX: '.html',
- HAS_SOURCE: true
- };
- </script>
- <script type="text/javascript" src="_static/jquery.js"></script>
- <script type="text/javascript" src="_static/underscore.js"></script>
- <script type="text/javascript" src="_static/doctools.js"></script>
- <link rel="top" title="Modelverse 0.4.0 documentation" href="index.html" />
- <link rel="next" title="Modelling Language" href="modellanguage.html" />
- <link rel="prev" title="How to run" href="howto.html" />
- </head>
- <body role="document">
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="genindex.html" title="General Index"
- accesskey="I">index</a></li>
- <li class="right" >
- <a href="modellanguage.html" title="Modelling Language"
- accesskey="N">next</a> |</li>
- <li class="right" >
- <a href="howto.html" title="How to run"
- accesskey="P">previous</a> |</li>
- <li class="nav-item nav-item-0"><a href="index.html">Modelverse 0.4.0 documentation</a> »</li>
- </ul>
- </div>
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <div class="section" id="action-language">
- <h1>Action Language<a class="headerlink" href="#action-language" title="Permalink to this headline">¶</a></h1>
- <p>The primary language of the Modelverse, is its action language.
- This language serves as a nicer representation of the underlying Modelverse Graph Language, which is stored as a graph.
- The action language gets parsed by the parser, resulting in a kind of abstract syntax graph.
- This abstract syntax graph highly resembles an executable graph in the Modelverse Graph Language.</p>
- <p>Users will mainly use this language to write actions and constraints, but maybe also to implement their own interfaces, or override core functionality of the Modelverse.</p>
- <div class="admonition warning">
- <p class="first admonition-title">Warning</p>
- <p class="last">The current parser is unable to handle whitespaces in a general way.
- As such, all indentation needs to be done using tabs, and the difference needs to be exactly 1.
- This is different from Python, where tabs and whitespaces can be mixed, and the number can even vary.</p>
- </div>
- <div class="section" id="files">
- <h2>Files<a class="headerlink" href="#files" title="Permalink to this headline">¶</a></h2>
- <p>There are two kinds of files: code files, and headers.
- This distinction is similar to C and related languages.
- Code in header files will always be copied throughout all including files.
- As such, it is a good idea to have header files which declare the signatures of functions, but leave the actual implementation to the code files.
- Code files do not need to import the headers they are implementing: all variable names are automatically shared.</p>
- </div>
- <div class="section" id="language-description">
- <h2>Language description<a class="headerlink" href="#language-description" title="Permalink to this headline">¶</a></h2>
- <p>The language is inspired by Python syntax, and highly resembles it.
- Nonetheless, it is a lot simpler.
- In the remainder of this subsection, we go over the different language constructs.</p>
- <div class="section" id="if">
- <h3>If<a class="headerlink" href="#if" title="Permalink to this headline">¶</a></h3>
- <p>The IF construct is similar to that found in other languages.
- Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="k">if</span> <span class="n">condition1</span><span class="p">:</span>
- <span class="n">do_when_condition1</span>
- <span class="k">elif</span> <span class="n">condition2</span><span class="p">:</span>
- <span class="n">do_when_condition2</span>
- <span class="k">else</span><span class="p">:</span>
- <span class="n">do_otherwise</span>
- </pre></div>
- </div>
- <p>Each condition can be an expression.
- The code blocks can be any other kind of code.
- Just like Python, indentation is the only way to structure code.
- Unlike Python, only tabs are allowed (thus no space), and the number of tabs must be exactly one higher for a deeper block.</p>
- <p>The presence of an “elif” and “else” is optional.</p>
- </div>
- <div class="section" id="while">
- <h3>While<a class="headerlink" href="#while" title="Permalink to this headline">¶</a></h3>
- <p>The WHILE construct is similar to that found in other languages.
- Contrary to Python, there is no support for the “else” construct.
- Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="k">while</span> <span class="n">condition</span><span class="p">:</span>
- <span class="n">action</span>
- </pre></div>
- </div>
- <p>Conditions and actions are similar to the If construct.</p>
- </div>
- <div class="section" id="break">
- <h3>Break<a class="headerlink" href="#break" title="Permalink to this headline">¶</a></h3>
- <p>Whereas this is supported in the Modelverse, the parser currently does not consider this keyword.</p>
- </div>
- <div class="section" id="continue">
- <h3>Continue<a class="headerlink" href="#continue" title="Permalink to this headline">¶</a></h3>
- <p>Whereas this is supported in the Modelverse, the parser currently does not consider this keyword.</p>
- </div>
- <div class="section" id="return">
- <h3>Return<a class="headerlink" href="#return" title="Permalink to this headline">¶</a></h3>
- <p>The RETURN construct is again similar to how it is expected.
- To prevent ambiguity in the grammar, an exclamation mark should follow after the expression to return.
- Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre>return expression!
- </pre></div>
- </div>
- <p>The expression can be any expression, similar to the condition in an If and While.</p>
- </div>
- <div class="section" id="function-call">
- <h3>Function call<a class="headerlink" href="#function-call" title="Permalink to this headline">¶</a></h3>
- <p>Function calls happen like usual, by appending an opening and closing parenthesis at the end.
- Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="n">my_function</span><span class="p">(</span><span class="n">argument_a</span><span class="p">,</span> <span class="n">argument_b</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>Arguments can again be any kind of expression.
- Named parameters are not supported in the grammar, though the Modelverse can internally handle them.</p>
- </div>
- <div class="section" id="function-definition">
- <h3>Function definition<a class="headerlink" href="#function-definition" title="Permalink to this headline">¶</a></h3>
- <p>Defining a function makes the function available as a variable in the remainder of the context.
- Forward declaration is unnecessary: all function names are retrieved before going over the body of the functions.
- This makes mutual recursion easy.</p>
- <p>A function needs to define its return type, as well as the type of all its parameters.
- In case the type is unknown, or can be anything, <em>Element</em> can be used as a kind of “void pointer”.
- Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="n">Element</span> <span class="n">function</span> <span class="n">function_name</span><span class="p">(</span><span class="n">parameter_a</span> <span class="p">:</span> <span class="n">Integer</span><span class="p">):</span>
- <span class="n">body_of_the_function</span>
- </pre></div>
- </div>
- <p>First comes the returntype, followed by the keyword “function”.
- Again, indentation needs to happen using tabs.</p>
- </div>
- <div class="section" id="assignment">
- <h3>Assignment<a class="headerlink" href="#assignment" title="Permalink to this headline">¶</a></h3>
- <p>Assignment is like usual.
- Its structure is:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="n">a</span> <span class="o">=</span> <span class="n">expression</span>
- </pre></div>
- </div>
- <p>This assumes that a is already defined.</p>
- </div>
- <div class="section" id="declaration">
- <h3>Declaration<a class="headerlink" href="#declaration" title="Permalink to this headline">¶</a></h3>
- <p>All variables used in the Modelverse need to be defined statically.
- Defining a variable reserves a part of the Modelverse State to hold the value for this value.
- As such, variables cannot be used if they are not defined.
- Additionally, a declared variable will have a type defined with it.
- Again, if the type can vary or is unknown, this can be <em>Element</em>.</p>
- <div class="admonition warning">
- <p class="first admonition-title">Warning</p>
- <p class="last">Contrary to other languages, declaring a variable does not equal defining the variable.
- Therefore, after a variable is declared, it can be used, but its contents will be non-existing.
- It is wise to always assign a value to a declared value right after declaration!</p>
- </div>
- <p>Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="n">String</span> <span class="n">abc</span>
- </pre></div>
- </div>
- <p>There are two kinds of declaration: local declaration, and global declaration.
- Local declarations happen in the current block of the code, and their references get removed when exiting the block.
- Global declarations have identically the same syntax, but are specified at the top level (<em>i.e.</em>, they have no tabs in front of them).
- Global declarations do not assign a value and are thus external references, to be defined in the future or by some other module.
- Sharing between modules is possible this way, as all global names are linked together when linking the application together.
- A global declaration that is never defined is flagged as invalid by the compiler and will prevent compilation.</p>
- </div>
- <div class="section" id="definition">
- <h3>Definition<a class="headerlink" href="#definition" title="Permalink to this headline">¶</a></h3>
- <p>Defining a variable is similar to a global declaration, but now there is an immediate assignment.
- Immediate assignment is only possible at the top level.
- Note that the assignment must be of a constant which requires no execution of functions or such.
- Also, it is impossible to assign the value of another variable.</p>
- <p>Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre><span class="n">String</span> <span class="n">abc</span> <span class="o">=</span> <span class="s">"abc"</span>
- </pre></div>
- </div>
- <p>It is possible that a definition does not yet know the value to assign, or is an empty element.
- To notify the other files that this is the defining element, use the import syntax to assign <em>?</em> to it:</p>
- <div class="highlight-default"><div class="highlight"><pre>Element abc = ?
- </pre></div>
- </div>
- <p>This results in the Modelverse creating an empty node as placeholder for a value.
- The value will now be defined and accessible.</p>
- </div>
- <div class="section" id="imports">
- <h3>Imports<a class="headerlink" href="#imports" title="Permalink to this headline">¶</a></h3>
- <p>Direct imports in the Modelverse are possible, but are not recommended for ordinary users.
- This syntax allows a variable to be bound to an absolute location in the Modelverse, which is resolved at compile time.
- The primary use case for this is the creation of bootstrap files, but it is also possible for other purposes.
- Use with care!</p>
- <p>Its structure is as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre>String abc = ?path/in/modelverse
- </pre></div>
- </div>
- <p>A special case is when the path is empty, which indicates that a new (anonymous) node should be created for it:</p>
- <div class="highlight-default"><div class="highlight"><pre>Element abc = ?
- </pre></div>
- </div>
- </div>
- <div class="section" id="include">
- <h3>Include<a class="headerlink" href="#include" title="Permalink to this headline">¶</a></h3>
- <p>Other files can easily be included using the include syntax.
- This is a raw include: the contents of the file are just copied inside the file at that exact spot.
- Generally, you should only include <em>.alh</em> files, unless you know what you are doing.</p>
- </div>
- <div class="section" id="constants">
- <h3>Constants<a class="headerlink" href="#constants" title="Permalink to this headline">¶</a></h3>
- <p>The Modelverse supports a set of constants that can be used.
- All constants can be assigned in a definition of globals.</p>
- <table border="1" class="docutils">
- <colgroup>
- <col width="14%" />
- <col width="79%" />
- <col width="7%" />
- </colgroup>
- <thead valign="bottom">
- <tr class="row-odd"><th class="head">Constant type</th>
- <th class="head">Values</th>
- <th class="head">Example</th>
- </tr>
- </thead>
- <tbody valign="top">
- <tr class="row-even"><td>Integer</td>
- <td>Any possible integer, either positive (no prefix) or negative (- prefix)</td>
- <td>1</td>
- </tr>
- <tr class="row-odd"><td>Float</td>
- <td>Any possible floating point value; scientific notation is not supported</td>
- <td>1.0</td>
- </tr>
- <tr class="row-even"><td>Boolean</td>
- <td>Either True or False</td>
- <td>True</td>
- </tr>
- <tr class="row-odd"><td>String</td>
- <td>Any possible string, enclosed with either double or single quotes</td>
- <td>“abc”</td>
- </tr>
- <tr class="row-even"><td>Action</td>
- <td>An action construct from the Modelverse, prefixed with an exclamation mark</td>
- <td>!If</td>
- </tr>
- </tbody>
- </table>
- </div>
- <div class="section" id="operators">
- <h3>Operators<a class="headerlink" href="#operators" title="Permalink to this headline">¶</a></h3>
- <p>While operators are seemingly supported by the compiler, these are actually expanded to function calls to relevant functions.
- For example, <em>1 + 2</em>, is expanded to <em>integer_addition(1, 2)</em></p>
- </div>
- <div class="section" id="user-i-o">
- <h3>User I/O<a class="headerlink" href="#user-i-o" title="Permalink to this headline">¶</a></h3>
- <p>User input and output is done through the keyworded operations <em>input()</em> and <em>output(msg)</em>.
- <em>input()</em> returns the first message in the input queue of the current user.
- <em>output(msg)</em> places the value of the expression in the output queue of the current user.</p>
- <p>All I/O is done using queues: the value is only read and written to a specific place in the Modelverse.
- To actually read or write it at the client side, these special places should be accessed through dedicated Modelverse operations.</p>
- </div>
- </div>
- <div class="section" id="examples">
- <h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
- <p>We now show some simple code fragments written in valid Action Language code.
- As this code is directly executable in the Modelverse, the main function is always called “main” and all includes are also present.
- We do not currently handle how to execute this code: this is explained further on.</p>
- <div class="section" id="fibonacci">
- <h3>Fibonacci<a class="headerlink" href="#fibonacci" title="Permalink to this headline">¶</a></h3>
- <p>The Fibonacci code is fairly simple.
- First, the primitives are imported to make sure that we know about all operations on primitives.
- Then, a function <em>fib</em> is defined, which will recursively compute the specified Fibonacci number.
- This is wrapped by a <em>main</em> function, which takes input from the user and outputs the result of the <em>fib</em> function.</p>
- <p>This code looks as follows:</p>
- <div class="highlight-default"><div class="highlight"><pre>include "primitives.alh"
- Integer function fib(param : Integer):
- if (param <= 2):
- return 1!
- else:
- return fib(param - 1) + fib(param - 2)!
- Void function main():
- while(True):
- output(fib(input()))
- </pre></div>
- </div>
- </div>
- <div class="section" id="factorial">
- <h3>Factorial<a class="headerlink" href="#factorial" title="Permalink to this headline">¶</a></h3>
- <p>Similarly, the code for computing a factorial is given below:</p>
- <div class="highlight-default"><div class="highlight"><pre>include "primitives.alh"
- Integer function factorial(n : Integer):
- if(n <= 1):
- return 1!
- else:
- return n * factorial(n - 1)!
- Void function main():
- while(True):
- output(factorial(input()))
- </pre></div>
- </div>
- </div>
- <div class="section" id="binary-to-decimal-converter">
- <h3>Binary to decimal converter<a class="headerlink" href="#binary-to-decimal-converter" title="Permalink to this headline">¶</a></h3>
- <p>A simple binary to decimal converter is given below:</p>
- <div class="highlight-default"><div class="highlight"><pre>include "primitives.alh"
- Integer function b2d(param : String):
- Integer value
- value = 0
- Integer length
- length = string_len(param)
- Integer counter
- counter = integer_subtraction(length, 1)
- Integer accumul
- accumul = 1
- while (counter >= 0):
- if (string_get(param, counter) == "1"):
- value = integer_addition(value, accumul)
- accumul = integer_multiplication(accumul, 2)
- counter = integer_subtraction(counter, 1)
- return value!
- Void function main():
- while(True):
- output(b2d(input()))
- </pre></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <h3><a href="index.html">Table Of Contents</a></h3>
- <ul>
- <li><a class="reference internal" href="#">Action Language</a><ul>
- <li><a class="reference internal" href="#files">Files</a></li>
- <li><a class="reference internal" href="#language-description">Language description</a><ul>
- <li><a class="reference internal" href="#if">If</a></li>
- <li><a class="reference internal" href="#while">While</a></li>
- <li><a class="reference internal" href="#break">Break</a></li>
- <li><a class="reference internal" href="#continue">Continue</a></li>
- <li><a class="reference internal" href="#return">Return</a></li>
- <li><a class="reference internal" href="#function-call">Function call</a></li>
- <li><a class="reference internal" href="#function-definition">Function definition</a></li>
- <li><a class="reference internal" href="#assignment">Assignment</a></li>
- <li><a class="reference internal" href="#declaration">Declaration</a></li>
- <li><a class="reference internal" href="#definition">Definition</a></li>
- <li><a class="reference internal" href="#imports">Imports</a></li>
- <li><a class="reference internal" href="#include">Include</a></li>
- <li><a class="reference internal" href="#constants">Constants</a></li>
- <li><a class="reference internal" href="#operators">Operators</a></li>
- <li><a class="reference internal" href="#user-i-o">User I/O</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#examples">Examples</a><ul>
- <li><a class="reference internal" href="#fibonacci">Fibonacci</a></li>
- <li><a class="reference internal" href="#factorial">Factorial</a></li>
- <li><a class="reference internal" href="#binary-to-decimal-converter">Binary to decimal converter</a></li>
- </ul>
- </li>
- </ul>
- </li>
- </ul>
- <h4>Previous topic</h4>
- <p class="topless"><a href="howto.html"
- title="previous chapter">How to run</a></p>
- <h4>Next topic</h4>
- <p class="topless"><a href="modellanguage.html"
- title="next chapter">Modelling Language</a></p>
- <div role="note" aria-label="source link">
- <h3>This Page</h3>
- <ul class="this-page-menu">
- <li><a href="_sources/actionlanguage.txt"
- rel="nofollow">Show Source</a></li>
- </ul>
- </div>
- <div id="searchbox" style="display: none" role="search">
- <h3>Quick search</h3>
- <form class="search" action="search.html" method="get">
- <div><input type="text" name="q" /></div>
- <div><input type="submit" value="Go" /></div>
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
- <script type="text/javascript">$('#searchbox').show(0);</script>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="genindex.html" title="General Index"
- >index</a></li>
- <li class="right" >
- <a href="modellanguage.html" title="Modelling Language"
- >next</a> |</li>
- <li class="right" >
- <a href="howto.html" title="How to run"
- >previous</a> |</li>
- <li class="nav-item nav-item-0"><a href="index.html">Modelverse 0.4.0 documentation</a> »</li>
- </ul>
- </div>
- <div class="footer" role="contentinfo">
- © Copyright 2016, Yentl Van Tendeloo.
- Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
- </div>
- </body>
- </html>
|