Berkeley YACC  1993-03-03
Berkeley's version of Yet Another Compiler Compiler
 All Data Structures Files Functions Variables Typedefs Macros Groups
defs.h File Reference
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
+ Include dependency graph for defs.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bucket
 
struct  core
 
struct  shifts
 
struct  reductions
 
struct  action
 

Macros

#define MAXCHAR   255
 
#define MAXSHORT   32767
 
#define MINSHORT   -32768
 
#define MAXTABLE   32500
 
#define BITS_PER_WORD   32
 
#define WORDSIZE(n)   (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
 
#define BIT(r, n)   ((((r)[(n)>>5])>>((n)&31))&1)
 
#define SETBIT(r, n)   ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
 
#define NUL   '\0' /* the null character */
 
#define NEWLINE   '\n' /* line feed */
 
#define SP   ' ' /* space */
 
#define BS   '\b' /* backspace */
 
#define HT   '\t' /* horizontal tab */
 
#define VT   '\013' /* vertical tab */
 
#define CR   '\r' /* carriage return */
 
#define FF   '\f' /* form feed */
 
#define QUOTE   '\'' /* single quote */
 
#define DOUBLE_QUOTE   '\"' /* double quote */
 
#define BACKSLASH   '\\' /* backslash */
 
#define CODE_SUFFIX   ".code.c"
 
#define DEFINES_SUFFIX   ".tab.h"
 
#define OUTPUT_SUFFIX   ".tab.c"
 
#define VERBOSE_SUFFIX   ".output"
 
#define TOKEN   0
 
#define LEFT   1
 
#define RIGHT   2
 
#define NONASSOC   3
 
#define MARK   4
 
#define TEXT   5
 
#define TYPE   6
 
#define START   7
 
#define UNION   8
 
#define IDENT   9
 
#define UNKNOWN   0
 
#define TERM   1
 
#define NONTERM   2
 
#define UNDEFINED   (-1)
 
#define SHIFT   1
 
#define REDUCE   2
 
#define IS_IDENT(c)   (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
 
#define IS_OCTAL(c)   ((c) >= '0' && (c) <= '7')
 
#define NUMERIC_VALUE(c)   ((c) - '0')
 
#define ISTOKEN(s)   ((s) < start_symbol)
 
#define ISVAR(s)   ((s) >= start_symbol)
 
#define CALLOC(k, n)   (calloc((unsigned)(k),(unsigned)(n)))
 
#define FREE(x)   (free((char*)(x)))
 
#define MALLOC(n)   (malloc((unsigned)(n)))
 
#define NEW(t)   ((t*)allocate(sizeof(t)))
 
#define NEW2(n, t)   ((t*)allocate((unsigned)((n)*sizeof(t))))
 
#define REALLOC(p, n)   (realloc((char*)(p),(unsigned)(n)))
 

Typedefs

typedef struct bucket bucket
 
typedef struct core core
 
typedef struct shifts shifts
 
typedef struct reductions reductions
 
typedef struct action action
 

Functions

char * allocate ()
 
bucketlookup ()
 
bucketmake_bucket ()
 
void free ()
 
char * calloc ()
 
char * malloc ()
 
char * realloc ()
 
char * strcpy ()
 

Variables

char dflag
 
char lflag
 
char rflag
 
char tflag
 
char vflag
 
char * symbol_prefix
 
char * myname
 
char * cptr
 
char * line
 
int lineno
 
int outline
 
char * banner []
 
char * tables []
 
char * header []
 
char * body []
 
char * trailer []
 
char * action_file_name
 
char * code_file_name
 
char * defines_file_name
 
char * input_file_name
 
char * output_file_name
 
char * text_file_name
 
char * union_file_name
 
char * verbose_file_name
 
FILE * action_file
 
FILE * code_file
 
FILE * defines_file
 
FILE * input_file
 
FILE * output_file
 
FILE * text_file
 
FILE * union_file
 
FILE * verbose_file
 
int nitems
 
int nrules
 The number of rules in the grammar. More...
 
int nsyms
 The number of symbols (terminals + non-terminals) in the grammar. More...
 
int ntokens
 The number of tokens (terminals) in the grammar. More...
 
int nvars
 The number of variables (non-terminals) in the grammar. More...
 
int ntags
 
char unionized
 
char line_format []
 
int start_symbol
 Index of the starting symbol of the grammar. More...
 
char ** symbol_name
 Array of symbol names. More...
 
short * symbol_value
 
short * symbol_prec
 
char * symbol_assoc
 
short * ritem
 Representation of all productions (and items) More...
 
short * rlhs
 List of left-hand sides of all rules. More...
 
short * rrhs
 List of right-hand sides of all rules. More...
 
short * rprec
 
char * rassoc
 
short ** derives
 List of rules that derive each non-terminal. More...
 
char * nullable
 
bucketfirst_symbol
 
bucketlast_symbol
 
int nstates
 
corefirst_state
 
shiftsfirst_shift
 
reductionsfirst_reduction
 
short * accessing_symbol
 
core ** state_table
 
shifts ** shift_table
 
reductions ** reduction_table
 
unsigned * LA
 
short * LAruleno
 
short * lookaheads
 
short * goto_map
 
short * from_state
 
short * to_state
 
action ** parser
 
int SRtotal
 
int RRtotal
 
short * SRconflicts
 
short * RRconflicts
 
short * defred
 
short * rules_used
 
short nunused
 
short final_state
 
int errno
 

Macro Definition Documentation

#define BACKSLASH   '\\' /* backslash */

Definition at line 43 of file defs.h.

#define BIT (   r,
 
)    ((((r)[(n)>>5])>>((n)&31))&1)

Definition at line 27 of file defs.h.

Referenced by add_reductions().

#define BITS_PER_WORD   32
#define BS   '\b' /* backspace */

Definition at line 36 of file defs.h.

#define CALLOC (   k,
 
)    (calloc((unsigned)(k),(unsigned)(n)))

Definition at line 101 of file defs.h.

Referenced by allocate().

#define CODE_SUFFIX   ".code.c"

Definition at line 48 of file defs.h.

Referenced by create_file_names().

#define CR   '\r' /* carriage return */

Definition at line 39 of file defs.h.

#define DEFINES_SUFFIX   ".tab.h"

Definition at line 49 of file defs.h.

Referenced by create_file_names().

#define DOUBLE_QUOTE   '\"' /* double quote */

Definition at line 42 of file defs.h.

#define FF   '\f' /* form feed */

Definition at line 40 of file defs.h.

#define HT   '\t' /* horizontal tab */

Definition at line 37 of file defs.h.

#define IDENT   9

Definition at line 65 of file defs.h.

Referenced by keyword(), and read_declarations().

#define IS_IDENT (   c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')

Definition at line 88 of file defs.h.

Referenced by get_name(), get_tag(), and mark_symbol().

#define IS_OCTAL (   c)    ((c) >= '0' && (c) <= '7')

Definition at line 89 of file defs.h.

Referenced by get_literal().

#define ISTOKEN (   s)    ((s) < start_symbol)

Definition at line 95 of file defs.h.

Referenced by get_shifts(), and set_goto_map().

#define ISVAR (   s)    ((s) >= start_symbol)

Definition at line 96 of file defs.h.

Referenced by build_relations(), closure(), initialize_F(), print_actions(), print_gotos(), and set_EFF().

#define LEFT   1

Definition at line 57 of file defs.h.

Referenced by keyword(), read_declarations(), and remove_conflicts().

#define MARK   4

Definition at line 60 of file defs.h.

Referenced by advance_to_start(), keyword(), and read_declarations().

#define MAXCHAR   255

Definition at line 21 of file defs.h.

Referenced by get_literal().

#define MAXSHORT   32767

Definition at line 22 of file defs.h.

Referenced by new_state(), set_goto_map(), and token_actions().

#define MAXTABLE   32500

Definition at line 24 of file defs.h.

Referenced by pack_vector().

#define MINSHORT   -32768

Definition at line 23 of file defs.h.

#define NEW (   t)    ((t*)allocate(sizeof(t)))

Definition at line 104 of file defs.h.

Referenced by add_lookback_edge(), add_reduce(), and get_shifts().

#define NEWLINE   '\n' /* line feed */

Definition at line 34 of file defs.h.

#define NONASSOC   3

Definition at line 59 of file defs.h.

Referenced by keyword(), and read_declarations().

#define NONTERM   2

Definition at line 72 of file defs.h.

Referenced by insert_empty_rule(), and start_rule().

#define NUL   '\0' /* the null character */

Definition at line 33 of file defs.h.

Referenced by get_literal(), get_name(), get_tag(), is_reserved(), and keyword().

#define NUMERIC_VALUE (   c)    ((c) - '0')

Definition at line 90 of file defs.h.

#define OUTPUT_SUFFIX   ".tab.c"

Definition at line 50 of file defs.h.

Referenced by create_file_names().

#define QUOTE   '\'' /* single quote */

Definition at line 41 of file defs.h.

#define REALLOC (   p,
 
)    (realloc((char*)(p),(unsigned)(n)))

Definition at line 106 of file defs.h.

Referenced by cachec(), expand_items(), expand_rules(), get_line(), get_tag(), pack_grammar(), and pack_vector().

#define REDUCE   2
#define RIGHT   2

Definition at line 58 of file defs.h.

Referenced by keyword(), read_declarations(), and remove_conflicts().

#define SETBIT (   r,
 
)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))

Definition at line 28 of file defs.h.

Referenced by initialize_F(), set_EFF(), and set_first_derives().

#define SHIFT   1
#define SP   ' ' /* space */

Definition at line 35 of file defs.h.

#define START   7

Definition at line 63 of file defs.h.

Referenced by advance_to_start(), keyword(), and read_declarations().

#define TEXT   5

Definition at line 61 of file defs.h.

Referenced by advance_to_start(), keyword(), and read_declarations().

#define TYPE   6

Definition at line 62 of file defs.h.

Referenced by keyword(), and read_declarations().

#define UNDEFINED   (-1)
#define UNION   8

Definition at line 64 of file defs.h.

Referenced by keyword(), and read_declarations().

#define UNKNOWN   0

Definition at line 70 of file defs.h.

Referenced by check_symbols(), and make_bucket().

#define VERBOSE_SUFFIX   ".output"

Definition at line 51 of file defs.h.

Referenced by create_file_names().

#define VT   '\013' /* vertical tab */

Definition at line 38 of file defs.h.

Typedef Documentation

typedef struct action action

Definition at line 166 of file defs.h.

typedef struct bucket bucket

Definition at line 111 of file defs.h.

typedef struct core core

Definition at line 128 of file defs.h.

typedef struct reductions reductions

Definition at line 154 of file defs.h.

typedef struct shifts shifts

Definition at line 142 of file defs.h.

Function Documentation

char* allocate ( )

Referenced by new_state(), save_reductions(), and save_shifts().

+ Here is the caller graph for this function:

char* calloc ( )
void free ( )
bucket* lookup ( )

Referenced by get_literal(), and get_name().

+ Here is the caller graph for this function:

bucket* make_bucket ( )

Referenced by insert_empty_rule().

+ Here is the caller graph for this function:

char* malloc ( )
char* realloc ( )
char* strcpy ( )

Referenced by create_file_names(), get_tag(), make_bucket(), and pack_names().

+ Here is the caller graph for this function:

Variable Documentation

FILE* action_file

Definition at line 27 of file main.c.

Referenced by copy_action(), done(), open_files(), and output_semantic_actions().

char* action_file_name

Definition at line 18 of file main.c.

Referenced by create_file_names(), done(), open_files(), and output_semantic_actions().

char* banner[]

Definition at line 15 of file skeleton.c.

Referenced by reader().

char* body[]

Definition at line 77 of file skeleton.c.

Referenced by output().

char* code_file_name
FILE* defines_file

Definition at line 30 of file main.c.

Referenced by open_files(), and output_defines().

char* defines_file_name

Definition at line 20 of file main.c.

Referenced by create_file_names(), and open_files().

short* defred

Definition at line 9 of file mkpar.c.

Referenced by defreds(), output_yydefred(), print_actions(), and token_actions().

short** derives

List of rules that derive each non-terminal.

Array of pointers that associates to each symbol the list of productions that have it as the left-hand side. Each item in those lists is the identifying number of a rule. The first ntokens entries (the ones for terminals) are not set and should not be accessed. They are only present to make the indexes consistent with other arrays (i.e. this array can be indexed using the symbol number).

Allocated and filled in set_first_derives().

Definition at line 140 of file main.c.

Referenced by build_relations(), free_derives(), initialize_states(), set_derives(), set_EFF(), and set_first_derives().

char dflag

Definition at line 4 of file main.c.

Referenced by copy_union(), create_file_names(), getargs(), open_files(), and output_defines().

int errno
short final_state
reductions* first_reduction

Definition at line 11 of file lr0.c.

Referenced by free_reductions(), and set_reduction_table().

shifts* first_shift

Definition at line 10 of file lr0.c.

Referenced by free_shifts(), set_goto_map(), and set_shift_table().

core* first_state

Definition at line 9 of file lr0.c.

Referenced by free_itemsets(), set_accessing_symbol(), and set_state_table().

bucket* first_symbol

Definition at line 11 of file symtab.c.

Referenced by check_symbols(), pack_names(), and pack_symbols().

short* from_state

Definition at line 20 of file lalr.c.

Referenced by build_relations(), map_goto(), output_actions(), save_column(), and set_goto_map().

short* goto_map

Definition at line 19 of file lalr.c.

Referenced by default_goto(), map_goto(), output_actions(), save_column(), and set_goto_map().

char* header[]

Definition at line 49 of file skeleton.c.

Referenced by output().

FILE* input_file

Definition at line 31 of file main.c.

Referenced by get_line(), getargs(), open_files(), and output_trailing_text().

unsigned* LA

Definition at line 14 of file lalr.c.

Referenced by add_reductions(), compute_lookaheads(), initialize_LA(), and output_actions().

short* LAruleno

Definition at line 13 of file lalr.c.

Referenced by add_lookback_edge(), add_reductions(), initialize_LA(), and output_actions().

bucket* last_symbol

Definition at line 12 of file symtab.c.

Referenced by insert_empty_rule().

char line_format[]
short* lookaheads
int nsyms

The number of symbols (terminals + non-terminals) in the grammar.

All symbols can be uniquely represented using integers in the range [0, nsyms - 1], which is obtained by joining the range of terminals [0, ntokens - 1] with the range of non-terminals [ntokens, nsyms - 1].

It holds that nsyms = ntokens + nvars.

Definition at line 55 of file main.c.

Referenced by allocate_itemsets(), allocate_storage(), goto_actions(), new_itemsets(), pack_symbols(), set_derives(), set_EFF(), set_first_derives(), set_goto_map(), and set_nullable().

int ntags

Definition at line 13 of file reader.c.

Referenced by copy_action(), free_tags(), get_tag(), and output_stype().

int ntokens

The number of tokens (terminals) in the grammar.

All tokens can be uniquely represented using integers in the range [0, ntokens - 1].

It holds that nsyms = ntokens + nvars.

Definition at line 64 of file main.c.

Referenced by add_reductions(), finalize_closure(), lalr(), output_actions(), output_debug(), output_defines(), pack_symbols(), set_first_derives(), set_goto_map(), token_actions(), and verbose().

char* nullable

Definition at line 141 of file main.c.

Referenced by build_relations(), free_nullable(), initialize_F(), and set_nullable().

short nunused

Definition at line 11 of file mkpar.c.

Referenced by unused_rules(), and verbose().

int nvars

The number of variables (non-terminals) in the grammar.

All variables can be uniquely represented using integers in the range [ntokens, nsyms - 1], which is equivalent to the range [ntokens, ntokens + nvars - 1].

It holds that nsyms = ntokens + nvars.

Definition at line 74 of file main.c.

Referenced by output_actions(), pack_symbols(), set_derives(), set_EFF(), set_first_derives(), set_goto_map(), and verbose().

char* output_file_name

Definition at line 22 of file main.c.

Referenced by create_file_names(), and open_files().

action** parser

Definition at line 4 of file mkpar.c.

Referenced by print_actions(), print_conflicts(), print_nulls(), and token_actions().

char* rassoc
reductions** reduction_table

Definition at line 18 of file lalr.c.

Referenced by free_reductions().

short* ritem

Representation of all productions (and items)

Typical shape: [1, 12, 21, -1, 2, 3, -2, 1, 4, -3, ...]

All productions are represented in this array as the list of their right-hand side symbols followed by the negation of their index. So the symbols on the right-hand side of the first rule are followed by -1, then there are the right-hand side symbols of the second rule and then -2, and so on.

Indices (using short integers) inside this array can represent rules (in that case they point to the first element after a negative one) or items, in which case they can point to any position; the element in that position is taken to be the first element after the "point" of the item. If the index points to a negative number, then it represents a reduction item for the rule whose number is the absolute value of the pointed element.

The array called rrhs contains indices inside this list and is used to associate to each rule the beginning of its production (that is, the closure item for that rule).

Definition at line 112 of file main.c.

Referenced by allocate_itemsets(), build_relations(), closure(), find_final_state(), log_unused(), new_itemsets(), output_debug(), pack_grammar(), print_core(), print_grammar(), save_reductions(), set_EFF(), set_maxrhs(), set_nullable(), show_cores(), and show_ritems().

short* rlhs

List of left-hand sides of all rules.

This array associates to each production its left-hand side symbol.

Definition at line 119 of file main.c.

Referenced by log_unused(), output_debug(), output_rule_data(), pack_grammar(), print_core(), print_grammar(), print_nulls(), set_derives(), set_nullable(), and show_cores().

short* rprec
short* RRconflicts

Definition at line 8 of file mkpar.c.

Referenced by log_conflicts(), print_state(), and remove_conflicts().

short* rrhs

List of right-hand sides of all rules.

Array of indices inside ritem. It is used record the position inside ritem where each rule begins.

Definition at line 126 of file main.c.

Referenced by build_relations(), closure(), initialize_states(), log_unused(), output_debug(), output_rule_data(), pack_grammar(), print_core(), print_nulls(), set_EFF(), show_cores(), and show_rrhs().

int RRtotal

Definition at line 6 of file mkpar.c.

Referenced by make_parser(), remove_conflicts(), total_conflicts(), and verbose().

short* rules_used

Definition at line 10 of file mkpar.c.

Referenced by log_unused(), and unused_rules().

shifts** shift_table

Definition at line 17 of file lalr.c.

Referenced by find_final_state(), free_shifts(), get_shifts(), print_actions(), and print_gotos().

short* SRconflicts

Definition at line 7 of file mkpar.c.

Referenced by log_conflicts(), print_state(), and remove_conflicts().

int SRtotal

Definition at line 5 of file mkpar.c.

Referenced by make_parser(), remove_conflicts(), total_conflicts(), and verbose().

int start_symbol

Index of the starting symbol of the grammar.

It holds that start_symbol = ntokens. In fact, the starting symbol is always placed at the beginning of the non-terminal range [ntokens, nsyms - 1].

Definition at line 82 of file main.c.

Referenced by free_derives(), goto_actions(), initialize_states(), output_rule_data(), pack_grammar(), pack_symbols(), set_derives(), set_EFF(), and set_first_derives().

core** state_table

Definition at line 16 of file lalr.c.

Referenced by free_itemsets(), and print_core().

char* symbol_assoc

Definition at line 93 of file main.c.

Referenced by get_shifts(), and pack_symbols().

char** symbol_name

Array of symbol names.

Array of strings representing the names of all symbols. All names are allocated in a single contiguous block of memory to improve locality.

Definition at line 90 of file main.c.

Referenced by log_unused(), output_debug(), output_defines(), pack_symbols(), print_conflicts(), print_core(), print_gotos(), print_grammar(), print_nulls(), print_reductions(), print_shifts(), set_nullable(), and show_cores().

short* symbol_prec

Definition at line 92 of file main.c.

Referenced by get_shifts(), and pack_symbols().

short* symbol_value
char* tables[]

Definition at line 30 of file skeleton.c.

Referenced by output().

FILE* text_file

Definition at line 33 of file main.c.

Referenced by copy_text(), copy_union(), done(), open_files(), and output_stored_text().

char* text_file_name

Definition at line 23 of file main.c.

Referenced by create_file_names(), done(), open_files(), and output_stored_text().

char tflag

Definition at line 7 of file main.c.

Referenced by getargs(), and output_debug().

char* trailer[]

Definition at line 225 of file skeleton.c.

Referenced by output().

FILE* union_file

Definition at line 35 of file main.c.

Referenced by copy_union(), done(), open_files(), and output_defines().

char* union_file_name

Definition at line 24 of file main.c.

Referenced by create_file_names(), done(), open_files(), and output_defines().

char unionized

Definition at line 16 of file reader.c.

Referenced by copy_union(), output_defines(), and output_stype().

char* verbose_file_name

Definition at line 25 of file main.c.

Referenced by create_file_names(), and open_files().

char vflag

Definition at line 8 of file main.c.

Referenced by create_file_names(), getargs(), open_files(), print_grammar(), and verbose().