Purple  0.1
Standard Language Specification
Classes | Macros | Typedefs | Enumerations | Functions | Variables
scan.h File Reference

Lexical Scanner function headers. More...

#include <stdbool.h>
#include "types/identifier.h"
#include "types/number.h"
Include dependency graph for scan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  position
 Structure containing information about a Token's position in the input. More...
 
struct  Token
 Structure containing information about individual scannable tokens. More...
 

Macros

#define NUMBER_LITERAL_BASE_PREFIX   '0'
 
#define NUMBER_LITERAL_BIN_PREFIX   'b'
 
#define NUMBER_LITERAL_OCT_PREFIX   'o'
 
#define NUMBER_LITERAL_HEX_PREFIX   'x'
 
#define NUMBER_LITERAL_LONG_SUFFIX   'L'
 
#define NUMBER_LITERAL_SPACING_SEPARATOR   '\''
 
#define NUMBER_LITERAL_BASE_SEPARATOR   '#'
 
#define TOKENTYPE_IS_BINARY_ARITHMETIC(type)   (type >= T_PLUS && type <= T_EXPONENT)
 Determines if a TokenType is associated with a binary arithmetic operation. More...
 
#define TOKENTYPE_IS_TYPE(type)   (type >= T_VOID && type <= T_LONG)
 Determines if a TokenType is associated with a type keyword. More...
 
#define TOKENTYPE_IS_NUMBER_TYPE(tt)    ((tt >= T_BOOL && tt <= T_LONG) || (T_TRUE <= tt && tt <= T_LONG_LITERAL))
 Determines if a TokenType is associated with a number type keyword or a number literal. More...
 
#define TOKENTYPE_IS_LITERAL(type)   (type >= T_TRUE && type <= T_LONG_LITERAL)
 Determines if a TokenType is associated with a literal value. More...
 
#define TOKENTYPE_IS_BOOL_LITERAL(type)   (type >= T_TRUE && type <= T_FALSE)
 Determines if a TokenType is associated with a boolean literal value. More...
 
#define TOKENTYPE_IS_IDENTIFIER(type)   (type >= T_IDENTIFIER && type <= T_LVALUE_IDENTIFIER)
 Determines if a TokenType is associated with an identifier. More...
 
#define TOKENTYPE_IS_COMPARATOR(type)   (type >= T_EQ && type <= T_GE)
 Determines if a TokenType is associated with a comparison operator. More...
 
#define TOKENTYPE_IS_LOGICAL_OPERATOR(type)   (type >= T_AND && type <= T_XNOR)
 Determines if a TokenType is associated with a logical operator. More...
 
#define number_literal_type   long long int
 Number literals can have a max value of 2^63 - 1 and a min value of -2^63. More...
 
#define MAX_NUMBER_LITERAL_DIGITS   19
 len(str(2^63)) = 19 More...
 

Typedefs

typedef struct position position
 Structure containing information about a Token's position in the input. More...
 
typedef struct Token Token
 Structure containing information about individual scannable tokens. More...
 

Enumerations

enum  TokenType {
  T_EOF , T_PLUS , T_MINUS , T_STAR ,
  T_SLASH , T_EXPONENT , T_EQ , T_NEQ ,
  T_LT , T_GT , T_LE , T_GE ,
  T_AND , T_OR , T_XOR , T_NAND ,
  T_NOR , T_XNOR , T_TRUE , T_FALSE ,
  T_BYTE_LITERAL , T_CHAR_LITERAL , T_SHORT_LITERAL , T_INTEGER_LITERAL ,
  T_LONG_LITERAL , T_VOID , T_BOOL , T_BYTE ,
  T_CHAR , T_SHORT , T_INT , T_LONG ,
  T_ASSIGN , T_PRINT , T_IF , T_ELSE ,
  T_WHILE , T_FOR , T_RETURN , T_SEMICOLON ,
  T_LEFT_PAREN , T_RIGHT_PAREN , T_LEFT_BRACE , T_RIGHT_BRACE ,
  T_IDENTIFIER , T_LVALUE_IDENTIFIER , T_AST_GLUE , T_FUNCTION_DECLARATION ,
  T_FUNCTION_CALL
}
 Types of scannable tokens. More...
 

Functions

char next (void)
 Get the next valid character from the current input file. More...
 
void put_back_into_stream (char c)
 Put a character back into the input stream. More...
 
bool scan (Token *t)
 Scan tokens into the Token struct. More...
 

Variables

static char * tokenStrings []
 Token string equivalents. More...
 

Detailed Description

Lexical Scanner function headers.

Author
CharlesAverill
Date
05-Oct-2021

Macro Definition Documentation

◆ MAX_NUMBER_LITERAL_DIGITS

#define MAX_NUMBER_LITERAL_DIGITS   19

len(str(2^63)) = 19

◆ NUMBER_LITERAL_BASE_PREFIX

#define NUMBER_LITERAL_BASE_PREFIX   '0'

◆ NUMBER_LITERAL_BASE_SEPARATOR

#define NUMBER_LITERAL_BASE_SEPARATOR   '#'

◆ NUMBER_LITERAL_BIN_PREFIX

#define NUMBER_LITERAL_BIN_PREFIX   'b'

◆ NUMBER_LITERAL_HEX_PREFIX

#define NUMBER_LITERAL_HEX_PREFIX   'x'

◆ NUMBER_LITERAL_LONG_SUFFIX

#define NUMBER_LITERAL_LONG_SUFFIX   'L'

◆ NUMBER_LITERAL_OCT_PREFIX

#define NUMBER_LITERAL_OCT_PREFIX   'o'

◆ NUMBER_LITERAL_SPACING_SEPARATOR

#define NUMBER_LITERAL_SPACING_SEPARATOR   '\''

◆ number_literal_type

#define number_literal_type   long long int

Number literals can have a max value of 2^63 - 1 and a min value of -2^63.

◆ TOKENTYPE_IS_BINARY_ARITHMETIC

#define TOKENTYPE_IS_BINARY_ARITHMETIC (   type)    (type >= T_PLUS && type <= T_EXPONENT)

Determines if a TokenType is associated with a binary arithmetic operation.

◆ TOKENTYPE_IS_BOOL_LITERAL

#define TOKENTYPE_IS_BOOL_LITERAL (   type)    (type >= T_TRUE && type <= T_FALSE)

Determines if a TokenType is associated with a boolean literal value.

◆ TOKENTYPE_IS_COMPARATOR

#define TOKENTYPE_IS_COMPARATOR (   type)    (type >= T_EQ && type <= T_GE)

Determines if a TokenType is associated with a comparison operator.

◆ TOKENTYPE_IS_IDENTIFIER

#define TOKENTYPE_IS_IDENTIFIER (   type)    (type >= T_IDENTIFIER && type <= T_LVALUE_IDENTIFIER)

Determines if a TokenType is associated with an identifier.

◆ TOKENTYPE_IS_LITERAL

#define TOKENTYPE_IS_LITERAL (   type)    (type >= T_TRUE && type <= T_LONG_LITERAL)

Determines if a TokenType is associated with a literal value.

◆ TOKENTYPE_IS_LOGICAL_OPERATOR

#define TOKENTYPE_IS_LOGICAL_OPERATOR (   type)    (type >= T_AND && type <= T_XNOR)

Determines if a TokenType is associated with a logical operator.

◆ TOKENTYPE_IS_NUMBER_TYPE

#define TOKENTYPE_IS_NUMBER_TYPE (   tt)     ((tt >= T_BOOL && tt <= T_LONG) || (T_TRUE <= tt && tt <= T_LONG_LITERAL))

Determines if a TokenType is associated with a number type keyword or a number literal.

◆ TOKENTYPE_IS_TYPE

#define TOKENTYPE_IS_TYPE (   type)    (type >= T_VOID && type <= T_LONG)

Determines if a TokenType is associated with a type keyword.

Typedef Documentation

◆ position

typedef struct position position

Structure containing information about a Token's position in the input.

◆ Token

typedef struct Token Token

Structure containing information about individual scannable tokens.

Enumeration Type Documentation

◆ TokenType

enum TokenType

Types of scannable tokens.

Enumerator
T_EOF 
T_PLUS 
T_MINUS 
T_STAR 
T_SLASH 
T_EXPONENT 
T_EQ 
T_NEQ 
T_LT 
T_GT 
T_LE 
T_GE 
T_AND 
T_OR 
T_XOR 
T_NAND 
T_NOR 
T_XNOR 
T_TRUE 
T_FALSE 
T_BYTE_LITERAL 
T_CHAR_LITERAL 
T_SHORT_LITERAL 
T_INTEGER_LITERAL 
T_LONG_LITERAL 
T_VOID 
T_BOOL 
T_BYTE 
T_CHAR 
T_SHORT 
T_INT 
T_LONG 
T_ASSIGN 
T_PRINT 
T_IF 
T_ELSE 
T_WHILE 
T_FOR 
T_RETURN 
T_SEMICOLON 
T_LEFT_PAREN 
T_RIGHT_PAREN 
T_LEFT_BRACE 
T_RIGHT_BRACE 
T_IDENTIFIER 
T_LVALUE_IDENTIFIER 
T_AST_GLUE 
T_FUNCTION_DECLARATION 
T_FUNCTION_CALL 

Function Documentation

◆ next()

char next ( void  )

Get the next valid character from the current input file.

Returns
char Next valid character from the current input file

◆ put_back_into_stream()

void put_back_into_stream ( char  c)

Put a character back into the input stream.

Parameters
cCharacter to be placed into the input stream

◆ scan()

bool scan ( Token t)

Scan tokens into the Token struct.

Parameters
tToken to scan data into
Returns
bool Returns true if a Token was scanned successfully

Variable Documentation

◆ tokenStrings

char* tokenStrings[]
static

Token string equivalents.