void lalr1( void ) { a_state *x; a_shift_action *tx; a_reduce_action *rx; a_look *lk, *look; a_word *lp, *lset; a_word *rp, *rset; InitSets( nterm ); lk = look = CALLOC( nvtrans + nstate, a_look ); lp = lset = AllocSet( nvtrans ); rp = rset = AllocSet( nredun ); for( x = statelist; x != NULL; x = x->next ) { x->look = lk; for( tx = x->trans; tx->sym != NULL; ++tx ) { if( tx->sym->pro != NULL ) { lk->trans = tx; lk->follow = lp; lp += GetSetSize( 1 ); ++lk; } } ++lk; for( rx = x->redun; rx->pro != NULL; ++rx ) { rx->follow = rp; rp += GetSetSize( 1 ); } } stk = CALLOC( nvtrans, a_look * ); top = stk; Nullable(); CalcReads(); CalcIncludes(); Lookback(); if( lk - look != nvtrans + nstate ) { puts( "internal error" ); } if( lp - lset != GetSetSize( nvtrans ) ) { puts( "internal error" ); } if( rp - rset != GetSetSize( nredun ) ) { puts( "internal error" ); } FREE( look ); FREE( lset ); FREE( stk ); Conflict(); nbstate = nstate; }
int* setToArray(Set *S){ int size = GetSetSize(S); int* array = (int*)malloc(sizeof(int)*size); int i; for (i = 0; i < size; i++){ array[i] = S->elem; S = S->next; } return array; }
static void Conflict( void ) { a_word *set; a_state *x; a_shift_action *tx; a_reduce_action *rx; a_reduce_action **reduce; set_size *work; set_size i; set = AllocSet( 1 ); reduce = CALLOC( nterm, a_reduce_action * ); work = CALLOC( nterm, set_size ); for( x = statelist; x != NULL; x = x->next ) { Clear( set ); for( tx = x->trans; tx->sym != NULL; ++tx ) { if( tx->sym->pro == NULL ) { SetBit( set, tx->sym->idx ); } } for( rx = x->redun; rx->pro != NULL; ++rx ) { for( i = 0; i < GetSetSize( 1 ); ++i ) { if( rx->follow[i] & set[i] ) { resolve( x, work, reduce ); break; } set[i] |= rx->follow[i]; } if( i < GetSetSize( 1 ) ) { break; } } } FREE( set ); FREE( reduce ); FREE( work ); }
GlyphSize scCachedStyle::GetEscapement( UCS2 ch ) { if ( GetDeviceValues() ) { if ( ch >= 256 ) return FIgetDEVEscapement( fSpec, ch ); if ( fWidths[ch] == kInvalMP ) { if ( GetSmallCaps() && CTIsLowerCase( ch ) ) fWidths[ch] = scRoundMP( FIgetDEVEscapement( fSpec, ::CTToUpper( ch ) ) * kSmallCapCorrection ); else fWidths[ch] = FIgetDEVEscapement( fSpec, GetCorrectedGlyph( ch ) ); } } else { REAL conversion; if ( fFlowDir.IsHorizontal() ) conversion = fSetConv; else conversion = fPtConv; if ( ch >= 256 ) { RLU rluWidth = FIgetRLUEscapement( fSpec, ch ); if ( rluWidth == scBaseRLUsystem ) { if ( fFlowDir.IsHorizontal() ) return GetSetSize(); else return GetPtSize(); } return scRoundGS( conversion * rluWidth ) + GetOptLSP(); } if ( fWidths[ch] == kInvalMP ) { // it has not been previously computed switch ( ch ) { default: { RLU rluWidth; if ( GetSmallCaps() && CTIsLowerCase( ch ) ) rluWidth = (RLU)scRoundGS( FIgetRLUEscapement( fSpec, ::CTToUpper( ch ) ) * kSmallCapCorrection ); else rluWidth = FIgetRLUEscapement( fSpec, GetCorrectedGlyph( ch ) ); if ( rluWidth == scBaseRLUsystem ) { fWidths[ch] = scRoundMP( conversion * rluWidth ); if ( fFlowDir.IsHorizontal() ) fWidths[ch] = GetSetSize() + GetOptLSP(); else fWidths[ch] = GetPtSize() + GetOptLSP(); } else fWidths[ch] = scRoundMP( conversion * rluWidth ); } break; case 0: case scVertTab: case scHardReturn: if ( fFlowDir.IsHorizontal() ) fWidths[ch] = GetSetSize(); else fWidths[ch] = GetPtSize(); break; case scNoBreakSpace: fWidths[ch] = GetOptWord(); break; // these really need to be further up stream case scNoBreakHyph: case scDiscHyphen: fWidths[ch] = 0; break; case scFigureSpace: fWidths[ch] = scRoundMP( conversion * FIgetRLUEscapement( fSpec, '0' ) ); break; case scThinSpace: fWidths[ch] = scRoundMP( conversion * scBaseRLUsystem / 6 ); break; case scEnSpace: fWidths[ch] = scRoundMP( conversion * scBaseRLUsystem / 2 ); break; case scEmSpace: fWidths[ch] = scRoundMP( conversion * scBaseRLUsystem ); break; } } if ( fWidths[ch] == 0 ) return 0; } return fWidths[ch] + GetOptLSP(); }
void scCachedStyle::ComputeExtentsnCursor( void ) { if ( GetDeviceValues() ) { scXRect rect; MicroPoint a,b,c,d; FIgetDEVFontExtents( fSpec, a, b, c, d, rect ); if ( fFlowDir.IsHorizontal() ) { scAssert( rect.Valid( eFirstQuad ) ); rect.FirstToFourth( GetPtSize() ); scAssert( rect.Valid( eFourthQuad ) ); fInkExtents.y1 = rect.y1; fInkExtents.y2 = rect.y2; fInkExtents.x1 = rect.x1; fInkExtents.x2 = rect.x2; } else { fInkExtents.y1 = 0; fInkExtents.y2 = rect.y1 - rect.y2; fInkExtents.x1 = -(rect.x2/2) - rect.x1; fInkExtents.x2 = rect.x2/2; } } else { scRLURect rect; RLU a,b,c,d; FIgetRLUFontExtents( fSpec, a, b, c, d, rect ); if ( fFlowDir.IsHorizontal() ) { scAssert( rect.Valid( eFirstQuad ) ); rect.FirstToFourth( scBaseRLUsystem ); } scAssert( rect.Valid( eFourthQuad ) ); fInkExtents.y1 = scRoundMP( fPtConv * rect.rluTop ); fInkExtents.y2 = scRoundMP( fPtConv * rect.rluBottom ); fInkExtents.x1 = scRoundMP( fSetConv * rect.rluLeft ); fInkExtents.x2 = scRoundMP( fSetConv * rect.rluRight ); } REAL obliqOff = 0; if ( GetHorzOblique() ) obliqOff = (REAL)tan( AngleToRadians( GetHorzOblique() ) ); if ( GetHorzOblique() < 0 ) fInkExtents.x1 += scRoundMP( GetPtSize() * obliqOff ); if ( GetHorzOblique() < 0 ) fInkExtents.x2 += scRoundMP( GetPtSize() * obliqOff ); scAssert( fInkExtents.Valid( eFourthQuad ) ); if ( fFlowDir.IsHorizontal() ) fInkExtents.Translate( 0, -GetBaseline() ); else fInkExtents.Translate( GetBaseline(), 0 ); if ( fFlowDir.IsHorizontal() ) { scLEADRefData ld; ld.Set( GetPtSize(), fFlowDir ); fLogicalExtents.Set( 0, -ld.GetAboveLead(), GetSetSize(), ld.GetBelowLead() ); } else fLogicalExtents.Set( -GetSetSize()/2, 0, GetSetSize()/2, GetPtSize() ); if ( fFlowDir.IsHorizontal() ) { fCursorY1 = -scRoundMP( fPtConv * RLU_BASEfmTop ); fCursorY2 = scRoundMP( fPtConv * RLU_BASEfmBottom ); } else { fCursorX1 = -GetSetSize() / 2; fCursorX2 = GetSetSize() / 2; } }
static AddError() { a_sym *xsym, *sym; a_pro *xpro, *pro; a_state *x, **s, **t, *AddErrState(); a_shift_action *tx, *ty, *trans; a_reduce_action *rx, *ry, *redun; int i; a_word *defined, *conflict, *rset; short int *at; trans = CALLOC( nsym, a_shift_action ); rx = redun = CALLOC( npro + 1, a_reduce_action ); rset = conflict = AllocSet( npro + 2 ); for( i = 0; i <= npro; ++i ) { (rx++)->follow = rset; rset += GetSetSize( 1 ); } defined = rset; s = CALLOC( nstate, a_state * ); at = CALLOC( nstate, short int ); s = t = CALLOC( nstate + 1, a_state * ); for( x = statelist; x != NULL; x = x->next ) { Mark( *x ); *t++ = x; } restart = AddErrState( &errsym->enter, s, t ); for( x = restart; x != NULL; x = x->next ) { Clear( defined ); Clear( conflict ); xpro = NULL; for( i = 0; i < x->kersize; ++i ) { at[i] = 0; pro = x->name.state[i]->redun->pro; if( pro > xpro ) { xpro = pro; } } redun->pro = errpro; rx = redun + 1; if( x != restart ) while( xpro ) { pro = xpro; xpro = NULL; Clear( rx->follow ); for( i = 0; i < x->kersize; ++i ) { ry = &x->name.state[i]->redun[at[i]]; if( ry->pro == pro ) { Union( rx->follow, ry->follow ); ++(at[i]); ++ry; } if( ry->pro > xpro ) { xpro = ry->pro; } } UnionAnd( conflict, rx->follow, defined ); Union( defined, rx->follow ); rx->pro = pro; ++rx; } xsym = NULL; for( i = 0; i < x->kersize; ++i ) { at[i] = 0; sym = x->name.state[i]->trans->sym; if( sym > xsym ) { xsym = sym; } } tx = trans; while( xsym ) { sym = xsym; xsym = NULL; t = s; for( i = 0; i < x->kersize; ++i ) { ty = &x->name.state[i]->trans[at[i]]; if( ty->sym == sym ) { if( !IsMarked( *ty->state ) ) { Mark( *ty->state ); *t++ = ty->state; } ++(at[i]); ++ty; } if( ty->sym > xsym ) { xsym = ty->sym; } } tx->sym = sym; if( sym->pro != NULL ) { ++nvtrans; } else { if( IsBitSet( defined, sym->id ) ) { SetBit( conflict, sym->id ); while( --t >= s ) { Unmark( **t ); } continue; } else { SetBit( defined, sym->id ); } } tx->state = AddErrState( &errsym->enter, s, t ); ++tx; } x->trans = CALLOC( tx - trans + 1, a_shift_action ); memcpy( x->trans, trans, ((char *) tx) - ((char *) trans) ); if( Empty( conflict ) ) { redun->pro = NULL; i = 0; } else { i = 1; } while( --rx > redun ) { AndNot( rx->follow, conflict ); if( Empty( rx->follow ) ) { rx->pro = NULL; } else { ++i; } } x->redun = CALLOC( i + 1, a_reduce_action ); if( i ) { rset = AllocSet( i ); rx = redun; while( i > 0 ) { if( rx->pro != NULL ) { --i; x->redun[i].pro = rx->pro; x->redun[i].follow = rset; Assign( rset, rx->follow ); rset += GetSetSize( 1 ); } ++rx; } } } FREE( trans ); FREE( redun ); FREE( conflict ); FREE( s ); FREE( at ); }