Belle II Software  release-08-01-10
B2Lexer Class Reference
Inheritance diagram for B2Lexer:
Collaboration diagram for B2Lexer:

Public Member Functions

def __init__ (self)
 
def LBRACK (self, t)
 
def RBRACK (self, t)
 
def LPAREN (self, t)
 

Public Attributes

 control_token_stack
 control_token_stack (list): stack for keeping track of seen brackets and parenthesis. More...
 

Static Public Attributes

dictionary cut_tokens
 cut specific tokens More...
 
dictionary expression_tokens
 expression tokens, also needed for cut. More...
 
dictionary tokens = expression_tokens.union(cut_tokens)
 Set of all tokens.
 
string ignore = " \t\n"
 ignore spaces tabs and newlines
 
dictionary literals = {r","}
 comma token definition as literal
 
string EQUALEQUAL = r"=="
 token regular expression for '=='
 
string GREATEREQUAL = r">="
 token regular expression for '>='
 
string LESSEQUAL = r"<="
 token regular expression for '<='
 
string GREATER = r">"
 token regular expression for '>'
 
string LESS = r"<"
 token regular expression for '<'
 
string NOTEQUAL = r"!="
 token regular expression for '!='
 
string POWER = r"\*\*|\^"
 token regular expression for power, both '**' and '^' allowed
 
string TIMES = r"\*"
 token regular expression for '*'
 
string DIVIDE = r"/"
 token regular expression for '/'
 
string PLUS = r"\+"
 token regular expression for '+'
 
string MINUS = r"-"
 token regular expression for '-'
 

Detailed Description

Class responsible for scanning the cut and generating a stream of tokens.
The token stream can be passed to `B2Parser` to generate a syntax tree.

Definition at line 73 of file b2parser.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)
Initialize Lexer

Definition at line 79 of file b2parser.py.

Member Function Documentation

◆ LBRACK()

def LBRACK (   self,
  t 
)
Scan opening bracket.

Parameters:
    t (sly.lex.token): token of type LBRACK

Raises:
    SyntaxError: if no following closing bracket is found
        in the input.

Side Effect:
    Pushes 'BRACK' onto control_token_stack

Returns:
    sly.lex.Token

Definition at line 146 of file b2parser.py.

◆ LPAREN()

def LPAREN (   self,
  t 
)
Scan opening parenthesis.

Parameters:
    t (sly.lex.token): token of type LPAREN

Raises:
    SyntaxError: if no following closing parenthesis is found
        in the input.

Side Effect:
    Pushes 'PAREN' onto control_token_stack

Returns:
    sly.lex.Token

Definition at line 198 of file b2parser.py.

◆ RBRACK()

def RBRACK (   self,
  t 
)
Scan closing bracket.

Parameters:
    t (sly.lex.token): token of type RBRACK

Raises:
    SyntaxError: 1. If control_token_stack is empty, which means
        no bracket was opened previously.
                 2. If state of control_token_stack is 'PAREN', which
        means a closing parenthesis is expected.

Side Effect:
    Pops object from control_token_stack

Returns:
    sly.lex.Token

Definition at line 169 of file b2parser.py.

Member Data Documentation

◆ control_token_stack

control_token_stack

control_token_stack (list): stack for keeping track of seen brackets and parenthesis.

Allows finding parenthesis and bracket syntax errors on scanner level.

Definition at line 84 of file b2parser.py.

◆ cut_tokens

dictionary cut_tokens
static
Initial value:
= {
# structure tokens
RBRACK, LBRACK, # noqa: F821
# boolean operators
AND, OR, NOT, # noqa: F821
# comparison operators
EQUALEQUAL, GREATEREQUAL, LESSEQUAL, GREATER, LESS, # noqa: F821
NOTEQUAL, # noqa: F821
}

cut specific tokens

Definition at line 87 of file b2parser.py.

◆ expression_tokens

dictionary expression_tokens
static
Initial value:
= {
LPAREN, RPAREN, # noqa: F821
# data types
DOUBLE, INTEGER, IDENTIFIER, BOOLEAN, # noqa: F821
# arithmetic operators
POWER, TIMES, DIVIDE, PLUS, MINUS # noqa: F821
}

expression tokens, also needed for cut.

Definition at line 97 of file b2parser.py.


The documentation for this class was generated from the following file: