Splaf  Check-in [2ef952be95]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added square root function.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2ef952be951a39a09f01156fca6af5ef7033d268
User & Date: emanuel.angelo@gmail.com 2012-10-16 19:41:23.000
Context
2012-10-16
23:22
Added two more variations for the I/O functions. check-in: 4277aea5f8 user: emanuel.angelo@gmail.com tags: trunk
19:41
Added square root function. check-in: 2ef952be95 user: emanuel.angelo@gmail.com tags: trunk
19:24
Added alternative functions for I/O ("ler" and "escrever"). check-in: b0380d17ef user: emanuel.angelo@gmail.com tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to .todo.done.
1
2
3
4
5
6
7
8

9
10
Add boolean variables and statements. | id:179a08af0f88c71e4925c7a50272345b46484de1
Add >=, <=, ==, logical AND, OR and NOT to the grammar | id:274f8bc44e3e6ee7b161d4b522dee61149449e83
Implement parser | id:555828ffa4e59f1ea30d47ace4993ff44475804a
Flowchart automatic construction from the structured language | id:765757bbdeb83d6200c099b9fa756b2323df467c
Saving to server | id:90cc94f0b58513cf08bba408ec8f70ca4585cdaf
Implement the if statement in the interpreter | id:9633335540f23eddbf08018bd7dfb5487c16ff9c
Loading from server | id:9863ee827ab9625d9a0716f03076ee4d3fec613d
Optimize parser by getting rid of scopes | id:af510b25ed70685884d69869eb4c0ccb7334b2b1

Add alternative functions for I/O ("ler" and "escrever"). | id:e058eb5693c76cf293e91b5a4b0507da1ea62bb1
Implement interpreter | id:f2d35003e89eaf78ecfd7d0acc6b782cebcd2396








>


1
2
3
4
5
6
7
8
9
10
11
Add boolean variables and statements. | id:179a08af0f88c71e4925c7a50272345b46484de1
Add >=, <=, ==, logical AND, OR and NOT to the grammar | id:274f8bc44e3e6ee7b161d4b522dee61149449e83
Implement parser | id:555828ffa4e59f1ea30d47ace4993ff44475804a
Flowchart automatic construction from the structured language | id:765757bbdeb83d6200c099b9fa756b2323df467c
Saving to server | id:90cc94f0b58513cf08bba408ec8f70ca4585cdaf
Implement the if statement in the interpreter | id:9633335540f23eddbf08018bd7dfb5487c16ff9c
Loading from server | id:9863ee827ab9625d9a0716f03076ee4d3fec613d
Optimize parser by getting rid of scopes | id:af510b25ed70685884d69869eb4c0ccb7334b2b1
Add function to calculate square root. | id:c86d8826f4917c7f3b901e91e3841208bc7ca333
Add alternative functions for I/O ("ler" and "escrever"). | id:e058eb5693c76cf293e91b5a4b0507da1ea62bb1
Implement interpreter | id:f2d35003e89eaf78ecfd7d0acc6b782cebcd2396
Changes to grammars/pt.grammar.
22
23
24
25
26
27
28

29
30
31
32
33
34
35

functionname "nome de função"
  = "diz"
  / "enquanto"
  / "escrever"
  / "ler"
  / "pede"

  / "se"

reserved "reservado"
  = functionname
  / "começa"
  / "e"
  / "então"







>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

functionname "nome de função"
  = "diz"
  / "enquanto"
  / "escrever"
  / "ler"
  / "pede"
  / "raiz_quadrada"
  / "se"

reserved "reservado"
  = functionname
  / "começa"
  / "e"
  / "então"
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  / "for diferente de"
  / "é diferente de"
  / "diferente de"
  / "não for"
  / "não é"

UnitaryExpression "expressão unitária"
  = op:(NotOperator / "-") _ operand:(UnitaryExpression / primary) {
      return { 
        type: "unaryop", 
        operator: op, 
        arg: operand 
      }
    }
  / primary







|







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  / "for diferente de"
  / "é diferente de"
  / "diferente de"
  / "não for"
  / "não é"

UnitaryExpression "expressão unitária"
  = op:(NotOperator / "-" / "raiz_quadrada") _ operand:(UnitaryExpression / primary) {
      return { 
        type: "unaryop", 
        operator: op, 
        arg: operand 
      }
    }
  / primary
Changes to interpreter.js.
35
36
37
38
39
40
41
42
43
44
45



46
47
48
49
50
51
52
    },

    "unaryop": function(node) {
      var arg = EvalNode[node.arg.type](node.arg)
      if (node.operator === "não é verdade que"
          || node.operator === "não for verdade que"
          || node.operator === "não") {
        return !arg;
      }
      else if (node.operator === "-") {
        return -arg



      }
    },

    "binaryop": function(node) {
      var left = EvalNode[node.args[0].type](node.args[0])
      var right = EvalNode[node.args[1].type](node.args[1])
      if (node.operator === "+") {







|



>
>
>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    },

    "unaryop": function(node) {
      var arg = EvalNode[node.arg.type](node.arg)
      if (node.operator === "não é verdade que"
          || node.operator === "não for verdade que"
          || node.operator === "não") {
        return !arg
      }
      else if (node.operator === "-") {
        return -arg
      }
      else if (node.operator === "raiz_quadrada") {
        return Math.sqrt(arg)
      }
    },

    "binaryop": function(node) {
      var left = EvalNode[node.args[0].type](node.args[0])
      var right = EvalNode[node.args[1].type](node.args[1])
      if (node.operator === "+") {
Changes to parser.js.
325
326
327
328
329
330
331
332
333
334
335
336
337










338

339
340
341
342
343
344
345
                } else {
                  result0 = null;
                  if (reportFailures === 0) {
                    matchFailed("\"pede\"");
                  }
                }
                if (result0 === null) {
                  if (input.substr(pos, 2) === "se") {
                    result0 = "se";
                    pos += 2;
                  } else {
                    result0 = null;
                    if (reportFailures === 0) {










                      matchFailed("\"se\"");

                    }
                  }
                }
              }
            }
          }
        }







|
|
|



>
>
>
>
>
>
>
>
>
>
|
>







325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
                } else {
                  result0 = null;
                  if (reportFailures === 0) {
                    matchFailed("\"pede\"");
                  }
                }
                if (result0 === null) {
                  if (input.substr(pos, 13) === "raiz_quadrada") {
                    result0 = "raiz_quadrada";
                    pos += 13;
                  } else {
                    result0 = null;
                    if (reportFailures === 0) {
                      matchFailed("\"raiz_quadrada\"");
                    }
                  }
                  if (result0 === null) {
                    if (input.substr(pos, 2) === "se") {
                      result0 = "se";
                      pos += 2;
                    } else {
                      result0 = null;
                      if (reportFailures === 0) {
                        matchFailed("\"se\"");
                      }
                    }
                  }
                }
              }
            }
          }
        }
1189
1190
1191
1192
1193
1194
1195











1196
1197
1198
1199
1200
1201
1202
            result0 = "-";
            pos++;
          } else {
            result0 = null;
            if (reportFailures === 0) {
              matchFailed("\"-\"");
            }











          }
        }
        if (result0 !== null) {
          result1 = parse__();
          if (result1 !== null) {
            result2 = parse_UnitaryExpression();
            if (result2 === null) {







>
>
>
>
>
>
>
>
>
>
>







1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
            result0 = "-";
            pos++;
          } else {
            result0 = null;
            if (reportFailures === 0) {
              matchFailed("\"-\"");
            }
          }
          if (result0 === null) {
            if (input.substr(pos, 13) === "raiz_quadrada") {
              result0 = "raiz_quadrada";
              pos += 13;
            } else {
              result0 = null;
              if (reportFailures === 0) {
                matchFailed("\"raiz_quadrada\"");
              }
            }
          }
        }
        if (result0 !== null) {
          result1 = parse__();
          if (result1 !== null) {
            result2 = parse_UnitaryExpression();
            if (result2 === null) {
Changes to todo.
1
2
3
4
5
6
7
8
9
Implement addEventListener with jQuery | id:198c5890a8c7b8d3ec69fc4f52485bc29d937b98
Convert verbose operators into compact ones in the flowchart. | id:282849e19d7c03287572c6ae311de1c1befd9dd7
Verify if source code was modified and warn user on actions that will discard those modifications | id:3bcb598ee0495084dd3881c550fee2e9099637d1
Flowchart editing infrastructure | id:4fd44559f6ef158c5652620ef58259427335578a
Structured language automatic writing from the flowchart editing actions | id:70c70f55ad67c1d3b305d21c30da459b18fa509a
Add arrows to connection lines | id:a21b2d395b3a9f155805347576f4974559618312
Use indentation to define blocks of statements. | id:c6e1342a5193a60399f945977b5482e30f14bba4
Add function to calculate square root. | id:c86d8826f4917c7f3b901e91e3841208bc7ca333
jQuerify the saveFile function in splaf.js | id:f0ae11338c032544edcfa32768321498262c7328







<

1
2
3
4
5
6
7

8
Implement addEventListener with jQuery | id:198c5890a8c7b8d3ec69fc4f52485bc29d937b98
Convert verbose operators into compact ones in the flowchart. | id:282849e19d7c03287572c6ae311de1c1befd9dd7
Verify if source code was modified and warn user on actions that will discard those modifications | id:3bcb598ee0495084dd3881c550fee2e9099637d1
Flowchart editing infrastructure | id:4fd44559f6ef158c5652620ef58259427335578a
Structured language automatic writing from the flowchart editing actions | id:70c70f55ad67c1d3b305d21c30da459b18fa509a
Add arrows to connection lines | id:a21b2d395b3a9f155805347576f4974559618312
Use indentation to define blocks of statements. | id:c6e1342a5193a60399f945977b5482e30f14bba4

jQuerify the saveFile function in splaf.js | id:f0ae11338c032544edcfa32768321498262c7328