<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to implementation notes</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>Recent changes to implementation notes</description><atom:link href="https://sourceforge.net/p/pascal-p5c/wiki/implementation%20notes/feed" rel="self"/><language>en</language><lastBuildDate>Sat, 23 Jun 2018 23:14:48 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/pascal-p5c/wiki/implementation%20notes/feed" rel="self" type="application/rss+xml"/><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v10
+++ v11
@@ -239,7 +239,7 @@
 gcc allows nested functions, so nested pascal functions are simply compiled into nested c functions.

-=====================================
+--------------------------------------------------------------

 ##Code Compilation

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 23 Jun 2018 23:14:48 -0000</pubDate><guid>https://sourceforge.net74165a1c331d19137e5a8b83f16403b48e3764ec</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v9
+++ v10
@@ -27,7 +27,7 @@

 ###arrays are different.

-At first sight they appear the same since they have the same syntax: array1[i] is the ith component of the array called array1.
+At first sight they appear the same since they have the same syntax: array1\[i] is the ith component of the array called array1.
 In c, however, array1 is not an array as a pascal user would understand it, but a pointer to an array.
 This c code
 ~~~c
@@ -100,9 +100,17 @@
 ####but note **arrays**:
 in c, an array is just a pointer, so if arrayA &amp;amp; arrayB are arrays,

- **in pascal** arrayA := arrayB copies all the components of arrayB  into arrayA,  and assigning a new value to one of the elents in arrayA has no effect on   arrayB.
-
- I**n c, on the other hand**,  the statement arrayA = arrayB makes arrayA point to the same components as arrayB.
+ **in pascal** the statement 
+ 
+     arrayA := arrayB
+     
+copies all the components of arrayB  into arrayA,  and assigning a new value to one of the elents in arrayA has no effect on   arrayB.
+
+ **In c, on the other hand**,  the statement 
+
+    arrayA = arrayB
+
+makes arrayA point to the same components as arrayB.
 Now a change to one of the components to arrayA will be seen in arrayB as well.

 To overcome this, p5x wraps pascal arrays are inside a c struct.
@@ -242,7 +250,7 @@

 See Pemberton for a complete explanation.

-Consequently, the compiler has almost no memory of the code it has just processed and code needs to generated in the same sequence as it is encountered.
+Consequently, the compiler has almost no memory of the code it has just processed and code needs to be generated in the same sequence as it is encountered.

 ###expressions become trees

@@ -323,9 +331,9 @@
 ~~~c
      struct { uint8_t element[n] }  mySet;
 ~~~
-where **n** is the number of bytes (ie uint8_t) needed to hol;e the set elements.
-
-A set union is a  bitwise or operation on the bytes and set intersection is a bitwise and operation.  Set difference is slightly more complicated - it is a bitwise and with a bitwise compliment, 
+where **n** is the number of bytes (ie uint8_t) needed to hold the set elements.
+
+A set union is a  bitwise **or operation** on the bytes and set intersection is a bitwise **and operation**.  Set difference is slightly more complicated - it is a bitwise **and** with a bitwise **compliment**, 
 eg 
 ~~~pascal
         setA - setB
@@ -355,7 +363,7 @@
 ~~~pascal
       myset : set of 30..40;
 ~~~
-will occupy 3 bytes, with the first byte holding the element values 24..31, even though only values 30 &amp;amp; 31 are used.  The second byte will hold values 32..39, and the third byte will hold the values 40..47 with only the value 4 being used,
+will occupy 3 bytes, with the first byte holding the element values 24..31, even though only values 30 &amp;amp; 31 are used.  The second byte will hold values 32..39, and the third byte will hold the values 40..47 with only the value 40 being used,

 A bigger question is what size does a set need to be to evaluate a given expression?

@@ -533,13 +541,13 @@
 ~~~pascal
    mySet := [0,5] - [i];
 ~~~
-We don't need to know where each element is of the set expression is, just whether any element is outside the bounds of mySet.
-
-For now, assume a function, **isNonEmpty(expression, range)**, which checks if there are elements of the set expression in the range.
+We don't need to know where each element of the set expression is, just whether any element is outside the bounds of mySet.
+
+For now, assume we have a function, **isNonEmpty(expression, range)**, which checks if there are elements of the set expression in the range.

 Recall that in p5c, we can analyse setexpressions because they are implemented by trees, and let's say the expression in the above example is represented by the tree T.

-We can now see that our set expression has an error iff
+We can now see that the above set expression has an error iff
 ~~~pascal
    isNonEmpty(T, -maxint..0) or isNonEmpty(T, 11..maxint)
 ~~~
@@ -590,8 +598,9 @@

      and similarly the high limit is 

-       min(high bounds of each set in the term)
-     In many cases, the low limit will be greater than the high bound, so there    is nothing to do.
+        min(high bounds of each set in the term)
+       
+In many cases, the low limit will be greater than the high bound, so there    is nothing to do.

  - many of the terms are of the form `[a..b]`, so apart from contributing to the    low &amp;amp; high limits of the term, they need no further consideration. 
         (  `[a..b] * s = s`  inside these limits)
@@ -622,7 +631,7 @@

      [i..j] - [k]  =  [i..j] * /[k]

-  where     `/[k]` is the inverse of `[k]`.  This is `[-maxint..k-1, k+1..maxint]`, but     here we are considering only the range `11..maxint`, so
+  where     `/[k]` is the compliment of `[k]`.  This is `[-maxint..k-1, k+1..maxint]`, but     here we are considering only the range `11..maxint`, so

                /[k] = [11..k-1, k+1..maxint]

@@ -654,7 +663,7 @@

                       [6..12]*[11..11] + [6..12]*[13..maxint]

-which reduces to `[11] + []` and  statement (1) is in error.
+which reduces to `[11] + []` which is non-empty and  statement (1) is in error.

 Returning to equation (2) above, we consider the term on each side of the plus operator separately. Since each term is just the intersection of 2 ranges, the result is another range whose lower limit is 

@@ -680,9 +689,8 @@

 - since many subexpressions are evaluated more than once, it is important to  consider side efefcts.  We need to store all sub expressions in temporary   variables to avoid unnecessary side efefcts, and to save reevaluating them   again.

-We can use analytic comparison to enhance some features of set evaluation mentioned earlier where the set size is unknown or impossibly large.
-
-The benefits of evaluating set expressions analytically go beyond debugging.
+The benefits of evaluating set expressions analytically go beyond error detection.
+We can use analytic comparison to enhance some features of set evaluation mentioned earlier where the set size is unknown at compile time or is known but is impossibly large.

 We saw earlier that in a statement such as

@@ -700,7 +708,7 @@

             a - b = []

-We can use now use our **isNonEmpty**() function to check the set expression a-b and determine the result of the expression.  This is without creating the large set(s), but possibly at the cost of creating a large amont of code.
+We can use now use our **isNonEmpty**() function to check the set expression `a-b` and determine the result of the expression.  This can be done without creating the large set(s), but possibly at the cost of creating a large amont of code.

 Note also that the set expression 

@@ -834,7 +842,7 @@
 p5c creates a function called **\_Pcleanup** that closes every file declared in that block.  If that file has a name, it is **external** and is correctly  terminated with a newline if necessary.
 When the procedure or function returns, **\_Pcleanup** is called to close all the files that are declared in this procedure or function.

-There is a global list of all cleanup functions which is updated on every block entry and exit. The head of this list is \**_Phead**.
+There is a global list of all cleanup functions which is updated on every block entry and exit. The head of this list is **_Phead**.

 Now, when a goto statement leaves a block, all the cleanup functions in this list are called upto the destination level, and \_Phead is updated.

@@ -848,6 +856,6 @@

 Note that:

--   it needs to account for arrays of files by generating a    loop tp close each member of the array.
+-   it needs to account for arrays of files by generating a    loop to close each member of the array.
 -  it calls itself recursively when it finds a record that contains files. In    this case the procedure parameter that prints the variable name might print    more than a simple identifier: it could print an arbitrarily complicated    declaration (say `a[i0].r.m`).

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 23 Jun 2018 23:13:23 -0000</pubDate><guid>https://sourceforge.net4870caa0c3acf5dea683400d06de466fe8525c5e</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v8
+++ v9
@@ -521,7 +521,7 @@

 ###set bounds errors

-We have seen already the p5c implementation needs to solve the difficulties of alignment of the elemnts and determining the size of sets inside set expressions.  There is another problem to be solved - how do we determine if a set's bounds are exceeded?
+We have seen already the p5c implementation needs to solve the difficulties of alignment of the elements and determining the size of sets inside set expressions.  There is another problem to be solved - how do we determine if a set's bounds are exceeded?

 This example is simple enough:
 ~~~pascal
@@ -712,6 +712,7 @@

 so again we can use our isNonEmpty() function evalute this expression without knowing the set size.

+&lt;a name="extreme-sets"&gt;&lt;/a&gt;
 Finally, the set expression may have a known size, but might be too extreme to use.
 For example this expression:
 ~~~pascal
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Fri, 08 Jun 2018 15:15:10 -0000</pubDate><guid>https://sourceforge.net77b20ad86af815a0b7b1db66a89ebf44303e2a84</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v7
+++ v8
@@ -1,12 +1,12 @@
 p5c Implementation Notes
 ========================

-* See Pemberton for outline of program structure
-* See all the docs in p5 project.
-* you might need a c reference.
-     eg "The C book". avaialable at http://publications.gbdirect.co.uk/c_book/
-* See gcc docs.   gcc has important extensions that are needed by p5c and p5x
-* 
+* See [Pemberton' book](https://homepages.cwi.nl/~steven/pascal/) for an excellent outline of program structure
+* See all the docs in [the p5 project](https://sourceforge.net/projects/pascalp5/files/).
+* you might need a c reference,
+     eg [The C book](http://publications.gbdirect.co.uk/c_book/)
+* See gcc docs.   gcc has [important extensions](http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html) that are needed by p5c and p5x
+

 [TOC]

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sun, 03 Jun 2018 14:57:55 -0000</pubDate><guid>https://sourceforge.netb01e2eb84a5088b61cafe252016fd91985884845</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v6
+++ v7
@@ -787,7 +787,7 @@
 The flags member of the file structure has the following values:

 value | meaning 
----------- :| ---------- 
+----------:| ---------- 
 -2  |  the file is a text file in write mode, and                    the current line has not been terminated with an eoln char
 -1   | the file is in write mode
  0    | the file has not yet read the next item into buffer, see note below.
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 02 Jun 2018 22:18:01 -0000</pubDate><guid>https://sourceforge.netc751f0c422a15646e5f61f4a9148e564fa8d1f87</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v5
+++ v6
@@ -787,7 +787,7 @@
 The flags member of the file structure has the following values:

 value | meaning 
-----------: | ---------- 
+---------- :| ---------- 
 -2  |  the file is a text file in write mode, and                    the current line has not been terminated with an eoln char
 -1   | the file is in write mode
  0    | the file has not yet read the next item into buffer, see note below.
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 02 Jun 2018 22:13:57 -0000</pubDate><guid>https://sourceforge.net8cf9f7e2b8f85bce8982ba0ae90b89098fac24b3</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -46,9 +46,9 @@
 ~~~
 is compiled to a c declaration like this:
 ~~~c
-typedef struct {
-   int component[9];
-} MyArray;
+    typedef struct {
+       int component[9];
+    } MyArray;
 ~~~
 Now, if arrays a and b are of the same type (or are strings), the pascal  assignment
 ~~~pascal
@@ -91,11 +91,11 @@
 ###types
 a c type declaration reverses the order of a pascal declaration, eg

-   i : ^integer;     ===&amp;gt; int *i;
+     i : ^integer;     ===&amp;gt; int *i;

 This is done by procedure **genCType**

-  r : record .... end;  ==&amp;gt; struct { ... } r;
+    r : record .... end;  ==&amp;gt; struct { ... } r;

 ####but note **arrays**:
 in c, an array is just a pointer, so if arrayA &amp;amp; arrayB are arrays,
@@ -113,8 +113,8 @@
 ~~~
 is translated into the c code
 ~~~c
-struct {
-    int component[10] } arrayA;
+    struct {
+        int component[10] } arrayA;
 ~~~
 so that all components of arrayA can be copied when assigned.

@@ -220,7 +220,7 @@
 ~~~
 might become
 ~~~c
-  int i_1;
+     int i_1;
 ~~~
 This prevents pascal identifiers clashing with c reserved words, and  c can refer to the id at the correct level. (this could otherwise happen in  some pathological cases.)

@@ -276,11 +276,11 @@

 Now when the expression has been completely parsed, p5c can use the tree to generate code. It starts at the root of the tree, ie the string **&amp;lt;** operator node, and knows that it needs to emit something like this:

-*  emit "(strcmp("
-*  emit left child, ie "string1"
-*  emit ", "
-*  emit right child, ie "string2"
-*  emit ") &amp;lt; 0)
+*  emit "`(strcmp(`"
+*  emit left child, ie "`string1`"
+*  emit "`, `"
+*  emit right child, ie "`string2`"
+*  emit "`) &amp;lt; 0)`"

 As previously mentioned, The arguments of the strcmp() function could be arbitrarily complex, and this is easily handled by traversing the left and right children of the tree.

@@ -449,6 +449,7 @@
 ~~~

 **Note** 
+
 - if we say the empty set has a lower bound of maxint and an upper bound of -maxint, these results work as expected for empty sets.

 See the procedure **findResBounds**() for the implementation details.
@@ -671,7 +672,7 @@

           max(i,11) &amp;lt;= min(j,k-1) or max(i,k+1) &amp;lt;= min(j,maxint)

-In the p5c world, we'll refer to this technique as '**analytic comparison**', or **algebraic comparison**.
+In the p5c world, we'll refer to this technique as '**analytic comparison**', or '**algebraic comparison**'.

 **Notes**:

@@ -786,7 +787,7 @@
 The flags member of the file structure has the following values:

 value | meaning 
-----------:| ---------- 
+----------: | ---------- 
 -2  |  the file is a text file in write mode, and                    the current line has not been terminated with an eoln char
 -1   | the file is in write mode
  0    | the file has not yet read the next item into buffer, see note below.
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 02 Jun 2018 22:11:58 -0000</pubDate><guid>https://sourceforge.net6bfd806194a4168a1aa16901e8567998d7a58a80</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v3
+++ v4
@@ -7,6 +7,8 @@
      eg "The C book". avaialable at http://publications.gbdirect.co.uk/c_book/
 * See gcc docs.   gcc has important extensions that are needed by p5c and p5x
 * 
+
+[TOC]

 ##Pascal and C have important differences

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 02 Jun 2018 22:03:33 -0000</pubDate><guid>https://sourceforge.neta6dc09c2162f9b3f91c7fa4d44c9fabafdcaa55b</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -53,9 +53,9 @@
      a := b;
 ~~~
 compiles directly into the corersponding c assignment
- ~~~c
+~~~c
      a = b;
- ~~~
+~~~
 with the results the pascal programmer expects.

@@ -75,14 +75,18 @@

 ##Compiling Declarations:
-=======================
-
-###**labels** are compiled into jump buffers.
+
+
+###labels
+
+**labels** are compiled into jump buffers.
 If a label is used in a subprocedure a jumpbuffer is set up at the start of the procedure.  Otherwise the jump buffer is left unused, and gcc is free to optimise it out.

-###**constant** identifers are kept internal to the compiler, so no corresponding c code is emitted.
-
-###**type declarations**
+###constants
+
+**constant** identifers are kept internal to the compiler, so no corresponding c code is emitted.
+
+###types
 a c type declaration reverses the order of a pascal declaration, eg

    i : ^integer;     ===&amp;gt; int *i;
@@ -113,11 +117,11 @@
 so that all components of arrayA can be copied when assigned.

-####**sets**:
+####sets
 sets are declared in the same way as arrays are.

-####**pointer declarations** are different:
+####pointers

 In pascal, pointers are resolved at the end of the type declaration block to enable recursive data structures.
 In c, recursive data structures are implemented by forward referencing structs.
@@ -183,7 +187,7 @@

        sometype =  ...
 ~~~
-In c, on the other hand sometype must be declared before the pointer to it, and record r2 must be forward declared so r1 can access it.
+In c, on the other hand **sometype** must be declared before the pointer to it, and record r2 must be forward declared so r1 can access it.
 Also colour needs to be declared earlier than r2, so if r2 is moved the colour may need to be moved as well.

 The equivalent c code might be like this:
@@ -206,7 +210,9 @@
 ~~~

-####**identifier names **need to be unique, so the declaration level is appended to the name.  eg for the declaration if an integer declared at the program level,
+####identifiers
+
+**identifier names **need to be unique, so the declaration level is appended to the name.  eg for the declaration if an integer declared at the program level,
 ~~~pascal
      i: integer;
 ~~~
@@ -223,9 +229,10 @@
 gcc allows nested functions, so nested pascal functions are simply compiled into nested c functions.

+=====================================

 ##Code Compilation
-================
+

 This is mostly straight forward.

@@ -236,6 +243,7 @@
 Consequently, the compiler has almost no memory of the code it has just processed and code needs to generated in the same sequence as it is encountered.

 ###expressions become trees
+
 p5 (but not p5c or p5x) produces code for an abstract stack machine.
 So for example, the p5 compiler takes the following steps when compiling the expression
 ~~~pascal
@@ -260,9 +268,9 @@

 So for above example, when p5c find the 'string1' &amp;lt; 'string2' expression, it does this:

-* - encounter 'string1', make a node for 'string1'
-* - encounter &amp;lt;, make a node for &amp;lt; string operator, put node for 'string1' on  left child
-* - encounter 'string2', make a node for 'string2', put onto right child of the  **&amp;lt;** node
+*  encounter 'string1', make a node for 'string1'
+*  encounter &amp;lt;, make a node for &amp;lt; string operator, put node for 'string1' on  left child
+*  encounter 'string2', make a node for 'string2', put onto right child of the  **&amp;lt;** node

 Now when the expression has been completely parsed, p5c can use the tree to generate code. It starts at the root of the tree, ie the string **&amp;lt;** operator node, and knows that it needs to emit something like this:

@@ -295,7 +303,9 @@
 This is easily accomplished if expression trees are used.

-###for loops need careful consideration
+###for loops 
+
+These need careful consideration

   - the end condition must be executed only once
   - the loop variable is assigned only if the loop is entered.
@@ -305,7 +315,7 @@
 ###sets

-sets are not part of the gcc language, so need to be specially implemented some simple optimisations are done, eg p5c may keep lists of const elements and var elements of sets.
+sets are not part of the gcc language, so need to be specially implemented.   Some simple optimisations are done, eg p5c may keep lists of const elements and var elements of sets.

 Sets are implemented with a c struct containing an array of elements:
 ~~~c
@@ -320,7 +330,7 @@
 ~~~
 becomes
 ~~~c
-    setA &amp;amp; ~setB
+        setA &amp;amp; ~setB
 ~~~
 p5c and p5x construct expression trees for sets before generating c code.
 This enables analysis of set expressions for possible efficiencies and to determine how to implement the set operations.
@@ -377,30 +387,33 @@
       if e in s1 + s2 then ...
 ~~~
 is translated into 
-
+~~~pascal
     if (e in s1) or (e in s2) then ...
-
+~~~
 Also 
 ~~~pascal
     e in s1 * s2
 ~~~
 is translated as 
-
+~~~pascal
     (e in s1) and (e in s2)
-
+~~~
 and 
-~~~
+~~~pascal
     e in s1 - s2
 ~~~
 is translated as 
-
+~~~pascal
     (e in s1) and not(e in s2)
-
+~~~
 Since a set expression is represented by a tree, abitrarily complex set expressions on the right hand side of the "**in**" operator can be compiled recursively without needing to construct intermediate sets (whose size we might not know).
 See the function **isMember**() for implementation details.

-####We can also use expression trees to analyse set comparisons.
+####set comparisons
+
+We can also use expression trees to analyse set comparisons.
+
 As the tree is being constructed, each node combines the sizes of its children to form a new size for its result.

 The lower bound of a '+' node (set union) is the minimum of the lower bounds of each of its children.  Similarly, the resulting upper bound is the maximum of the upper bounds of its children.
@@ -409,7 +422,7 @@
     [-12..3] + [8..80]
 ~~~
 are -12 and 80 for the lower and upper bounds respectively as this diagram shows:
-~~~
+~~~none
  left side    --&amp;gt;         [-12................3]
  right side   --&amp;gt;                  [8................................80]
  left + right --&amp;gt;         [-12.......................................80]
@@ -419,7 +432,7 @@
 ~~~pascal
     [ 2..20] * [10..30]
 ~~~
-are [[10..20], as shown here:
+are \[10..20], as shown here:
 ~~~
  left side    --&amp;gt;         [-12................3]
  right side   --&amp;gt;                  [8................................80]
@@ -434,7 +447,7 @@
 ~~~

 **Note** 
-if we say the empty set has a lower bound of maxint and an upper bound of -maxint, these results work as expected for empty sets.
+- if we say the empty set has a lower bound of maxint and an upper bound of -maxint, these results work as expected for empty sets.

 See the procedure **findResBounds**() for the implementation details.

@@ -442,7 +455,9 @@

 What happens next depends on the compare operator.

-#####For equality, we have
+#####set equality
+
+For equality, we have

 ~~~pascal
       setSubExpression1 = setSubExpression2
@@ -458,14 +473,16 @@
     if s1 + [24] = s2 + [15] then
        writeln( 'equal' );
 ~~~
-While the tree for the set expression  s1+[24] tree is being created, the bounds of the left hand side of the = operator are determined to be [0..24], as described above.
-Similarly, the bounds of the set expression s2+15 are [10..50].
-Each side of the **= operator** must now be constructed in a set with bounds [0..50] so that the sets can be compared.
-
-##### set inequality,
+While the tree for the set expression  `s1+[24]` tree is being created, the bounds of the left hand side of the = operator are determined to be` [0..24]`, as described above.
+Similarly, the bounds of the set expression `s2+15` are `[10..50]`.
+Each side of the **= operator** must now be constructed in a set with bounds `[0..50]` so that the sets can be compared.

 For set inequality, ie &amp;lt;&amp;gt;,  the bound calculations are similar.

+
+##### set inclusion
+
+
 For set inclusion, we might have
 ~~~pascal
       setSubExpression1 &amp;lt;= setSubExpression2
@@ -478,7 +495,7 @@
 ~~~
 where all the varaibles have values that are unknown at compile time.

-We know the size of expressions like `[x..y]`, ie `-maxint..maxint`, but this set cannot be implemented in practice.  At this point, the compiler issues a warning and uses a default set size of [-255..255].
+We know the size of expressions like `[x..y]`, ie `-maxint..maxint`, but this set cannot be implemented in practice.  At this point, the compiler issues a warning and uses a default set size of `[-255..255]`.

 If this is not suitable, there are a number of options:

@@ -492,9 +509,9 @@

 - Alternatively, assign the expressions to a set of suitable size, eg

-      s1 := [i,j,k];
-      s2 := [m..n];
-      if s1 = s2 then ...   { now the compiler can use the correct size sets }
+         s1 := [i,j,k];
+         s2 := [m..n];
+         if s1 = s2 then ...   { now the compiler can use the correct size sets }

   If the set size implied by these options is impossibly large, you may need to consider the `{$Z+}` compiler option described below.

@@ -530,15 +547,15 @@
 is in error if either s1 or s2 has an element that is out of bounds.
 In other words, set expressions that are unions can be split up and examined individually.  So our **isNonEmpty** function doesn't need to consider the set **+ operator** when it is at the top level.

-When there is a set + operators at lower a level in the expression tree, we can use the rule:
-
-   (s1+s2)*s3 = s1*s3 + s2*s3
+When there is a set + operators at lower a level in the expression tree, we can use the **associative** rule:
+
+         (s1+s2)*s3 = s1*s3 + s2*s3

 We can repeat this rule as often as necessary to move all + operators to the top level of the set expression.

 It is beginning to look like our **isNonEmpty** function needs to examine terms like `s1*s2` to see if they produce any elements inside the specified range.

-But what about the set **- operator**?  Recall that s1 - s2 is implemented as
+But what about the set **- operator**?  Recall that `s1 - s2` is implemented as

      s1 * ~s2

@@ -548,17 +565,17 @@

 So if the bounds of s2 are m..n, and isNonEmpty is considering the range  r0..r1, then s1 - s2 becomes

-    s1*( sa + sb + sc)
+     s1*( sa + sb + sc)

 where

-    sa = [r0 .. m]
-    sb = ~s2
-    sc = [n .. r1]
+     sa = [r0 .. m]
+     sb = ~s2
+     sc = [n .. r1]

 We can now see that the **plus operators** in this expression can be moved to the top of the expression tree, and that any set expression can be rewritten as a **union of terms**, ie

-    sa*sb*sc...*sz  + ssa*ssb*...
+      sa*sb*sc...*sz  + ssa*ssb*...

 Our **isNonEmpty** function needs to determine whether any of these terms produce an elemnt in the specified range.  

@@ -568,12 +585,12 @@

           max(low bounds of each set in the term)

-   and similarly the high limit is 
+     and similarly the high limit is 

        min(high bounds of each set in the term)
-   In many cases, the low limit will be greater than the high bound, so there    is nothing to do.
+     In many cases, the low limit will be greater than the high bound, so there    is nothing to do.

- - many of the terms are of the form `[a..b]`, so apart from contributing to the    low &amp;amp; high limits of the term, they need no further consideration.
+ - many of the terms are of the form `[a..b]`, so apart from contributing to the    low &amp;amp; high limits of the term, they need no further consideration. 
         (  `[a..b] * s = s`  inside these limits)

 Some of this analysis can be done at compile time, some needs to be done at run time, but after all this we can now catch set assignment errors.
@@ -602,7 +619,7 @@

      [i..j] - [k]  =  [i..j] * /[k]

-  where     `/[k]` is the inverse of [k].  This is `[-maxint..k-1, k+1..maxint]`, but     here we are considering only the range 11..maxint, so
+  where     `/[k]` is the inverse of `[k]`.  This is `[-maxint..k-1, k+1..maxint]`, but     here we are considering only the range `11..maxint`, so

                /[k] = [11..k-1, k+1..maxint]

@@ -614,7 +631,7 @@
 So if the range `i..j` intersects the range `11..k-1`, or if` i..j` intersects `k+1..maxint`, then the expression is non-empty.  That is, the region above the upper bound of s1 is occupied and there is an error in statement (1) above.
 eg, if i is 6 and j and k are both 11, statement (1) is

-    s1 := [6..11] - [11];
+                      s1 := [6..11] - [11];

 which is OK.

@@ -626,7 +643,7 @@

 On the other hand, if both j and k are now 12, statement (1) is

-    s1 := [6..12] - [12];
+                       s1 := [6..12] - [12];

 which is in error because element 11 cannot legally be assigned to s1.

@@ -634,15 +651,15 @@

                       [6..12]*[11..11] + [6..12]*[13..maxint]

-which reduces to [11] + [] statement (1) is in error.
+which reduces to `[11] + []` and  statement (1) is in error.

 Returning to equation (2) above, we consider the term on each side of the plus operator separately. Since each term is just the intersection of 2 ranges, the result is another range whose lower limit is 

-   max(lower limit of each range)
+      max(lower limit of each range)

  and higher limit is 

-   min(higher limit of each range)
+      min(higher limit of each range)

 The result is

@@ -684,7 +701,7 @@

 Note also that the set expression 

-    a=b
+            a=b

  is equivalent to

@@ -767,7 +784,7 @@
 The flags member of the file structure has the following values:

 value | meaning 
----------- | ---------- 
+----------:| ---------- 
 -2  |  the file is a text file in write mode, and                    the current line has not been terminated with an eoln char
 -1   | the file is in write mode
  0    | the file has not yet read the next item into buffer, see note below.
@@ -786,7 +803,7 @@

           f1 := f2

-   You can, however, pass a file variable to a procedure (or function) as a    **var** parameter since this is passing the variable itself, not making a new   copy.
+      You can, however, pass a file variable to a procedure (or function) as a    **var** parameter since this is passing the variable itself, not making a new   copy.

  - file variables must be able to represent "no file attached"

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 02 Jun 2018 22:02:47 -0000</pubDate><guid>https://sourceforge.net91724fadd05b4775a256ccc5918fbe5db791f426</guid></item><item><title>implementation notes modified by Trevor Blight</title><link>https://sourceforge.net/p/pascal-p5c/wiki/implementation%2520notes/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -14,12 +14,12 @@
 Pascal has strong typing so is able to find more errors at compilation time rather than at run time, etc, etc

 Both have a similar approach to data &amp;amp; code, so much Pascal data code translates directly to c:, eg
-
+~~~none
     integer       --&amp;gt; int,
     record        --&amp;gt; struct
     while         --&amp;gt; while
     function f(x) --&amp;gt; f(x)
-
+~~~
 There are, however, enough differences to prevent simple direct compilation:

@@ -36,7 +36,7 @@
 ~~~c
    array1[1] = 5
 ~~~
-also sets array2[1] to 5.
+also sets `array2[1]` to 5.

 p5c and p5x work around this by wrapping all arrays inside structs, so a pascal array declaration:
 ~~~pascal
@@ -50,8 +50,8 @@
 ~~~
 Now, if arrays a and b are of the same type (or are strings), the pascal  assignment
 ~~~pascal
-     a:= b;
- ~~~
+     a := b;
+~~~
 compiles directly into the corersponding c assignment
  ~~~c
      a = b;
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Trevor Blight</dc:creator><pubDate>Sat, 02 Jun 2018 21:39:26 -0000</pubDate><guid>https://sourceforge.net0f2c3b31a3fe89ed6f2bde8e0459749bd3d66691</guid></item></channel></rss>