view anagram/agcore/token.cpp @ 13:43d8b194fb4e

Remove unused variables.
author David A. Holland
date Tue, 31 May 2022 00:59:00 -0400
parents 607e3be6bad8
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * token.cpp
 */

#include "q1glbl.h"
#include "rule.h"
#include "token.h"

//#define INCLUDE_LOGGING
#include "log.h"


Token::Map map_token_number;
const int Token::first = 1;

token_number_map &Token::Map::operator [] (unsigned x) {
  //LOGSECTION("Token::Map::operator []");
  //LOGV(x) LCV(Token::descriptorList.size());
  assert(x < Token::descriptorList.size());
  return Token::descriptorList[x];
}

token_number_map::token_number_map()
  : key()
  , vp_prod_number(0)
  , value_type(0)
  //, value_type(void_token_type)
  , token_set_id(0)
  , part_number(0)
  , precedence_level(0)
  , sticky(0)
  , zero_length_flag(0)
  , non_terminal_flag(0)
  , sem_det_flag(0)
  , fine_structure(0)
  , left_associative(0)
  , right_associative(0)
  , rp_arg(0)
  , pure(0)
  , junky(0)
  , reserve(0)
  , reserved_word(0)
  , subgrammar(0)
  , lexeme(0)
  , lexical(0)
  , immediate_action(0)
  , operatorCandidate(0)
  , disregard(0)
{
  LOGSECTION("token_number_map::token_number_map");
}

Token::Token(int x) : ObjectRegister<token_number_map>(x) {}
Token::Token(const Token &t) : ObjectRegister<token_number_map>(t) {}
void Token::operator = (const Token &t) {
   ObjectRegister<token_number_map>::operator = (t);
}

Token Token::create() {
  LOGSECTION("Token::create");
  ntkns = descriptorList.size();
  descriptorList.push(token_number_map());
  //LOGV(netAllocations());
  Token token(ntkns);
  //LOGV(netAllocations());
  LOGV(token) LCV(ntkns) LCV(descriptorList.size()) 
    LCV(token->value_type) LCV(token->token_name);
  return token;
}

void Token::reset() {
  LOGSECTION("Token::reset");
  ntkns = descriptorList.size();
  descriptorList.reset().push(token_number_map());
  LOGV(ntkns) LCV(descriptorList.size());
}

Rule Token::rule(int x) const {
  //return descriptorList[index].rule(x);
  return descriptor->ruleList[x];
}

Rule Token::expansionRule(int x) const {
  //return descriptorList[index].expansionRule(x);
  return descriptor->expansionRuleList[x];
}

Token Token::follower(int x) const {
  return descriptor->followerList[x];
}

Token Token::leadingToken(int x) const {
  return descriptor->leadingTokenList[x];
}

int Token::isLeadingToken(const Token candidate) const {
  LOGSECTION("Token::isLeadingToken");
  LOGV(index) LCV(candidate.index);

  int nt;

  if (index == candidate.index) {
    return 1;
  }

  AgArray<Token> leadingTokenList = descriptor->leadingTokenList;
  nt = leadingTokenList.size();
  LOGV(nt);

  while (nt--) {
    LOGV(index) LCV(leadingTokenList[nt].index);
    if (candidate.index == leadingTokenList[nt].index) {
      return 1;
    }
  }

  return 0;
}

int Token::isExpansionToken(const Token candidate) const {
  int nf;

  if (index == candidate.index) {
    return 1;
  }

  //token_number_map &descriptor = descriptorList[index];
  nf = descriptor->expansionRuleList.size();
  for (int i = 0; i < nf; i++) {
    Rule rule = descriptor->expansionRuleList[i];
    int k = rule->length();
    if (k == 0) {
      continue;
    }
    if (candidate == rule.token(0)) {
      return 1;
    }
  }
  return 0;
}

int Token::isExpansionRule(const Rule rule) const {
  //token_number_map &descriptor = descriptorList[index];
  unsigned nf = descriptor->expansionRuleList.size();

  while (nf--) {
    if (descriptor->expansionRuleList[nf] == rule) {
      return 1;
    }
  }

  return 0;
}