Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ASTNode Class Referenceabstract

#include <argsparser.h>

Inheritance diagram for ASTNode:
Inheritance graph
[legend]
Collaboration diagram for ASTNode:
Collaboration graph
[legend]

Public Member Functions

 ASTNode (ArgLexer *lexer=NULL, ASTNode *parent=NULL)
 
virtual ~ASTNode ()
 
virtual bool parse ()=0
 
virtual void check (std::stringstream &errors)=0
 
virtual bool consume (ArgTokenType type)
 
ArgTokenType lookahead () const
 
bool lookahead (ArgTokenType type) const
 
ArgTokencurrentToken () const
 
void nextToken ()
 
bool parseCommentList (CommentList &comments)
 
void error (String msg)
 
void unexpectedToken (String msg="")
 

Public Attributes

ASTNodeparent
 
ArgLexerpLexer
 
ArgToken token
 
String name
 
int visible
 

Detailed Description

Following classes represent the Abstract Syntax Tree for the language of definition of a program. Class representing the nodes of the tree. All nodes will have the parse method, which need a ArgLexer to ask for tokens. Also a 'consume' method to use the terminal symbols

Definition at line 140 of file argsparser.h.

Constructor & Destructor Documentation

◆ ASTNode()

ASTNode::ASTNode ( ArgLexer lexer = NULL,
ASTNode parent = NULL 
)

Definition at line 349 of file argsparser.cpp.

350 {
351  pLexer = lexer;
352  visible = 0;
353  this->parent = parent;
354 }
ASTNode * parent
Definition: argsparser.h:147
ArgLexer * pLexer
Definition: argsparser.h:150
int visible
Definition: argsparser.h:153

◆ ~ASTNode()

virtual ASTNode::~ASTNode ( )
inlinevirtual

Definition at line 144 of file argsparser.h.

145  {
146  }

Member Function Documentation

◆ check()

virtual void ASTNode::check ( std::stringstream &  errors)
pure virtual

Implemented in ProgramDef, SectionDef, ParamDef, and ArgumentDef.

◆ consume()

bool ASTNode::consume ( ArgTokenType  type)
virtual

Definition at line 376 of file argsparser.cpp.

377 {
378  ArgTokenType t = lookahead();
379  if (t != type)
380  unexpectedToken();
381  //Store consumed token
382  if (currentToken() != NULL)
383  token = *currentToken();
384  else
385  REPORT_ERROR(ERR_MEM_NULLPOINTER, "current token is null");
386 
387  //Ask for new token
388  nextToken();
389  return true;
390 }
void nextToken()
Definition: argsparser.cpp:371
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Null pointer passed as parameter.
Definition: xmipp_error.h:168
ArgTokenType
Definition: argsparser.h:43
viol type
ArgToken * currentToken() const
Definition: argsparser.cpp:366
ArgToken token
Definition: argsparser.h:151
void unexpectedToken(String msg="")
Definition: argsparser.cpp:413
ArgTokenType lookahead() const
Definition: argsparser.cpp:356

◆ currentToken()

ArgToken * ASTNode::currentToken ( ) const

Definition at line 366 of file argsparser.cpp.

367 {
368  return pLexer->currentToken();
369 }
ArgLexer * pLexer
Definition: argsparser.h:150
ArgToken * currentToken() const
Definition: argsparser.cpp:337

◆ error()

void ASTNode::error ( String  msg)

Definition at line 406 of file argsparser.cpp.

407 {
408  std::cerr << ">>> ERROR: " << msg << std::endl << " at line "
409  << token.line + 1 << " column " << token.start + 1 << std::endl;
410  exit(1);
411 }
int start
Definition: argsparser.h:78
int line
line where token was found
Definition: argsparser.h:77
ArgToken token
Definition: argsparser.h:151

◆ lookahead() [1/2]

ArgTokenType ASTNode::lookahead ( ) const

Definition at line 356 of file argsparser.cpp.

357 {
358  return pLexer->lookahead();
359 }
ArgTokenType lookahead() const
Definition: argsparser.cpp:341
ArgLexer * pLexer
Definition: argsparser.h:150

◆ lookahead() [2/2]

bool ASTNode::lookahead ( ArgTokenType  type) const

Definition at line 361 of file argsparser.cpp.

362 {
363  return pLexer->lookahead() == type;
364 }
ArgTokenType lookahead() const
Definition: argsparser.cpp:341
ArgLexer * pLexer
Definition: argsparser.h:150
viol type

◆ nextToken()

void ASTNode::nextToken ( )

Definition at line 371 of file argsparser.cpp.

372 {
373  pLexer->nextToken();
374 }
ArgLexer * pLexer
Definition: argsparser.h:150
bool nextToken()
Definition: argsparser.cpp:164

◆ parse()

virtual bool ASTNode::parse ( )
pure virtual

Implemented in ProgramDef, SectionDef, ParamDef, and ArgumentDef.

◆ parseCommentList()

bool ASTNode::parseCommentList ( CommentList comments)

Definition at line 392 of file argsparser.cpp.

393 {
394  comments.clear();
395  //Comment List (CL)
396  //CL -> comment CL | e
397  while (lookahead(TOK_COMM))
398  {
399  consume(TOK_COMM);
401  }
402 
403  return true;
404 }
virtual bool consume(ArgTokenType type)
Definition: argsparser.cpp:376
int visibility
Definition: argsparser.h:83
ArgToken token
Definition: argsparser.h:151
void addComment(const String &comment, int visible=0, bool wikiVerbatim=false)
String lexeme
the string literal value of the token
Definition: argsparser.h:76
ArgTokenType lookahead() const
Definition: argsparser.cpp:356

◆ unexpectedToken()

void ASTNode::unexpectedToken ( String  msg = "")

Definition at line 413 of file argsparser.cpp.

414 {
415  token = *currentToken();
416  error(formatString("Unexpected token '%s' (%s) \n %s",
417  token.lexeme.c_str(), ArgToken::typeString(token.type), msg.c_str()));
418 
419 }
ArgTokenType type
Type of the token.
Definition: argsparser.h:75
static const char * typeString(ArgTokenType type)
Definition: argsparser.cpp:33
void error(String msg)
Definition: argsparser.cpp:406
ArgToken * currentToken() const
Definition: argsparser.cpp:366
String formatString(const char *format,...)
ArgToken token
Definition: argsparser.h:151
String lexeme
the string literal value of the token
Definition: argsparser.h:76

Member Data Documentation

◆ name

String ASTNode::name

Definition at line 152 of file argsparser.h.

◆ parent

ASTNode* ASTNode::parent

Definition at line 147 of file argsparser.h.

◆ pLexer

ArgLexer* ASTNode::pLexer

Definition at line 150 of file argsparser.h.

◆ token

ArgToken ASTNode::token

Definition at line 151 of file argsparser.h.

◆ visible

int ASTNode::visible

Definition at line 153 of file argsparser.h.


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