view anagram/agcore/rule.h @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children 607e3be6bad8
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.
 *
 * rule.h
 */

#ifndef RULE_H
#define RULE_H

class AgStringDictionary; // from agdict.h
#include "agstring.h"
#include "register.h"


struct RuleDescriptor; // below
class Token; // from token.h (included below)

extern AgStringDictionary cVariableList;

class Rule : public ObjectRegister<RuleDescriptor> {
public:
  Rule();// {}
  Rule(int x);
  Rule(const Rule &t);
  Token &token(int) const;

  static Rule create();
  static void reset();
  static const int first;

  class Map;
  friend class Map;

  class Map {
  public:
    RuleDescriptor &operator [] (unsigned x);
  };
};

class CastDescriptor {
public:
  AgString name;
  int wrapper : 1;

  CastDescriptor();
  CastDescriptor(const char *s);
  int operator < (const CastDescriptor &c) const { return name < c.name; }
  char *pointer() { return name.pointer(); }
};

class Cast : public KeyedObjectRegister<CastDescriptor> {
public:
  Cast();
  Cast(const int x);
  Cast(const char *);
  Cast(const AgString);

  static const int first;

  static void reset();
  static Cast create();

  AgString &name() { return descriptor->name; }
  int operator < (const Cast x) const;

  static Cast voidCast;
  static Cast intCast;
  static Cast longCast;
  static int nWrappers;

  void requireWrapper();
  int wrapperRequired();
};

#include "token.h"

class RuleElement {
public:
  Token token;
  int cVariable;

  RuleElement() {}
  RuleElement(const Token &t, int x);
  int operator < (const RuleElement) const;
};

struct RuleDescriptor {
  Token prim_tkn;
  unsigned line, col;
  unsigned proc_name;
  AgArray<RuleElement> elementList;
  AgArray<RuleElement> hostElementList;    // for immmediate actions only
  unsigned
    non_vanishing_length,
    op_bias;
  unsigned precedence_level;
  unsigned not_unique_reduction : 1;
  unsigned error_mask: 1;
  unsigned left_associative: 1;
  unsigned right_associative: 1;
  unsigned fast_loop: 1;
  unsigned immediate_proc: 1;
  unsigned lexical: 1;
  unsigned nonLexical: 1;
  unsigned reductionRequired: 1;

  unsigned length() { return elementList.size(); }
  RuleDescriptor();
  int operator < (const RuleDescriptor &d) const {
    return elementList < d.elementList;
  }
  Token &token(int);
};

extern Rule::Map map_form_number;

struct VpRuleDescriptor {
  AgArray<RuleElement> elementList;
  unsigned procedureName;

  VpRuleDescriptor();
  VpRuleDescriptor(AgStack<RuleElement> &, int pn);
  int operator < (const VpRuleDescriptor x) const;
};

class VpRule : public KeyedObjectRegister<VpRuleDescriptor> {
public:
  VpRule();
  VpRule(const int x);
  VpRule(const VpRule &x);
  VpRule(AgStack<RuleElement> &, int pn);

  static const int first;

  static void reset();
  static VpRule create();
};


#endif /* RULE_H */