amath  1.8.5
Simple command line calculator
Token Struct Reference

Tokens are created by the Lexical Analyzer and provides an intermediate state for input consumed by the parser. More...

#include <token.h>

Collaboration diagram for Token:

Public Member Functions

 Token (Token *last, Symbol symbol, int pos)
 
 Token (Token *last, Symbol symbol, const char *text, int pos)
 
 ~Token ()
 
int GetPos () const
 
char * GetText () const
 
TokenGetLastToken () const
 
TokenGetNextToken ()
 

Public Attributes

Symbol symbol
 

Private Attributes

int pos
 
char * text
 
Tokenlast
 
Tokennext
 

Friends

class Lexer
 

Detailed Description

Tokens are created by the Lexical Analyzer and provides an intermediate state for input consumed by the parser.

Definition at line 46 of file token.h.

Constructor & Destructor Documentation

◆ Token() [1/2]

Token::Token ( Token last,
Symbol  symbol,
int  pos 
)

Definition at line 37 of file token.cpp.

References last, next, pos, symbol, and text.

Referenced by Lexer::GetLiteral(), GetNextToken(), Lexer::GetNextToken(), and Lexer::GetOperator().

38 {
39  this->last = last;
40  this->symbol = symbol;
41  this->pos = pos;
42  this->text = nullptr;
43  this->next = nullptr;
44 }
Token * last
Definition: token.h:62
char * text
Definition: token.h:61
Symbol symbol
Definition: token.h:53
int pos
Definition: token.h:60
Token * next
Definition: token.h:63
Here is the caller graph for this function:

◆ Token() [2/2]

Token::Token ( Token last,
Symbol  symbol,
const char *  text,
int  pos 
)

Definition at line 46 of file token.cpp.

References AllocAndCopy(), last, next, pos, symbol, and text.

Referenced by Lexer::GetDigitValue(), Lexer::GetLiteral(), and Lexer::GetQuotedIdent().

47 {
48  this->last = last;
49  this->symbol = symbol;
50  this->pos = pos;
51  this->next = nullptr;
52  AllocAndCopy(&this->text, text);
53 }
Token * last
Definition: token.h:62
char * text
Definition: token.h:61
Symbol symbol
Definition: token.h:53
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
int pos
Definition: token.h:60
Token * next
Definition: token.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Token()

Token::~Token ( )

Definition at line 55 of file token.cpp.

References next, and text.

56 {
57  if (text != nullptr)
58  {
59  delete [] text;
60  }
61 
62  if (next != nullptr)
63  {
64  delete next;
65  }
66 }
char * text
Definition: token.h:61
Token * next
Definition: token.h:63

Member Function Documentation

◆ GetLastToken()

Token * Token::GetLastToken ( ) const

Definition at line 68 of file token.cpp.

References last.

Referenced by Parser::PutToken().

69 {
70  return last;
71 }
Token * last
Definition: token.h:62
Here is the caller graph for this function:

◆ GetNextToken()

Token * Token::GetNextToken ( )

Definition at line 73 of file token.cpp.

References next, pos, symend, and Token().

Referenced by Parser::GetToken(), and Parser::Peek().

74 {
75  // Always return a token if requested
76  if (next == nullptr)
77  {
78  next = new Token(this, symend, pos);
79  }
80 
81  return next;
82 }
Token(Token *last, Symbol symbol, int pos)
Definition: token.cpp:37
int pos
Definition: token.h:60
Definition: symbol.h:81
Token * next
Definition: token.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPos()

int Token::GetPos ( ) const

◆ GetText()

Friends And Related Function Documentation

◆ Lexer

friend class Lexer
friend

Definition at line 64 of file token.h.

Member Data Documentation

◆ last

Token* Token::last
private

Definition at line 62 of file token.h.

Referenced by GetLastToken(), and Token().

◆ next

Token* Token::next
private

Definition at line 63 of file token.h.

Referenced by GetNextToken(), Token(), Lexer::Tokenize(), and ~Token().

◆ pos

int Token::pos
private

Definition at line 60 of file token.h.

Referenced by GetNextToken(), GetPos(), and Token().

◆ symbol

◆ text

char* Token::text
private

Definition at line 61 of file token.h.

Referenced by GetText(), Token(), and ~Token().


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