105436638acc7c010349a69c3395f1a57c642dc62Ying Wang/* Type definitions for the finite state machine for Bison. 2cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 305436638acc7c010349a69c3395f1a57c642dc62Ying Wang Copyright (C) 1984, 1989, 2000-2004, 2007, 2009-2012 Free Software 405436638acc7c010349a69c3395f1a57c642dc62Ying Wang Foundation, Inc. 5cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 6cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project This file is part of Bison, the GNU Compiler Compiler. 7cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 805436638acc7c010349a69c3395f1a57c642dc62Ying Wang This program is free software: you can redistribute it and/or modify 9cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project it under the terms of the GNU General Public License as published by 1005436638acc7c010349a69c3395f1a57c642dc62Ying Wang the Free Software Foundation, either version 3 of the License, or 1105436638acc7c010349a69c3395f1a57c642dc62Ying Wang (at your option) any later version. 12cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 1305436638acc7c010349a69c3395f1a57c642dc62Ying Wang This program is distributed in the hope that it will be useful, 14cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project but WITHOUT ANY WARRANTY; without even the implied warranty of 15cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project GNU General Public License for more details. 17cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 18cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project You should have received a copy of the GNU General Public License 1905436638acc7c010349a69c3395f1a57c642dc62Ying Wang along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 21cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 22cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* These type definitions are used to represent a nondeterministic 23cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project finite state machine that parses the specified grammar. This 24cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project information is generated by the function generate_states in the 25cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project file LR0. 26cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 27cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Each state of the machine is described by a set of items -- 28cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project particular positions in particular rules -- that are the possible 29cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project places where parsing could continue when the machine is in this 30cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project state. These symbols at these items are the allowable inputs that 31cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project can follow now. 32cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 33cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project A core represents one state. States are numbered in the NUMBER 34cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project field. When generate_states is finished, the starting state is 35cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project state 0 and NSTATES is the number of states. (FIXME: This sentence 36cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project is no longer true: A transition to a state whose state number is 37cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project NSTATES indicates termination.) All the cores are chained together 38cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project and FIRST_STATE points to the first one (state 0). 39cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 40cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project For each state there is a particular symbol which must have been 41cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project the last thing accepted to reach that state. It is the 42cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project ACCESSING_SYMBOL of the core. 43cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 44cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Each core contains a vector of NITEMS items which are the indices 4505436638acc7c010349a69c3395f1a57c642dc62Ying Wang in the RITEM vector of the items that are selected in this state. 46cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 4705436638acc7c010349a69c3395f1a57c642dc62Ying Wang The two types of actions are shifts/gotos (push the lookahead token 48cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project and read another/goto to the state designated by a nterm) and 49cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project reductions (combine the last n things on the stack via a rule, 50cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project replace them with the symbol that the rule derives, and leave the 5105436638acc7c010349a69c3395f1a57c642dc62Ying Wang lookahead token alone). When the states are generated, these 52cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project actions are represented in two other lists. 53cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 54cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Each transition structure describes the possible transitions out 55cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project of one state, the state whose number is in the number field. Each 56cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project contains a vector of numbers of the states that transitions can go 57cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project to. The accessing_symbol fields of those states' cores say what 58cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project kind of input leads to them. 59cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 60cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project A transition to state zero should be ignored: conflict resolution 61cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project deletes transitions by having them point to zero. 62cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 63cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Each reductions structure describes the possible reductions at the 6405436638acc7c010349a69c3395f1a57c642dc62Ying Wang state whose number is in the number field. rules is an array of 6505436638acc7c010349a69c3395f1a57c642dc62Ying Wang num rules. lookahead_tokens is an array of bitsets, one per rule. 66cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 67cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Conflict resolution can decide that certain tokens in certain 68cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project states should explicitly be errors (for implementing %nonassoc). 69cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project For each state, the tokens that are errors for this reason are 70cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project recorded in an errs structure, which holds the token numbers. 71cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 72cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project There is at least one goto transition present in state zero. It 73cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project leads to a next-to-final state whose accessing_symbol is the 74cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project grammar's start symbol. The next-to-final state has one shift to 75cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project the final state, whose accessing_symbol is zero (end of input). 76cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project The final state has one shift, which goes to the termination state. 77cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project The reason for the extra state at the end is to placate the 78cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project parser's strategy of making all decisions one token ahead of its 79cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project actions. */ 80cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 81cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#ifndef STATE_H_ 82cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# define STATE_H_ 83cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 84cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# include <bitset.h> 85cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 86cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# include "gram.h" 87cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# include "symtab.h" 88cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 89cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 90cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/*-------------------. 91cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project| Numbering states. | 92cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project`-------------------*/ 93cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 94cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projecttypedef int state_number; 95cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# define STATE_NUMBER_MAXIMUM INT_MAX 96cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 97cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Be ready to map a state_number to an int. */ 98cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectstatic inline int 99cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectstate_number_as_int (state_number s) 100cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{ 101cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project return s; 102cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project} 103cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 104cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 105cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projecttypedef struct state state; 106cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 107cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/*--------------. 108cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project| Transitions. | 109cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project`--------------*/ 110cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 111cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projecttypedef struct 112cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{ 113cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project int num; 114cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project state *states[1]; 115cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project} transitions; 116cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 117cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 118cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* What is the symbol labelling the transition to 119cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project TRANSITIONS->states[Num]? Can be a token (amongst which the error 120cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project token), or non terminals in case of gotos. */ 121cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 122cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define TRANSITION_SYMBOL(Transitions, Num) \ 123cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project (Transitions->states[Num]->accessing_symbol) 124cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 125cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Is the TRANSITIONS->states[Num] a shift? (as opposed to gotos). */ 126cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 127cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define TRANSITION_IS_SHIFT(Transitions, Num) \ 128cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project (ISTOKEN (TRANSITION_SYMBOL (Transitions, Num))) 129cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 130cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Is the TRANSITIONS->states[Num] a goto?. */ 131cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 132cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define TRANSITION_IS_GOTO(Transitions, Num) \ 133cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project (!TRANSITION_IS_SHIFT (Transitions, Num)) 134cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 135cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Is the TRANSITIONS->states[Num] labelled by the error token? */ 136cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 137cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define TRANSITION_IS_ERROR(Transitions, Num) \ 138cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project (TRANSITION_SYMBOL (Transitions, Num) == errtoken->number) 139cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 140cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* When resolving a SR conflicts, if the reduction wins, the shift is 141cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project disabled. */ 142cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 143cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define TRANSITION_DISABLE(Transitions, Num) \ 144cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project (Transitions->states[Num] = NULL) 145cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 146cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define TRANSITION_IS_DISABLED(Transitions, Num) \ 147cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project (Transitions->states[Num] == NULL) 148cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 149cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 150cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Iterate over each transition over a token (shifts). */ 151cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#define FOR_EACH_SHIFT(Transitions, Iter) \ 152cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project for (Iter = 0; \ 153cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Iter < Transitions->num \ 154cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project && (TRANSITION_IS_DISABLED (Transitions, Iter) \ 155cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project || TRANSITION_IS_SHIFT (Transitions, Iter)); \ 156cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project ++Iter) \ 157cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project if (!TRANSITION_IS_DISABLED (Transitions, Iter)) 158cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 159cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 160cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Return the state such SHIFTS contain a shift/goto to it on SYM. 161cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project Abort if none found. */ 162cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectstruct state *transitions_to (transitions *shifts, symbol_number sym); 163cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 164cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 165cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/*-------. 166cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project| Errs. | 167cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project`-------*/ 168cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 169cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projecttypedef struct 170cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{ 171cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project int num; 172cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project symbol *symbols[1]; 173cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project} errs; 174cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 175cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projecterrs *errs_new (int num, symbol **tokens); 176cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 177cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 178cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/*-------------. 179cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project| Reductions. | 180cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project`-------------*/ 181cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 182cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projecttypedef struct 183cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{ 184cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project int num; 18505436638acc7c010349a69c3395f1a57c642dc62Ying Wang bitset *lookahead_tokens; 18605436638acc7c010349a69c3395f1a57c642dc62Ying Wang /* Sorted ascendingly on rule number. */ 187cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project rule *rules[1]; 188cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project} reductions; 189cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 190cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 191cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 192cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/*---------. 193cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project| states. | 194cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project`---------*/ 195cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 19605436638acc7c010349a69c3395f1a57c642dc62Ying Wangstruct state_list; 19705436638acc7c010349a69c3395f1a57c642dc62Ying Wang 198cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectstruct state 199cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{ 200cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project state_number number; 201cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project symbol_number accessing_symbol; 202cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project transitions *transitions; 203cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project reductions *reductions; 204cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project errs *errs; 205cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 20605436638acc7c010349a69c3395f1a57c642dc62Ying Wang /* When an includer (such as ielr.c) needs to store states in a list, the 20705436638acc7c010349a69c3395f1a57c642dc62Ying Wang includer can define struct state_list as the list node structure and can 20805436638acc7c010349a69c3395f1a57c642dc62Ying Wang store in this member a reference to the node containing each state. */ 20905436638acc7c010349a69c3395f1a57c642dc62Ying Wang struct state_list *state_list; 21005436638acc7c010349a69c3395f1a57c642dc62Ying Wang 21105436638acc7c010349a69c3395f1a57c642dc62Ying Wang /* If non-zero, then no lookahead sets on reduce actions are needed to 21205436638acc7c010349a69c3395f1a57c642dc62Ying Wang decide what to do in state S. */ 213cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project char consistent; 214cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 215cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project /* If some conflicts were solved thanks to precedence/associativity, 216cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project a human readable description of the resolution. */ 217cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project const char *solved_conflicts; 21805436638acc7c010349a69c3395f1a57c642dc62Ying Wang const char *solved_conflicts_xml; 219cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 22005436638acc7c010349a69c3395f1a57c642dc62Ying Wang /* Its items. Must be last, since ITEMS can be arbitrarily large. Sorted 22105436638acc7c010349a69c3395f1a57c642dc62Ying Wang ascendingly on item index in RITEM, which is sorted on rule number. */ 222cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project size_t nitems; 223cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project item_number items[1]; 224cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project}; 225cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 226cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectextern state_number nstates; 227cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectextern state *final_state; 228cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 229cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Create a new state with ACCESSING_SYMBOL for those items. */ 230cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectstate *state_new (symbol_number accessing_symbol, 231cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project size_t core_size, item_number *core); 23205436638acc7c010349a69c3395f1a57c642dc62Ying Wangstate *state_new_isocore (state const *s); 233cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 234cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Set the transitions of STATE. */ 235cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid state_transitions_set (state *s, int num, state **trans); 236cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 237cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Set the reductions of STATE. */ 238cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid state_reductions_set (state *s, int num, rule **reds); 239cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 240cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectint state_reduction_find (state *s, rule *r); 241cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 242cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Set the errs of STATE. */ 243cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid state_errs_set (state *s, int num, symbol **errors); 244cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 24505436638acc7c010349a69c3395f1a57c642dc62Ying Wang/* Print on OUT all the lookahead tokens such that this STATE wants to 246cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project reduce R. */ 24705436638acc7c010349a69c3395f1a57c642dc62Ying Wangvoid state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out); 24805436638acc7c010349a69c3395f1a57c642dc62Ying Wangvoid state_rule_lookahead_tokens_print_xml (state *s, rule *r, 24905436638acc7c010349a69c3395f1a57c642dc62Ying Wang FILE *out, int level); 250cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 251cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Create/destroy the states hash table. */ 252cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid state_hash_new (void); 253cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid state_hash_free (void); 254cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 255cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Find the state associated to the CORE, and return it. If it does 256cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project not exist yet, return NULL. */ 257cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectstate *state_hash_lookup (size_t core_size, item_number *core); 258cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 259cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Insert STATE in the state hash table. */ 260cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid state_hash_insert (state *s); 261cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 26205436638acc7c010349a69c3395f1a57c642dc62Ying Wang/* Remove unreachable states, renumber remaining states, update NSTATES, and 26305436638acc7c010349a69c3395f1a57c642dc62Ying Wang write to OLD_TO_NEW a mapping of old state numbers to new state numbers such 26405436638acc7c010349a69c3395f1a57c642dc62Ying Wang that the old value of NSTATES is written as the new state number for removed 26505436638acc7c010349a69c3395f1a57c642dc62Ying Wang states. The size of OLD_TO_NEW must be the old value of NSTATES. */ 26605436638acc7c010349a69c3395f1a57c642dc62Ying Wangvoid state_remove_unreachable_states (state_number old_to_new[]); 26705436638acc7c010349a69c3395f1a57c642dc62Ying Wang 268cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* All the states, indexed by the state number. */ 269cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectextern state **states; 270cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project 271cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Free all the states. */ 272cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectvoid states_free (void); 27305436638acc7c010349a69c3395f1a57c642dc62Ying Wang 274cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#endif /* !STATE_H_ */ 275