A new Gobstones parser for a given lexer.
defining the lexer from where to obtain the tokens.
Private
_elementPrivate
Return the concrete element corresponding to the given token tag, depending of the concrete word in the language words definition.
Private
_functionPrivate
Return the token corresponding to the function name for the given operator, using for it the name of the abstract word for the operator.
PRECONDITION:
op
is one of the operators at the given levelPrivate
_expectPrivate
Confirm that the current token has the expected tag, or fail if it is not.
Its use is to fail with a controlled error in case the precondition of this._match
is not satisfied.
So, it usually will appear before the use of this._match
with the same expectedTokenTag
.
Consider also using _matchTokenInConstruction
for a combination of both.
PRECONDITION:
Optional
name: stringPrivate
_loadPrivate
TO DO: Complete
** PRECONDITION:**
THE TRY-CATCH HAS TO BE REVISITED AND THOUGHT WITH MORE PRECISION NOTE: the precondition is tested because this operations is meant to be used a lot during parsing, and it will be cumbersome to test on each call for its error. If some token is expected, but there are no more of them, a Parser error should be thrown -- not a Lexer error.
GErrors.NoMoreInputErrorIn is there are no more GTokens
Private
_matchPrivate
Confirm that the current token has the expected tag, or fail if it is not. If the tag is correct, advance to the next token, if there is one. It is not supposed to be used to match EOD.
PRECONDITION: (not verified)
Private
_matchPrivate
Combines the actions of _expectTokenInConstruction
and _match
, for the cases where
they must be used one after the other.
PRECONDITION:
Optional
name: stringPrivate
_optionallyPrivate
Match the current GToken if its tag is the one given, or do nothing if it is not. It implements the possibility to have an optional token. It is not supposed to be used to match EOD.
PRECONDITION:
Private
_parsePrivate
Return the next token, if it is the one expected, or fail if it is not. If the tag is correct, advance to the next token, if there is one. It is not supposed to be used to expect for EOD.
PRECONDITION:
Private
_skipEODsPrivate
_parsePrivate
Parse the sequence of Definitions forming the source code, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= *
** PRECOND:**
Private
_parsePrivate
Parse a Definition, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed. It is not supposed to be used when the current GToken is EOD.
Grammar rule:
:= | | | |
** PRECOND:**
Private
_parsePrivate
Parses an Expression at the given fixity level, if there is a well formed one starting at the curren GToken. It fails if current GToken does not start the described element, if it or any of its parts are not well formed, if the fixity of the level is not correct in the language declaration, or if the fixity of the level is not respected.
Grammar rule:
(level) := (level) | (level) | (level) | (level) |
PRECONDITION:
this._langWords
are in BaseFixities
Private
_parsePrivate
Parses an Expression at non-associative fixity level, if there is a well formed one starting at the curren GToken. It fails if current GToken does not start the described element, if it or any of its parts are not well formed, or if the fixity of the level is not respected.
Grammar rule:
(level) := (level + 1) (level) (level + 1) | (level + 1)
PRECONDITION:
Private
_parsePrivate
Parses an Expression at a left associative fixity level, if there is a well formed one starting at the curren GToken. It fails if current GToken does not start the described element, if it or any of its parts are not well formed, or if the fixity of the level is not respected.
Grammar rule:
(level) := (level + 1) ( (level) (level + 1))*
PRECONDITION:
Private
_parsePrivate
Parses an Expression at a right associative fixity level, if there is a well formed one starting at the curren GToken. It fails if current GToken does not start the described element, if it or any of its parts are not well formed, or if the fixity of the level is not respected.
Grammar rule:
(level) := (level + 1) ( (level) (level))*
PRECONDITION:
Private
_parsePrivate
Parses an Expression at a prefix fixity level, if there is a well formed one starting at the curren GToken. It fails if current GToken does not start the described element, if it or any of its parts are not well formed, or if the fixity of the level is not respected.
Grammar rule:
(level) := (level) (level) | (level + 1)
PRECONDITION:
Private
_parsePrivate
Parses an Expression at top level, if there is a well formed one starting at the curren GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= (0)
PRECONDITION:
Private
_parsePrivate
Parse a Statment, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= | | | | | | | | | |
PRECONDITION:
Private
_parsePrivate
Parse the argument list of a procedure or function definition, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
--> ( (COMMA )*)?
** PRECOND:**
Private
_parsePrivate
Parse the remainder of a procedure or function definition, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
--> LPAREN ( (COMMA )*)? RPAREN RBRACK
** PRECOND:**
name
tag is either UPPERID or LOWERIDPrivate
_parsePrivate
Parse a sequence of elements given by parseElement
, separated by the separator
and
ending in the rightDelimiter
(not parsed), if there is a well formed one starting at
the current token.
It fails if current token does not start the described element, or if it or any of its
parts are not well formed.
OBSERVATIONS:
rightDelimiter
, is NOT parsed to allow better structure at the callerGrammar rule:
(rightDelimiter, separator, element) --> (element (separator element)*)? rightDelimiter
** PRECOND:**
elementStarters
or rightDelimiter
Private
_parsePrivate
Parse the final part of a Range, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
OBSERVATION: The closing token, RBRACK, is parsed to allow better structure at the caller.
Grammar rule:
--> RANGE RBRACK
** PRECOND:**
Optional
secondElem: ASTExprPrivate
_parsePrivate
Parse a sequence of Expressions, starting and separated by commas and ending in a right bracket, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
OBSERVATION: The closing token, RBRACK, is parsed to allow better structure at the caller.
Grammar rule:
--> (COMMA )* RBRACK
** PRECOND:**
Private
_parsePrivate
Parse the name list (a parameter list of a procedure or function definition, or a tuple of variables on a let assignment), if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
--> ( (COMMA )*)?
** PRECOND:**
name
tag is either UPPERID or LOWERIDPrivate
_parsePrivate
Parse a sequence of elements given by parseElement
,
starting and separated by the separator
,
if there is a well formed one starting at the current GToken.
It fails if current GToken does not start the described element,
or if it or any of its parts are not well formed.
Grammar rule:
(separator, element) --> (separator element)*
** PRECOND:**
separator
Private
_parsePrivate
Parse a switch branch if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
--> ARROW
** PRECOND:**
Private
_parsePrivate
Parse a sequence of switch branches if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
--> ( ARROW )*
** PRECOND:**
Private
_parsePrivate
Parse a FUNTION definition, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= FUNTION LPAREN ( (, )*)? RPAREN
** PRECOND:**
Private
_parsePrivate
TO DO: Complete ** PRECOND:**
Private
_parsePrivate
Parse a PROCEDURE definition, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= PROCEDURE LPAREN ( (, )*)? RPAREN
** PRECOND:**
Private
_parsePrivate
Parse a PROGRAM definition, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= PROGRAM
** PRECOND:**
Private
_parsePrivate
TO DO: Complete ** PRECOND:**
Private
_parsePrivate
Parse an Expression atom, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= | | | | | | | | | LPAREN RPAREN | | |
PRECONDITION:
Private
_parsePrivate
TO DO: Complete ** PRECOND:**
Private
_parsePrivate
Parse an Ellipsis for Expressions, if there is one starting at the current GToken. It fails if current GToken does not start the described element.
Grammar rule:
:= ELLIPSIS
** PRECOND:**
Private
_parsePrivate
Parse a Literal List or a List Range, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rules:
:= LBRACK ( (COMMA )*)? RBRACK := LBRACK (COMMA )? RANGE RBRACK
OBSERVATION: The closing token, RBRACK, is parsed in the endings operations to allow better code structure.
** PRECOND:**
Private
_parsePrivate
Parse a Literal Number expression, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:=
** PRECOND:**
Private
_parsePrivate
Parse a Literal String expression, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:=
** PRECOND:**
Private
_parsePrivate
TO DO: Complete ** PRECOND:**
Private
_parsePrivate
TO DO: Complete ** PRECOND:**
Private
_parsePrivate
Parse a Tuple or a single Expression surrounded by parentheses, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rules:
--> LPAREN RPAREN := LPAREN ( (COMMA <Expr)+)? RPAREN
** PRECOND:**
Private
_parsePrivate
Parse a Function Call expression, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= := LPAREN ( (COMMA )*)? RPAREN
** PRECOND:**
Private
_parsePrivate
TO DO: Complete Parse a pattern, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= | | << >>
** PRECOND:**
Private
_parsePrivate
Parse a pattern variable, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element.
Grammar rule:
:=
** PRECOND:**
Private
_parsePrivate
Parse a pattern wildcard, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element.
Grammar rule:
:= UNDERSCORE
** PRECOND:**
Private
_parsePrivate
Parse a conditional statement part of an if-then-else construct, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= LPAREN RPAREN (THEN)?
** PRECOND:**
Private
_parsePrivate
Parse an Assign Variable statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= ASSIGN
** PRECOND:**
Private
_parsePrivate
Parse a block of statements, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= LBRACE * RBRACE
** PRECOND:**
Private
_parsePrivate
Parse an Ellipsis for Statements, if there is one starting at the current GToken. It fails if current GToken does not start the described element.
Grammar rule:
:= ELLIPSIS
** PRECOND:**
Private
_parsePrivate
Parse a FOREACH statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= FOREACH IN
** PRECOND:**
Private
_parsePrivate
Parse a IF-THEN-ELSE statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= IF (ELSEIF )+ (ELSE )?
** PRECOND:**
Private
_parsePrivate
Parse a LET statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= LET LPAREN (COMMA )* RPAREN ASSIGN
** PRECOND:**
Private
_parsePrivate
Parse a Procedure Call statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= LPAREN ( (COMMA )*)? RPAREN
** PRECOND:**
Private
_parsePrivate
Parse a REPEAT statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= REPEAT LPAREN RPAREN
** PRECOND:**
Private
_parsePrivate
Parse a RETURN statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= RETURN LPAREN (COMMA )* RPAREN
** PRECOND:**
Private
_parsePrivate
Parse a SWITCH statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= SWITCH LPAREN RPAREN TO? LBRACE ( ARROW <Stmt-Block)* RBRACE
** PRECOND:**
Private
_parsePrivate
Parse a WHILE statement, if there is a well formed one starting at the current GToken. It fails if current GToken does not start the described element, or if it or any of its parts are not well formed.
Grammar rule:
:= WHILE LPAREN RPAREN
** PRECOND:**
Private
_currentGTokenTO DO: Complete
Private
_langTO DO: Complete
Private
_lexerTO DO: Complete
TO DO: Complete
NOTE: Attributes and comments right before the start of a definition are associated with that definition. However, if the comments or attributes are in the middle, they may be lost, or assigned to the next construction that is associated with attributes...
Pure attributes are supposed to be just before definitions... However, comments are also assigned to the program, and their behavior has to be better designed. Currently it is not too consistent. :(