linc 0.7
Linc is a general-purpose programming language inspired by C
Loading...
Searching...
No Matches
linc::Token Struct Referencefinal

Aggregate structure used by the lexer to abstract from raw code, such that the parser does not have to deal code on an individual character basis. More...

#include <Token.hpp>

Classes

struct  Info
 Struct holding data useful for error handling and logging. More...
 

Public Types

enum class  Type {
  InvalidToken , EndOfFile , KeywordReturn , KeywordFunction ,
  KeywordIf , KeywordElse , KeywordWhile , KeywordTrue ,
  KeywordFalse , KeywordMutability , KeywordFinally , KeywordAs ,
  KeywordFor , KeywordIn , KeywordExternal , KeywordBreak ,
  KeywordContinue , KeywordStructure , KeywordMatch , KeywordEnumeration ,
  ParenthesisLeft , ParenthesisRight , SquareLeft , SquareRight ,
  BraceLeft , BraceRight , Colon , Comma ,
  Tilde , Dot , PreprocessorSpecifier , GlueSpecifier ,
  ColonEquals , Terminator , Arrow , DoubleColon ,
  OperatorPlus , OperatorMinus , OperatorAsterisk , OperatorSlash ,
  OperatorPercent , OperatorIncrement , OperatorDecrement , OperatorStringify ,
  OperatorAssignment , OperatorAsignmentAddition , OperatorAsignmentSubstraction , OperatorAssignmentMultiplication ,
  OperatorAssignmentDivision , OperatorAssignmentModulo , OperatorEquals , OperatorNotEquals ,
  OperatorGreater , OperatorLess , OperatorGreaterEqual , OperatorLessEqual ,
  OperatorLogicalAnd , OperatorLogicalOr , OperatorLogicalNot , OperatorBitwiseAnd ,
  OperatorBitwiseOr , OperatorBitwiseXor , OperatorBitwiseNot , OperatorBitwiseShiftLeft ,
  OperatorBitwiseShiftRight , I8Literal , I16Literal , I32Literal ,
  I64Literal , U8Literal , U16Literal , U32Literal ,
  U64Literal , F32Literal , F64Literal , StringLiteral ,
  CharacterLiteral , Identifier
}
 The type of a Token.
 
enum class  NumberBase : unsigned char { Decimal , Hexadecimal , Binary }
 Enumeration of supported number system bases.
 

Public Member Functions

bool isValid () const
 Check whether the current token is valid- not of the 'InvalidToken' type.
 
bool isLiteral () const
 Check whether the current token is a literal. Literals include character literals (e.g. 'c', 60c), string literals (e.g. "hello world"), integer literals (e.g. 10u8, 10i16), boolean literals(true, false, 1b).
 
bool isKeyword () const
 Check whether the current token is a keyword. Keywords are reserved character sequences that follow the same rules as identifiers, but serve a unique purpose in the language (e.g. if, true, return, while).
 
bool isIdentifier () const
 Check whether the current token is an identifier. Identifiers are non-reserved sequences of alphanumeric(plus '_') characters used to 'identify', as the name suggests, structures like functions and variables. An identifier cannot, however, have a digit as its first character.
 
bool isEndOfFile () const
 Check whether the current token is the end of a file. the current token has been conventionally used to ease the parsing process, and is thus, also used int his project. EOF tokens are only produced at the end of files by the lexer. This means that no sequence of characters can 'emit' and end of File token as its output.
 
bool isBracket () const
 Check whether the current token is a bracket. Brackets are symbols that group together expressions and may declare additional syntax. For example, parentheses are used both for 'redirecting' the precedence of an expression, but also in cases like function declarations and function calls, where they specify the start and end of the function's argument list. Braces group statements and produce an output expression. Consequently, they are used for both grouping and introducing new syntax (the block expression in this case).
 
bool isOperator () const
 Check whether the current token is an operator. Operators are special characters that return the result of an operation that has been 'acted' upon a value. Operators are split into two primary categories: unary operators (those who modify a singular value, e.g. the unary negation operator), and binary operators (those who modify two values, e.g. the basic arithmetic operators of addition, subtraction, multiplication and division).
 
bool isSymbol () const
 Check whether the current token is a symbol. Symbols are all sequences of printable ASCII characters that are not alphanumeric (including '_'), and do not correspond to a valid operator or bracket.
 
bool isAssignmentOperator () const
 Check whether the current token is an assignment operator. Assignment operators include the 'main assignment operator' —typically used to assign a value to a given variable—, as well as all arithmetic assignment operators, which are equivelant to assignments of arithmetic binary operations to a variable, where the first operand is the same as the variable.
 
bool isArithmeticOperator () const
 Check whether the current token is an arithmetic operator. Arithmetic operators are those where all operands are numbers, and where the return value of the operation is also a number (e.g. addition, multiplication, negation, increment). Note: the arithmetic assignment operators are NOT arithmetic operators, since the assignment ones mutate a variable, and thus, cannot be applied to all number values.
 
bool isArithmeticAssignmentOperator () const
 Check whether the current token is an arithmetic assignment operator. Arithmetic assignment operators are equivelant to their corresponding binary arithmetic operators, with the first operand being a variable, which the result of the operation is also assigned to.
 
bool isComparisonOperator () const
 Check whether the current token is a comparison operator. Comparison operators are binary operators where the output is a boolean (e.g. the greater-than operator, the equality operator). Note: these operators operate solely on numbers, with the exception of the equality and inequality operators, which operate on any given type.
 
bool isLogicalOperator () const
 Check whether the current token is a logical operator. Logical operators are operators where both the operands and the return value are of boolean type, corresponding to basic statement logical operators in math (and, or, not).
 
bool isBitwiseOperator () const
 Check whether the current token is a bitwise operator. Bitwise operators are those where both the operands are integrals, and where an operation is applied to each of their individual bits. The most common bitwise operators correspond to the logical ones, but on a bit-wise level (bitwise and, bitwise or, bitwise not). Additional ones include bitwise xor, bitshift-left, bitshift-right, etc...
 
bool isBinaryOperator () const
 Check whether the current token is a binary operator. Binary operators are those that are applied to exactly two operands.
 
bool isUnaryOperator () const
 Check whether the current token is a unary operator. Unary operators are those that are applied to only a singular operand.
 
std::string getDescriptor () const
 Return a string representation of the current token, or the literal code representation of it for operators and brackets.
 

Static Public Member Functions

static unsigned char baseToInt (Token::NumberBase base)
 Convert a given number base to its corresponding integer (in decimal).
 
static std::string typeToString (Type type)
 Convert a given token type to a string, essential for error handling/debugging/IO.
 

Public Attributes

Type type
 
std::optional< std::string > value
 
std::optional< NumberBasenumberBase
 
Info info
 

Detailed Description

Aggregate structure used by the lexer to abstract from raw code, such that the parser does not have to deal code on an individual character basis.

Member Function Documentation

◆ baseToInt()

unsigned char linc::Token::baseToInt ( Token::NumberBase base)
static

Convert a given number base to its corresponding integer (in decimal).

Parameters
baseThe base enumerator.
Returns
Unsigned char (integer) corresponding to the number base.

◆ isArithmeticAssignmentOperator()

bool linc::Token::isArithmeticAssignmentOperator ( ) const
nodiscard

Check whether the current token is an arithmetic assignment operator. Arithmetic assignment operators are equivelant to their corresponding binary arithmetic operators, with the first operand being a variable, which the result of the operation is also assigned to.

Returns
Boolean corresponding to the result of the test.

◆ isArithmeticOperator()

bool linc::Token::isArithmeticOperator ( ) const
nodiscard

Check whether the current token is an arithmetic operator. Arithmetic operators are those where all operands are numbers, and where the return value of the operation is also a number (e.g. addition, multiplication, negation, increment). Note: the arithmetic assignment operators are NOT arithmetic operators, since the assignment ones mutate a variable, and thus, cannot be applied to all number values.

Returns
Boolean corresponding to the result of the test.

◆ isAssignmentOperator()

bool linc::Token::isAssignmentOperator ( ) const
nodiscard

Check whether the current token is an assignment operator. Assignment operators include the 'main assignment operator' —typically used to assign a value to a given variable—, as well as all arithmetic assignment operators, which are equivelant to assignments of arithmetic binary operations to a variable, where the first operand is the same as the variable.

Returns
Boolean corresponding to the result of the test.

◆ isBinaryOperator()

bool linc::Token::isBinaryOperator ( ) const
nodiscard

Check whether the current token is a binary operator. Binary operators are those that are applied to exactly two operands.

Returns
Boolean corresponding to the result of the test.

◆ isBitwiseOperator()

bool linc::Token::isBitwiseOperator ( ) const
nodiscard

Check whether the current token is a bitwise operator. Bitwise operators are those where both the operands are integrals, and where an operation is applied to each of their individual bits. The most common bitwise operators correspond to the logical ones, but on a bit-wise level (bitwise and, bitwise or, bitwise not). Additional ones include bitwise xor, bitshift-left, bitshift-right, etc...

Returns
Boolean corresponding to the result of the test.

◆ isBracket()

bool linc::Token::isBracket ( ) const
nodiscard

Check whether the current token is a bracket. Brackets are symbols that group together expressions and may declare additional syntax. For example, parentheses are used both for 'redirecting' the precedence of an expression, but also in cases like function declarations and function calls, where they specify the start and end of the function's argument list. Braces group statements and produce an output expression. Consequently, they are used for both grouping and introducing new syntax (the block expression in this case).

Returns
Boolean corresponding to the result of the test.

◆ isComparisonOperator()

bool linc::Token::isComparisonOperator ( ) const
nodiscard

Check whether the current token is a comparison operator. Comparison operators are binary operators where the output is a boolean (e.g. the greater-than operator, the equality operator). Note: these operators operate solely on numbers, with the exception of the equality and inequality operators, which operate on any given type.

Returns
Boolean corresponding to the result of the test.

◆ isEndOfFile()

bool linc::Token::isEndOfFile ( ) const
nodiscard

Check whether the current token is the end of a file. the current token has been conventionally used to ease the parsing process, and is thus, also used int his project. EOF tokens are only produced at the end of files by the lexer. This means that no sequence of characters can 'emit' and end of File token as its output.

Returns
Boolean corresponding to the result of the test.

◆ isIdentifier()

bool linc::Token::isIdentifier ( ) const
nodiscard

Check whether the current token is an identifier. Identifiers are non-reserved sequences of alphanumeric(plus '_') characters used to 'identify', as the name suggests, structures like functions and variables. An identifier cannot, however, have a digit as its first character.

Returns
Boolean corresponding to the result of the test.

◆ isKeyword()

bool linc::Token::isKeyword ( ) const
nodiscard

Check whether the current token is a keyword. Keywords are reserved character sequences that follow the same rules as identifiers, but serve a unique purpose in the language (e.g. if, true, return, while).

Returns
Boolean corresponding to the result of the test.

◆ isLiteral()

bool linc::Token::isLiteral ( ) const
nodiscard

Check whether the current token is a literal. Literals include character literals (e.g. 'c', 60c), string literals (e.g. "hello world"), integer literals (e.g. 10u8, 10i16), boolean literals(true, false, 1b).

Returns
Boolean corresponding to the result of the test.

◆ isLogicalOperator()

bool linc::Token::isLogicalOperator ( ) const
nodiscard

Check whether the current token is a logical operator. Logical operators are operators where both the operands and the return value are of boolean type, corresponding to basic statement logical operators in math (and, or, not).

Returns
Boolean corresponding to the result of the test.

◆ isOperator()

bool linc::Token::isOperator ( ) const
nodiscard

Check whether the current token is an operator. Operators are special characters that return the result of an operation that has been 'acted' upon a value. Operators are split into two primary categories: unary operators (those who modify a singular value, e.g. the unary negation operator), and binary operators (those who modify two values, e.g. the basic arithmetic operators of addition, subtraction, multiplication and division).

Returns
Boolean corresponding to the result of the test.

◆ isSymbol()

bool linc::Token::isSymbol ( ) const
nodiscard

Check whether the current token is a symbol. Symbols are all sequences of printable ASCII characters that are not alphanumeric (including '_'), and do not correspond to a valid operator or bracket.

Returns
Boolean corresponding to the result of the test.

◆ isUnaryOperator()

bool linc::Token::isUnaryOperator ( ) const
nodiscard

Check whether the current token is a unary operator. Unary operators are those that are applied to only a singular operand.

Returns
Boolean corresponding to the result of the test.

◆ isValid()

bool linc::Token::isValid ( ) const
nodiscard

Check whether the current token is valid- not of the 'InvalidToken' type.

Returns
Boolean corresponding to the result of the test.

◆ typeToString()

std::string linc::Token::typeToString ( Type type)
static

Convert a given token type to a string, essential for error handling/debugging/IO.

Parameters
typeThe type of the token, to be converted to string.
Returns
String corresponding to the given token type.

The documentation for this struct was generated from the following files: