It contains all static utilities for parsing Simula Syntax.
The Simula Compiler uses Recursive Descent Parsing. Each syntax class is a subclass of this class.
A NonTerminal object represents non terminal symbol in the formal syntax.
Parsing descends in a top-down manner, until the final nonterminal has been processed. The parsing process depends on a global variable, currentToken, which contains the current symbol from the input, and the function nextToken, which updates currentToken when called.
For further description of Recursive Descent Parsing see Wikipedia.
*********************************************************************** META-SYNTAX: MetaSymbol Meaning = is defined to be | alternatively [ x ] 0 or 1 instance of x { x } 0 or more instances of x ( x | y ) grouping: either x or y xyz the terminal symbol xyz MetaIdentifier a non terminal symbol ***********************************************************************Link to GitHub: Source File.
- Author:
- Øystein Myhre Andersen
-
Field Summary
Modifier and TypeFieldDescriptionstatic Token
The current Token.private static boolean
Indicate that endOfFile error is givenstatic Token
The previous Token.private static Token
The saved Token used by 'pushBack'private static SimulaScanner
The SimulaScanner -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Test to accept a KeyWord.static String
Test to accept an identifier.static boolean
Test to accept a postfix operator ( DOT, IS, IN, QUA).static boolean
Test to accept a relational operator.static Type
Test to accept a Type.static void
close()
Close the Simula scanner.static boolean
Expect the given KeyWord.static String
Test to expect an identifier.static void
Initiate Parsing utilities.static void
Advance to next Token.static void
Save current Tokenstatic void
Skip misplaced current symbol.static void
Utility TRACE.
-
Field Details
-
savedToken
The saved Token used by 'pushBack' -
endOfFileErrorGiven
private static boolean endOfFileErrorGivenIndicate that endOfFile error is given -
simulaScanner
The SimulaScanner -
prevToken
The previous Token. -
currentToken
The current Token.
-
-
Constructor Details
-
Parse
Parse()Default constructor.
-
-
Method Details
-
initiate
Initiate Parsing utilities.- Parameters:
reader
- the source file reader.
-
close
public static void close()Close the Simula scanner. -
saveCurrentToken
public static void saveCurrentToken()Save current Token -
nextToken
public static void nextToken()Advance to next Token. -
accept
Test to accept a KeyWord.Test currentToken against each given key. If accepted 'nextToken' is called, thus setting prevToken.
- Parameters:
key
- t the given keywords- Returns:
- true if a keyword is accepted, false otherwise.
-
expect
Expect the given KeyWord.If it is not accepted an error message is given.
- Parameters:
key
- a keyword- Returns:
- true if the keyword was accepted, otherwise false
-
skipMisplacedCurrentSymbol
public static void skipMisplacedCurrentSymbol()Skip misplaced current symbol. -
acceptIdentifier
Test to accept an identifier.- Returns:
- the identifier or null
-
expectIdentifier
Test to expect an identifier.If failing to do so, an error is printed.
- Returns:
- the identifier or null
-
acceptType
Test to accept a Type.- Returns:
- the type or null
-
acceptPostfixOprator
public static boolean acceptPostfixOprator()Test to accept a postfix operator ( DOT, IS, IN, QUA).- Returns:
- true if the keyword is accepted, false otherwise.
-
acceptRelationalOperator
public static boolean acceptRelationalOperator()Test to accept a relational operator.value-relational-operator = < | <= | = | >= | > | <> | == | =/=
- Returns:
- true if the keyword is accepted, false otherwise.
-
TRACE
Utility TRACE.- Parameters:
msg
- a message
-