2015-11-30 18:55:48 +01:00
|
|
|
[![Build Status](https://travis-ci.org/salama/soml-parser.svg?branch=master)](https://travis-ci.org/salama/soml-parser)
|
|
|
|
[![Gem Version](https://badge.fury.io/rb/soml-parser.svg)](http://badge.fury.io/rb/soml-parser)
|
|
|
|
[![Test Coverage](https://codeclimate.com/github/salama/soml-parser/badges/coverage.svg)](https://codeclimate.com/github/salama/soml-parser)
|
2015-07-18 12:09:16 +02:00
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
## Soml Parser
|
2015-08-30 16:28:30 +02:00
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
The parser part of soml is a standalone gem to allow independent development.
|
|
|
|
It parses Soml using Parslet and no other dependencies.
|
2015-08-30 16:28:30 +02:00
|
|
|
|
2015-09-15 17:57:21 +02:00
|
|
|
Also it is very educational, as it is very readable code, and not too much of it.
|
2014-06-04 18:55:04 +02:00
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
## Soml: Salama Object Machine Language
|
2014-06-04 20:07:47 +02:00
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
Soml is Still forming after realizing the need for an oo system language.
|
2015-09-15 17:57:21 +02:00
|
|
|
|
2015-10-07 14:04:23 +02:00
|
|
|
The need comes from these three things:
|
2015-09-15 17:57:21 +02:00
|
|
|
|
2015-10-07 14:04:23 +02:00
|
|
|
- a language is needed to translate to. Meaning a software layer is needed, but to understand how
|
|
|
|
that layer works, a syntax is needed. Thus is born a language.
|
|
|
|
- Upward compatible memory and calling conventions are needed
|
|
|
|
- Multiple return addresses are needed
|
2015-09-15 17:57:21 +02:00
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
In Soml a function call is not necessarily a part of linear code. A call may return to several
|
2015-10-07 14:04:23 +02:00
|
|
|
addresses, making the call more like an if statement.
|
2015-09-17 23:02:52 +02:00
|
|
|
|
2015-09-15 17:57:21 +02:00
|
|
|
### Syntax
|
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
Syntax and semantics of Soml are described on the [salama site](http://salama-vm.org/soml/soml.html)
|
2015-09-15 17:57:21 +02:00
|
|
|
|
2015-11-30 18:55:48 +01:00
|
|
|
- statically typed so all variable declarations, functions and arguments are typed.
|
2015-09-15 17:57:21 +02:00
|
|
|
- objects but without data hiding
|
|
|
|
- static blocks (a bit ala crystal)
|
|
|
|
- call syntax as already discussed, ie message based
|
2015-11-30 18:55:48 +01:00
|
|
|
- no semicolns and stuff, but not ruby either
|
2014-06-04 20:07:47 +02:00
|
|
|
|
2014-06-04 20:36:47 +02:00
|
|
|
### Parser
|
|
|
|
|
2015-05-01 15:26:26 +02:00
|
|
|
The main parser per se is in parser/salama , but it just pulls in all the parts.
|
2014-06-04 20:36:47 +02:00
|
|
|
|
2015-05-01 15:26:26 +02:00
|
|
|
All the other files are ruby modules representing aspects of the parser.
|
|
|
|
Most names are quite self explanatory, but here is a list:
|
2014-06-04 20:36:47 +02:00
|
|
|
|
|
|
|
- basic_type defines just that. Strings, symbols, integers, floats , also comments and space
|
|
|
|
- call_site is a function call. May be qualified, but currently must still have braches
|
|
|
|
- compound types are hash and array definitions. Hashes still need curlies
|
|
|
|
- control is if statement which still must have an else
|
2015-10-09 16:23:43 +02:00
|
|
|
- statement is a helper for all code allowed in a function
|
2014-06-04 20:36:47 +02:00
|
|
|
- function definition must have braces too
|
|
|
|
- keywords is just a list of them
|
2015-10-09 16:23:43 +02:00
|
|
|
- operator statement are binary operators (see also below). There's a surprising amount
|
2014-06-04 20:36:47 +02:00
|
|
|
- return statement are straightforward
|
|
|
|
- while still needs a do, though i think in ruby a newline is sufficient
|
|
|
|
|
|
|
|
**Transform** defines how the rules map to Ast objects.
|
|
|
|
|
|
|
|
### Ast
|
|
|
|
|
2015-09-15 17:57:21 +02:00
|
|
|
The ast layer now uses the ast gem. That approach is to use a single class to represent all
|
|
|
|
types of node and use a type symbol (instead of different classes)
|
2014-06-04 20:36:47 +02:00
|
|
|
|
2015-09-15 17:57:21 +02:00
|
|
|
This works well, and is much less work.
|
2014-06-04 20:36:47 +02:00
|
|
|
|
2015-09-15 17:57:21 +02:00
|
|
|
The following step of compiling use the same kind of visitor approach as before
|
2014-06-04 20:07:47 +02:00
|
|
|
|
|
|
|
### Parslet
|
2014-06-04 18:55:04 +02:00
|
|
|
|
|
|
|
Parslet is really great in that it:
|
2014-06-04 20:36:47 +02:00
|
|
|
- does not generate code but instead gives a clean dsl to define a grammar
|
2014-06-04 18:55:04 +02:00
|
|
|
- uses ruby modules so one can split the grammars up
|
2015-05-01 15:26:26 +02:00
|
|
|
- has support for binary operators with precedence and binding
|
|
|
|
- has a separate transform stage to generate an ast layer
|
2014-06-04 18:55:04 +02:00
|
|
|
|
2015-05-01 15:26:26 +02:00
|
|
|
Especially the last point is great. Since it is separate it does not clutter up the actual grammar.
|
2014-06-04 18:55:04 +02:00
|
|
|
And it can generate a layer that has no links to the actual parser anymore, thus saving/automating
|
2015-05-01 15:26:26 +02:00
|
|
|
a complete transformation process.
|