view examples/mpp/mpp.h @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, a System for Syntax Directed Programming
 * C Macro preprocessor
 * Global Definitions
 *
 * Copyright 1993 Parsifal Software. All Rights Reserved.
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software
 *    in a product, an acknowledgment in the product documentation would be
 *    appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */

#ifndef MPP_H
#define MPP_H


//#define NDEBUG
#include "token.h"
#include <charsink.h>
#include <stack.h>
#include <strdict.h>
#include "ex.h"

#include "krc.h"
//#include "jrc.h"

#define N_MACROS 500            // max number of macros
#define N_SYMBOLS 5000          // size of token dictionary

enum symbol_type_enum {identifier, typedef_name};

struct macro_descriptor {
  unsigned name;                // token dictionary index of name
  unsigned* arg_names;          // pointer to list of parameter names
  unsigned n_args;              // number of parameters
  token *body;                  // body of macro
  unsigned busy_flag : 1;       // set when macro should not be expanded
  unsigned parens : 1;          // set if macro defined with parens
};

struct op_descriptor {
  const char *op;
  token_id id;
};


// Parser classes

// Expression evaluator
//  member functions are in EX.SYN

class expression_evaluator : public token_sink {
  ex_pcb_type pcb;
public:
  expression_evaluator();
  friend token_sink& reset(expression_evaluator &);
  token_sink& operator << (token t);
  token_sink& operator << (token *tp);
  operator long();
//  friend int error(expression_evaluator &);
};


// C parser
// Member Functions are in JRC.SYN or KRC.SYN

class c_parser: public token_sink {
public:
  cc_pcb_type pcb;
  c_parser();
 ~c_parser();
  token_sink &operator << (token);
  token_sink& operator << (token *);
//  friend int error(c_parser &p);
  friend c_parser &reset(c_parser &);
};


// Global variables
//  Variables are defined in mpp.cpp

extern  expression_evaluator   condition;
extern  char                   default_path[];
extern  unsigned               defined_value;
extern  int                    if_clause;
extern  macro_descriptor       macro[];
extern  unsigned               macro_id[];
extern  int                    n_macros;
extern  unsigned               n_reserved_words;
extern  int                    nest_comments;
extern  unsigned               one_value;
extern  stack<char *>          paths;
extern  op_descriptor          reserved_words[];
extern  string_accumulator     sa;
extern  token_accumulator      ta;
extern  token_sink            *scanner_sink;
extern  string_dictionary      td;
extern  unsigned               token_handles[];
extern  unsigned               zero_value;


// Function declarations

token_id classify_token(char *);                           // ct.syn
void     expand_macro(token, unsigned);                    // asc.syn
void     expand_text(token *, int = 0, unsigned * = NULL); // asc.syn
void     scan_input(char *);                               // ts.syn
void     syntax_error(const char *);                       // ts.syn

#endif