Implementation of 'C' like pointers and arrays...

Tom Fjellstrom <tfjellstrom@home.com>
5 Aug 2000 21:27:57 -0400

          From comp.compilers

Related articles
Implementation of 'C' like pointers and arrays... tfjellstrom@home.com (Tom Fjellstrom) (2000-08-05)
Re: Implementation of 'C' like pointers and arrays... tfjellstrom@home.com (Tom Fjellstrom) (2000-08-09)
Re: Implementation of 'C' like pointers and arrays... tfjellstrom@home.com (Tom Fjellstrom) (2000-08-13)
| List of all articles for this month |
From: Tom Fjellstrom <tfjellstrom@home.com>
Newsgroups: comp.compilers
Date: 5 Aug 2000 21:27:57 -0400
Organization: Excite@Home - The Leader in Broadband
Keywords: question, comment

I've been writing a 'C' like scripting engine/language and I've gotten
stuck on how to get the parser (hand written) to create a variable
defined like:


  char *ch[3]; // or char **ch;


but I don't understand how to get it to create a pointer to an array
of chars. (could be any type) Or even a pointer to a pointer. I'm
just plain stuck.


basically what I do now with a plain pointer or regular var is to
create the symbol and give it its type ([pointer to]/int/char...)


Here is a short version of the structs that I use.


union var_sym_t {
      int ival;
      double fval;
      char cval;
      char *sval;
      void *vval;
};


struct symbol_t {
      struct {
            int offset;
            int len; // len==??? for arrays
            int size; // size==8-32bits
            union var_sym_t val;
      } data;
      ...
};


struct symtab_node_t {
      struct symtab_node_t *prev, *next;
      struct symtab_node_t *parent, *child;
      int flags;
      char *name;
      struct symbol_t info;
};


I'm guessing that my symtab setup
won't cut it.


Any help would be appreciated.
--
Tom Fjellstrom
[C types are recursively defined wigth "array of", "pointer to", and
"function returning" either a base type or another array, pointer, or
function. I'd use a recursive data structure if you really want the
fully glory of C types. PCC, the 2nd C compiler, used a cute trick
using two-bit fields in the type word to describe the pointer, array,
and function bits. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.