Simple compiler and webapp for Modelleertaal
Modelleertaal is the language used for "natuurkundig modelleren" (dynamical models in high school physics in NL. System dynamics, Jay W. Forrester, DYNAMO, ...) The language is a subset of "CoachTaal" which is an imperative language derived from Pascal.
Modelleertaal tries to resemble the syntax used in NL textbooks and exams, which is CoachTaal with some differences:
- Statements are not ; terminated
- = is used for assignments (:= is allowed, and treated as an alias. Slightly different from CoachTaal)
- == is used for the 'equal' operator, instead of =. In practice the == operator should never be used.
- Only 'als dan eindals' 'anders' and 'stop' statements are implemented. Other flowcontrol is never used in Modelleertaal.
- Functions cannot be defined. Most math functions from CoachTaal are implemented.
- sin(x), cos(x) and tan(x) are always in degrees. Other trig functions in radians.
- C/Java style comments are allowed
Als (a == 0) En Niet(b == Waar) Dan Stop 'modelleertaal
If (a = 0) AND !(b = True) then Halt(0);
Examen vwo 2005-I Champignon:
'model parachutesprong 'modelregels Fwr = k * v^2 Fres = Fzw - Fwr a = Fres/m dv = a * dt v = v + dv dy = v * dt y = y + dy h = h0 - y t = t + dt als h < 400 dan k = 0.6 * (400 - h) eindals als h < 350 dan k = 30 eindals
About the modelleertaal compiler
run.js contains a benchmark. Compared to other modellertaal interpreters/compilers it is orders of magnitude faster.
eval() has been wrapped into an anonymous function to prevent bailout of the V8 optimising compiler.
model = new evaluator_js.Model(); model.modelregels = "a = a + 1"; model.startwaarden ="a = 1\n b=2\n"; N = 1000; var evaluator = new evaluator_js.ModelregelsEvaluator(model); results = evaluator.run(N);
model.js is used to read/write models. Models are stored in
BogusXML which has an XML-like syntax with
To use the
master branch (development version) of the webapp and/or compiler you will need to build it. This requires Node.js,
npm and grunt:
npm install -g grunt-cli npm install grunt
To just run the webapp in a browser or in a website you need the browserified file
which is not included in the
master branch. Either clone the
gh-pages branch or download a zip or tarball from the
How to customize the webapp
index.html and the folders
modellen/ are needed. See the previous paragraph on how to obtain or build
scripts/modelleertaal-app.browser.js which is not included in the
master branch. Optionally change the models in
modellen/models.js accordingly. Put it on a website somewhere. All code runs in the browser.
Running the webapp offline
The webapp should run offline, but browser security may interfere with loading the models. (Cross site scripting protection may
block the ajax request). At the time of writing the webapp works offline in Edge and Firefox (47) but ajax is blocked in Chrome (61).
To use Chrome use the
--disable-web-security flag when starting Chrome.
License and credits
This compiler and webapp implements the language used in Dutch High School Physics exams. This language is (based on) Coach and CoachTaal. Coach is developped by CMA Science.
The webapp was built using jQuery and Flot and heavily inspired by HiSPARC jSPARC.
This was originally based on Zach Carter's jsconf 2010 jison talk.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.