java.lang.Object
simula.compiler.parsing.DefaultScanner
simula.compiler.parsing.SimulaScanner
The Simula Scanner.
Link to GitHub: Source File.
- Author:
- Øystein Myhre Andersen
-
Field Summary
Modifier and TypeFieldDescriptionprivate StringBuilder
StringBuilder used to accumulate input strings for Simula Editor.private int
The current character read.private final boolean
Editor mode.private static final int
ISO EM(EndMedia) character used to denote end-of-inputprivate boolean
Set 'true' when EOF-character ( -1 ) was read.private int
NOTE: An initial "-" in array upper bound may follow : directly (cf. 1.3).private int
The previous character read.The pushBack stackstatic boolean[]
The selector array.(package private) SourceFileReader
The current source file reader;private LinkedList
<Token> The Token queue. -
Constructor Summary
ConstructorDescriptionSimulaScanner
(Reader reader, boolean editorMode) Constructs a new SimulaScanner that produces Items scanned from the specified source. -
Method Summary
Modifier and TypeMethodDescription(package private) void
close()
Close the scanner.private boolean
Scanner Utility: Check if current is a string separator.private String
Utility: Edit current character.private int
getNext()
Returns next input character.private Token
identifierToken
(String name) Scanner Utility: Create an identifier Token.(package private) void
Insert a file.private boolean
isHexDigit
(int c) Utility: Check if a character is a hex digit.private boolean
isPrintable
(int c) Utility: Check if a character is printable.private boolean
isWhiteSpace
(int c) Utility: Check if a character is a whiteSpace.private Token
javaKeyword
(String name) Scanner Utility: Create an Java-name Token.private boolean
Determine if current line is selected.private Token
Create a new Token without a valueprivate Token
Create a new TokenReturns the next Token.private void
pushBack
(int chr) Push a character onto the puchBackStack.private void
Push a string onto the puchBackStack.private String
Utility: Read until end-of-line.private Token
Scan basic Tokenprivate Token
Scan and deliver a Character constant.private Token
Scan a Comment.private Token
Scan Comment to end-of-line.private Token
scanDigitsExp
(StringBuilder number) Scan exponent-part.private Token
Scan a %Directive lineprivate Token
scanDotDigit
(StringBuilder number) Scan decimal-fraction possibly followed by an exponent-part.private Token
Scan end-comment.private Token
Scan and return an identifier Token.private String
scanName()
Scan identifier or reserved name.private Token
Scan a unsigned number.private int
Scanner Utility: Scan possible iso-codeprivate Token
Scan and deliver a Text constant.private Token
Scan and return a Token.private void
%SELECT select-character { select-character }
-
Field Details
-
EOF_MARK
private static final int EOF_MARKISO EM(EndMedia) character used to denote end-of-input- See Also:
-
EOF_SEEN
private boolean EOF_SEENSet 'true' when EOF-character ( -1 ) was read. -
puchBackStack
The pushBack stack -
accum
StringBuilder used to accumulate input strings for Simula Editor. -
editorMode
private final boolean editorModeEditor mode. Set when the scanner is used by Simula Editor -
tokenQueue
The Token queue. The method nextToken will pick Tokens from the queue first. -
sourceFileReader
SourceFileReader sourceFileReaderThe current source file reader; -
selector
public static boolean[] selectorThe selector array. -
pardepth
private int pardepthNOTE: An initial "-" in array upper bound may follow : directly (cf. 1.3). The scanner will treat ":-" within parentheses (round brackets) as two separate symbols ":" and "-" thus solving this ambiguity in the syntax.This variable is used to cover such situations.
-
prevChar
private int prevCharThe previous character read. -
current
private int currentThe current character read.
-
-
Constructor Details
-
SimulaScanner
Constructs a new SimulaScanner that produces Items scanned from the specified source.- Parameters:
reader
- The character source to scaneditorMode
- true: delivers tokens to the SimulaEditor
-
-
Method Details
-
insert
Insert a file.- Parameters:
file
- the file to be inserted
-
close
void close()Close the scanner. -
nextToken
Description copied from class:DefaultScanner
Returns the next Token.- Overrides:
nextToken
in classDefaultScanner
- Returns:
- the next Token
-
scanToken
Scan and return a Token.End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- next Token
-
scanBasic
Scan basic Token- Returns:
- next Token
-
javaKeyword
Scanner Utility: Create an Java-name Token.- Parameters:
name
- the Token's Java-name- Returns:
- an identifier Token
-
identifierToken
Scanner Utility: Create an identifier Token.- Parameters:
name
- the Token's name- Returns:
- an identifier Token
-
scanIdentifier
Scan and return an identifier Token.End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- next Token
-
scanNumber
Scan a unsigned number.Reference-Syntax: unsigned-number = decimal-number [ exponent-part ] | exponent-part decimal-number = unsigned-integer [ decimal-fraction ] | decimal-fraction decimal-fraction = . unsigned-integer exponent-part = ( & | && ) [ + | - ] unsigned-integer unsigned-integer = digit { digit | _ } | radix R radix-digit { radix-digit | _ radix-digit } radix = 2 | 4 | 8 | 16 radix-digit = digit | A | B | C | D | E | F
End-Condition:- current is last character of construct
- getNext will return first character after construct
- Returns:
- A Token representing a unsigned number.
-
scanDotDigit
Scan decimal-fraction possibly followed by an exponent-part. And append it to the given number.Reference-Syntax: decimal-fraction = . unsigned-integer End-Condition: current is last character of construct getNext will return first character after construct
- Parameters:
number
- The edited number so far- Returns:
- next Token
-
scanDigitsExp
Scan exponent-part. And append it to the given number.Reference-Syntax: exponent-part = ( & | && ) [ + | - ] unsigned-integer
Pre-Condition: First & is already read End-Condition: current is last character of construct getNext will return first character after construct- Parameters:
number
- The edited number so far- Returns:
- next Token
-
scanName
Scan identifier or reserved name.Reference-Syntax: identifier = letter { letter | digit | _ } End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- the resulting identifier
-
scanCharacterConstant
Scan and deliver a Character constant.Reference-Syntax: character-constant = ' character-designator ' character-designator = iso-code | non-quote-character | " iso-code = ! digit [ digit ] [ digit ] ! End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- next Token
-
scanTextConstant
Scan and deliver a Text constant.Reference-Syntax: string = simple-string { string-separator simple-string } simple-string = " { iso-code | non-quote-character | "" } " iso-code = ! digit [ digit ] [ digit ] ! string-separator = token-separator { token-separator } token-separator = a direct comment | a space { except in simple strings and character constants } | a format effector { except as noted for spaces } | the separation of consecutive lines End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- next Token
-
currentIsStringSeparator
private boolean currentIsStringSeparator()Scanner Utility: Check if current is a string separator.Reference-Syntax: string-separator = token-separator { token-separator } token-separator = a direct comment | a space { except in simple strings and character constants } | a format effector { except as noted for spaces } | the separation of consecutive lines End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- true if current is a string separator
-
scanPossibleIsoCode
private int scanPossibleIsoCode()Scanner Utility: Scan possible iso-codeReference-Syntax: iso-code = ! digit [ digit ] [ digit ] ! Pre-Condition: The leading character ! is already read End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- the resulting iso-code
-
scanDirectiveLine
Scan a %Directive lineReference-Syntax: directive = % { any character except end-of-line } A conditional line takes the form: %selector-expression text-line where text-line represents the line to be conditionally included and the selector-expression has the form: Selector-expression = selector-group { selector-group } Selector-group = + letter_or_digit { letter_or_digit } | - letter_or_digit { letter_or_digit } i.e. a string of letters and signs, with the first character being a sign. The selector-expression is terminated by a SPACE. End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- a Comment Token
-
readUntilEndofLine
Utility: Read until end-of-line.- Returns:
- the string read
-
setSelectors
private void setSelectors()%SELECT select-character { select-character }Set selectors for conditional compilation.
-
lineSelected
private boolean lineSelected()Determine if current line is selected.- Returns:
- true if current line is selected
-
scanComment
Scan a Comment.Reference-Syntax: comment = COMMENT { any character except semicolon } ; End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- a Comment Token
-
scanCommentToEndOfLine
Scan Comment to end-of-line.Reference-Syntax: comment = -- { any character until end-of-line } End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- a Comment Token
-
scanEndComment
Scan end-comment.reference-Syntax: The sequence: END { any sequence of printable characters not containing END, ELSE, WHEN, OTHERWISE or ; } is equivalent to: END End-Condition: current is last character of construct getNext will return first character after construct
- Returns:
- next Token
-
getNext
private int getNext()Returns next input character.- Returns:
- next input character
-
pushBack
private void pushBack(int chr) Push a character onto the puchBackStack.- Parameters:
chr
- character to be pushed
-
pushBack
Push a string onto the puchBackStack.- Parameters:
s
- string to be pushed
-
newToken
Create a new Token- Parameters:
keyWord
- the KeyWordvalue
- the value- Returns:
- the newly created Token
-
newToken
Create a new Token without a value- Parameters:
keyWord
- the KeyWord- Returns:
- the newly created Token
-
edcurrent
Utility: Edit current character.- Returns:
- edited current character
-
isHexDigit
private boolean isHexDigit(int c) Utility: Check if a character is a hex digit.- Parameters:
c
- the character- Returns:
- true if character c is a hex digit
-
isPrintable
private boolean isPrintable(int c) Utility: Check if a character is printable.- Parameters:
c
- the character- Returns:
- true if character c is printable
-
isWhiteSpace
private boolean isWhiteSpace(int c) Utility: Check if a character is a whiteSpace.- Parameters:
c
- the character- Returns:
- true if character c is a whiteSpace
-