Selaa lähdekoodia

Update documentation.

Vladislav Folts 9 vuotta sitten
vanhempi
commit
a74ab6e117
3 muutettua tiedostoa jossa 36 lisäystä ja 2 poistoa
  1. 1 2
      README.md
  2. 34 0
      doc/wiki/eberon-associative-arrays.md
  3. 1 0
      doc/wiki/eberon.md

+ 1 - 2
README.md

@@ -1,7 +1,6 @@
 # Oberon 07 compiler
 
-Written in JavaScript (and partially in oberon itself) and translates Oberon to JavaScript code so it can be run in web browser.
-Supports both "pure" and "plus extensions" mode. Pure mode is a strict implementation of original Oberon language report. Language [extensions](https://github.com/vladfolts/oberonjs/wiki/Eberon) implemented in my own way and available as a separate compiler mode.
+Translates Oberon to JavaScript code ready to be run in web browser or nodejs. Compiler itself is written in Oberon (with [extensions](https://github.com/vladfolts/oberonjs/wiki/Eberon)) and compiled to JavaScript. The compiler supports both "pure" and "plus extensions" mode. Pure mode is a strict implementation of original Oberon language report. Language [extensions](https://github.com/vladfolts/oberonjs/wiki/Eberon) implemented in my own way and available as a separate compiler mode.
 
 ## Quick start
 You can try the compiler online [here](http://oberspace.dyndns.org/oberonjs.html).

+ 34 - 0
doc/wiki/eberon-associative-arrays.md

@@ -0,0 +1,34 @@
+Associative arrays are indexed by string keys. The basic operations on a such array is storing a value (having declared type) and extracting the value given the key (string).
+
+### Syntax
+Associative arrays are declared using keyword *MAP*:
+    
+    VAR m: MAP OF INTEGER; (* m is associative array storing integer values *)
+
+    TYPE T = RECORD field: MAP OF T END; (* associative array can have records as values *)
+
+### Semantics
+Notation similar to ordinary arrays is used to acceess, add a new element or replace existing element (with the same key) in associative array:
+    
+    m[key] := value; (* add/replace element *)
+    value := m[key]; (* get element *)
+
+_key_ type should be compatible with [[STRING|eberon-strings]] and _value_ should be compatible with declared type. Attempt to access element with non-existing key will break program execution.
+
+Keyword *IN* is used to test whether element with specified key is present in the array:
+    
+    IF key IN m THEN
+
+It is also possible to iterate through associative array keys/values using *FOR..IN* loop:
+    
+    FOR key, value IN m DO END
+
+Here _key_ and _value_ are variables assigned to each key/value pair while iterating through array. These variables have no a separate declaration and their visibility scope is inside loop only. Also these variables are read-only - similar to non-VAR parameters.
+
+To remove element from array *remove* method is used:
+    
+    m.remove(key)
+
+To remove all elements from array *clear* method is used:    
+
+    m.clear()

+ 1 - 0
doc/wiki/eberon.md

@@ -9,6 +9,7 @@ Eberon basically extends original Oberon (excluding additional [restrictions](#r
 * [[In Place Variables|eberon-in-place-variables]]
 * [[Implicit Type Narrowing|eberon-implicit-type-narrowing]]
 * [[Dynamic Arrays|eberon-dynamic-arrays]]
+* [[Associative Arrays|eberon-associative-arrays]]
 * [[Array indexOf() method|eberon-array-methods]]
 * [[Record fields read-only export|eberon-record-fields-read-only-export]]
 * [[Procedure call result can be denoted|eberon-procedure-call-result]]