rthornton128 / calc

BSD 2-Clause "Simplified" License
65 stars 12 forks source link

function declarations are normal expressions #15

Closed rthornton128 closed 10 years ago

rthornton128 commented 10 years ago

Current spec allows for function declarations to occur anywhere. Functions should be declared only at the top scope of the file; OR, special conditions must be set to use them in a nested fashion.

(decl func int (decl another int)) - is currently legal but pointless. (var (= a (decl add (a b) int (+ a b)))) - is also currently legal. This is, essentially, an assignment to a function pointer but no such mechanism actually exists in the language at this point in time and is well beyond the scope of this iteration of the language.

For Calc 2, the specification should state that function declarations may only occur at the top level of the file scope. A field 'level' can be added to the parser which would be incremented when a 'decl' keyword is found. If 'level' is > 0, and another 'decl' keyword is encountered, the parser should generate an error.

rthornton128 commented 10 years ago

Spec updated to reflect changes - functions may only be declared at top-level scope