Download PHOEBE Scripter API
Transcript
2 GENERAL PROPERTIES
All line editing capabilities and history management are supported by
this library. If the library is not installed, the scripter will support only
simplest line editing features.
Since the parser is insensitive to whitespaces (including newlines), the
scripter must not evaluate the line until a statement is complete. This is
done automatically by the lexer: whenever a block start is encountered,
the scripter scope increases by 1; whenever a block end is encountered, it
decreases by 1. When it reaches 0, all input lines are concatenated and
evaluated as a single statement. Consider the following example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> for (i=1; i<=2; i++)
PHOEBE scripter: syntax error
> for (i=1; i<=2; i++) {
1> for (j=1; j<=2; j++) {
2> print "This is scope 2"
2> }
1> print "This is scope 1"
1> }
This is scope 2
This is scope 2
This is scope 1
This is scope 2
This is scope 2
This is scope 1
> # Back in prompt
We defer the explanation of the used directives to later sections. Numbers 1–15 on the left represent line numbers and are added for reference
only, they are not a part of the scripter output.
Right now we want to focus our attention to scoping. As you see, the
first for entry (line 1) fails because the parser expects a block to supersede
the read input. Since a line ends before the ’{’ delimeter is encountered,
syntax error is reported (line 2).
A second for entry (line 3) is accepted since a block delimeter ’{’ is
encountered and the scope level is increased by 1. To facilitate the user’s
task of counting scopes, current scope level is printed in the prompt – note
’1>’ and ’2>’ in lines 4–8.
A third for entry (line 4) opens a new block and thus increases the
PHOEBE Scripter API
7