General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
FunnelWebInput Processing
Special SequencesThe scanner scans the input file from top to bottom, left to right, treating the input as ordinary text (to be handed directly to the parser as a text token) unless it encounters the special character which introduces a special sequence. Thus, the scanner partitions the input file into ordinary text and special sequences. (The control character is often referred to as the escape character or the control character in other systems. However, as there is great potential to confuse these names with the escape character (ASCII 27) and ASCII control characters, the term special has been chosen instead. This results in the terms special character and special sequence.)
input_file ::= {ordinary_text / special_sequence} .
Upon startup, the special character
is An occurrence of the special character in the input file introduces a special sequence. The kind of special sequence is determined by the character following the special character. Only printable characters can follow the special character.
The following table gives all the possible characters that can follow
the special character, and the legality of each sequence. The item
headings give the ASCII number of each ASCII character and the special
sequence for that character. The descriptions start with one of three
characters:
The most important thing to remember about the scanner is that nothing happens unless the special character is seen. There are no funny sequences that will cause strange things to happen. The best way to view a FunnelWeb document at the scanner level is as a body of text punctuated by special sequences that serve to structure the text at a higher level. The remaining description of the scanner consists of a detailed description of the effect of each complex special sequence. Setting the Special Character
The special character can be set using the sequence
<special> Inserting the Special Character into the Text
The special sequence <special> Inserting Arbitrary Characters into the Text
While FunnelWeb does not tolerate unprintable characters in the input
file (except for the end of line character and the tabs that Eli expands
into spaces), it does allow the user to specify that unprintable
characters appear in the product file. The
control_sequence ::= `@^' char_spec . char_spec ::= binary / octal / decimal / hexadecimal . binary ::= (`b' / `B') `(' {binary_digit}8 `)' . octal ::= (`o' / `O' / `q' / `Q') `(' {octal_digit}3 `)' . decimal ::= (`d' / `D') `(' {decimal_digit}3 `)' . hexadecimal ::= (`h' / `H' / `x' / `X') `(' {hex_digit}2 `)' . binary_digit ::= `0' / `1' . octal_digit ::= binary_digit / `2' / `3' / `4' / `5' / `6' / `7' . decimal_digit ::= octal_digit / `8' / `9' . hex_digit ::= decimal_digit / `A' / `B' / `C' / `D' / `E' / `F' / `a' / `b' / `c' / `d' / `e' / `f' . Example:
@! Unix Make requires that productions commence with tab characters. @^D(009)prog.o <- prog.c
Note that the decimal
FunnelWeb treats the character resulting from a
@! Unix "Make" requires that productions commence with tab characters. @! So we define a macro with a quick name as a tab character. @$@#T@{@^D(009)@} @! And use it in our productions. @#Tprog.o <- prog.c @#Ta.out <- prog.o Warning: If you insert a Unix newline character (decimal 10) into the text, FunnelWeb will treat this as an end of line sequence regardless of what the character sequence for end of line is on the machine upon which it is running. Unix EOL is FunnelWeb's internal representation for end of line. Thus, in the current version of FunnelWeb, inserting character 10 into the text is impossible unless this also happens to be the character used by the operating system to mark the end of line. Comments
When FunnelWeb encounters the FunnelWeb comments can be used to insert comments into your input file that will neither appear in the product files nor in the documentation file, but will be solely for the benefit of those reading and editing the input file directly. Example:
@! I have used a quick macro for this definition as it will be used often. @$@#C@{--@} Because comments are defined to include the end-of-line marker, care must be taken when they are being added or removed within the text of macro bodies. For example the text fragment
for (i=0;i<MAXVAL;i++) @! Print out a[0..MAXVAL-1]. printf("%u\n",a[i]);will expand to
for (i=0;i<MAXVAL;i++) printf("%u\n",a[i]); This problem really has no solution; if FunnelWeb comments were defined to omit the end of line marker, the expanded text would contain trailing blanks! As it is, FunnelWeb comments are designed to support single line comments which can be inserted and removed as a line without causing trouble. For example:
@! Print out a[0..MAXVAL-1]. for (i=0;i<MAXVAL;i++) printf("%u\n",a[i]);
If you want a comment construct that does not enclose the end of line
marker, combine the insert end of line construct
for (i=0;i<MAXVAL;i++) @+@! Print out a[0..MAXVAL-1]. printf("%u\n",a[i]); FunnelWeb comments should really only be used to comment the FunnelWeb constructs being used in the input file. Comments on the target code are best placed in comments in the target language or in the documenting text surrounding the macro definitions. In the example above, a C comment would have been more appropriate. Quick Names
FunnelWeb provides a quick name syntax as an alternative, for
macros whose name consists of a single character, to the angle bracket
syntax usually used (eg.
quick_name ::= `@#' non_space_printable .
The result is identical to the
equivalent ordinary name syntax, but is
shorter. For example,
@! Define @<D@> as "" to turn on debug code and "--" to turn it off. @$@<D@>@{--@} @<D@>assert(b>3); @<D@>if x>7 then write("error") end if The calls can be shortened using the alternative syntax.
@! Define @#| as "" to turn on debug code and "--" to turn it off. @$@#|@{--@} @#|assert(b>3); @#|if x>7 then write("error") end if Inserting End of Line Markers
An end of line marker/character can be inserted into the text using the
Animal = Kangaroo Size = Medium Speed = Fast Animal = Sloth Size = Medium Speed = Slow Animal = Walrus Size = Big Speed = Mediumcan be converted into
Animal = Kangaroo @+Size = Medium @+Speed = Fast @+ Animal = Sloth @+Size = Medium @+Speed = Slow @+ Animal = Walrus @+Size = Big @+Speed = Medium @+which is easier to read, and more easily allows comparisons between records. Suppressing End of Line Markers
End of line markers can be suppressed by the
@$@<Walrus@>@{@- I am the walrus!@}is equivalent to
@$@<Walrus@>@{I am the walrus!@}
The comment construct ( Include Files
FunnelWeb provides an include file facility with a maximum depth of 10.
When FunnelWeb sees a line of the form
The
"Uh Oh, It's the Fuzz. We're busted!" said Baby Bear. @i mr_plod.txt "Quick! Flush the stash down the dunny and let's split." said Father Bear.and there is a file called `mr_plod.txt' containing
"'Ello, 'Ello, 'Ello! What's all this 'ere then?" Mr Plod exclaimed.then the scanner translates the input file into
"Uh Oh, It's the Fuzz. We're busted!" said Baby Bear. "'Ello, 'Ello, 'Ello! What's all this 'ere then?" Mr Plod exclaimed. "Quick! Flush the stash down the dunny and let's split." said Father Bear. As a point of terminology, FunnelWeb calls the original input file the input file and calls include files and their included files include files. The include file construct operates at a very low level. An include line can appear anywhere in the input file regardless of the context of the surrounding lines.
FunnelWeb sets the special character to the default ( Maximum Input Line LengthFunnelWeb generates an error for each input line that exceeds a certain maximum number of characters. At the start of the processing of each input file and each include file, this maximum is set to a default value of 80. However, the maximum can be changed using a maximum input line length pragma.
pragma_mill ::= ps `maximum_input_line_length' s `=' s numorinf . ps ::= (`@p' / `@P') ` ' . number ::= { decimal_digit }+ . numorinf ::= number / `infinity' . s ::= {` '}+ . The maximum input line length can be varied dynamically throughout the input file. Each maximum input line length pragma's scope covers the line following the pragma through to and including the next maximum input line length pragma, but not covering any intervening include files. At the start of an include file, FunnelWeb resets the maximum input line length to the default value. It restores it to its previous value at the end of the include file. This pragma is useful for detecting text that has strayed off the right side of the screen when editing. If you use FunnelWeb, and set the maximum input line length to be the width of your editing window, you will never be caught by, for example, off-screen opening comment symbols. You can also be sure that your source text can be printed raw, if necessary, without lines wrapping around.
|