Table of Contents

Class Parser

Namespace
EzrSquared.Syntax
Assembly
ezrSquared-lib.dll

The ezrĀ² Parser. The job of the Parser is to convert the input Token objects from the Lexer into Node objects to be given as the input to the Interpreter.

public class Parser
Inheritance
object
Parser

Constructors

Parser(List<Token>)

Creates a new Parser object.

public Parser(List<Token> tokens)

Parameters

tokens List<Token>

The System.Collections.Generic.List<T> of Token objects to be parsed.

Fields

_currentToken

The Token object currently being parsed at _index of _tokens.

private Token _currentToken

Field Value

Token

_index

The index of the Token object currently being parsed in the _tokensSystem.Collections.Generic.List<T>.

private int _index

Field Value

int

_result

The object that holds the result of the parsing.

private readonly ParseResult _result

Field Value

ParseResult

_tokens

The System.Collections.Generic.List<T> of Token objects to be parsed.

private readonly List<Token> _tokens

Field Value

List<Token>

Methods

Advance(int)

Advances to the next Token object in _tokens.

private void Advance(int advanceCount = 1)

Parameters

advanceCount int

BinaryOperation(Action, Action, TokenType[], (TokenType Type, Action OnCase)?)

Tries creating a BinaryOperationNode.

private void BinaryOperation(Action left, Action right, TokenType[] operators, (TokenType Type, Action OnCase)? specialCase = null)

Parameters

left Action

The function to call for the first operand.

right Action

The function to call for the second operand.

operators TokenType[]

The operator TokenType object(s).

specialCase (TokenType Type, Action OnCase)?

Any special case that needs to be uniquely handled by the "OnCase" System.Action.

"OnCase" is called after the token of type "Type" and any new lines have been parsed, and before right has been called.
Note that "Type" must be included in operators.

Parse()

Parses the Token objects in _tokens.

public ParseResult Parse()

Returns

ParseResult

ParseArithmeticExpression()

Tries parsing an 'arithmetic-expression' structure.

private void ParseArithmeticExpression()

ParseArrayOrParentheticalExpression()

Tries parsing an array, an ArrayLikeNode with CreateList set to false OR a parenthetical expression. Starts from _currentToken, which should be of TokenTypeLeftParenthesis.

private void ParseArrayOrParentheticalExpression()

ParseAtom()

Tries parsing a 'atom' structure.

private void ParseAtom()

ParseBitwiseAnd()

Tries parsing a 'bitwise-and' structure.

private void ParseBitwiseAnd()

ParseBitwiseOr()

Tries parsing a 'bitwise-or' structure.

private void ParseBitwiseOr()

ParseBitwiseShift()

Tries creating a 'bitwise-shift' structure.

private void ParseBitwiseShift()

ParseBitwiseXOr()

Tries parsing a 'bitwise-xor' structure.

private void ParseBitwiseXOr()

ParseCall()

Tries parsing a 'call' structure.

private void ParseCall()

ParseClassDefinitionExpression()

Tries parsing an class definition expression. Starts from _currentToken, which should be of TokenTypeKeywordObject.

private void ParseClassDefinitionExpression()

ParseComparison()

Tries parsing a 'comparison' structure.

private void ParseComparison()

ParseContainsCheck()

Tries parsing a 'contains-check' structure.

private void ParseContainsCheck()

ParseCountExpression()

Tries parsing a count expression. Starts from _currentToken, which should be of TokenTypeKeywordCount.

private void ParseCountExpression()

ParseDefineBlockExpression()

Tries parsing a define block expression. Starts from _currentToken, which should be of TokenTypeKeywordDefine.

private void ParseDefineBlockExpression()

ParseDictionary()

Tries parsing a dictionary. Starts from _currentToken, which should be of TokenTypeLeftCurlyBracket.

private void ParseDictionary()

ParseExpression(bool)

Tries parsing an 'expression' structure.

private void ParseExpression(bool itemKeywordRequired = false)

Parameters

itemKeywordRequired bool

In cases where the variable assignment expression requires the 'item' keyword, set this to true.

ParseFactor()

Tries parsing a 'factor' structure.

private void ParseFactor()

ParseForEachExpression()

Tries parsing a for-each expression. Starts from _currentToken, which should be of TokenTypeKeywordFor.

private void ParseForEachExpression()

ParseFunctionDefinitionExpression()

Tries parsing a function definition expression. Starts from _currentToken, which should be of TokenTypeKeywordFunction.

private void ParseFunctionDefinitionExpression()

ParseIfExpression()

Tries parsing an if expression. Starts from _currentToken, which should be of TokenTypeKeywordIf.

private void ParseIfExpression()

ParseIncludeExpression()

Tries parsing an include expression. Starts from _currentToken, which should be of TokenTypeKeywordInclude.

private void ParseIncludeExpression()

ParseInversion()

Tries parsing an 'inversion' structure.

private void ParseInversion()

ParseJunction()

Tries parsing a 'junction' structure.

private void ParseJunction()

ParseList()

Tries parsing a list, an ArrayLikeNode with CreateList set to true. Starts from _currentToken, which should be of TokenTypeLeftSquareBracket.

private void ParseList()

ParseObjectAttributeAccess()

Tries parsing an 'object-attribute-access' structure.

private void ParseObjectAttributeAccess()

ParsePower()

Tries parsing a 'power' structure.

private void ParsePower()

ParseQuickExpression(bool)

Tries parsing a 'quick-expression' structure.

private void ParseQuickExpression(bool itemKeywordRequired = false)

Parameters

itemKeywordRequired bool

ParseStatement()

Tries parsing a 'statement' structure.

private void ParseStatement()

ParseStatements()

Tries parsing a 'statements' structure.

private void ParseStatements()

ParseTerm()

Tries parsing a 'term' structure.

private void ParseTerm()

ParseTryExpression()

Tries parsing a try expression. Starts from _currentToken, which should be of TokenTypeKeywordTry.

private void ParseTryExpression()

ParseWhileExpression()

Tries parsing a while expression. Starts from _currentToken, which should be of TokenTypeKeywordWhile.

private void ParseWhileExpression()

PeekNext(int)

Peeks at the next Token object from _index in _tokens.

private Token PeekNext(int advanceCount = 1)

Parameters

advanceCount int

The numbers of places to advance in _tokens.

Returns

Token

The Token object.

PeekPrevious()

Peeks at the previous Token object from _index in _tokens.

private Token PeekPrevious()

Returns

Token

The Token object.

Reverse(int)

Reverses back to the Token object at _index - reverseCount in _tokens.

private void Reverse(int reverseCount = 1)

Parameters

reverseCount int

The number of positions to reverse _index in _tokens.