internal Object Unmarshal(HParsedToken tok) { // TODO switch (tok.token_type) { case HTokenType.TT_NONE: return(null); case HTokenType.TT_BYTES: { byte[] ret = new byte[tok.token_data.bytes.len]; Marshal.Copy(tok.token_data.bytes.token, ret, 0, ret.Length); return(ret); } case HTokenType.TT_SINT: return((System.Int64)tok.token_data.sint); case HTokenType.TT_UINT: return((System.UInt64)tok.token_data._uint); case HTokenType.TT_SEQUENCE: { Object[] ret = new Object[tok.token_data.seq.used]; for (uint i = 0; i < ret.Length; i++) { ret[i] = Unmarshal(tok.token_data.seq.at(i)); } return(ret); } default: if (tok.token_type == Hammer.tt_dotnet) { HTaggedToken tagged = hammer.h_parsed_token_get_tagged_token(tok); Object cb = Hammer.tag_to_action[tagged.label]; Object unmarshalled = Unmarshal(tagged.token); if (cb is HAction) { HAction act = (HAction)cb; return(act(unmarshalled)); } else if (cb is HPredicate) { HPredicate pred = (HPredicate)cb; if (!pred(unmarshalled)) { throw new ParseError("Predicate failed"); } else { return(unmarshalled); } } } throw new Exception("Should not reach here"); } }
internal static ulong RegisterPredicate(HPredicate predicate) { ulong newPredicate = (ulong)tag_to_action.Count; tag_to_action[newPredicate] = predicate; return(newPredicate); }
public LiftedNestedReducer(INestedReducer <γ, T> underlying, HPredicate <Cp, T> hPredicate, List <List <Tuple <int, int> > > multMap) { _underlying = underlying; _semiring = new LiftedSemiring <γ, Cp, T>(underlying.Semiring, hPredicate, multMap); _hPredicate = hPredicate; }
public LiftedSemiring(ISemiring <γ> semiring, HPredicate <Cp, T> p, List <List <Tuple <int, int> > > multMap) { // Sanity check to make sure there's an entry in the multiplication map for // each element of the predicate's state set if (multMap.Count != p.Symbols().Count) { throw new System.Exception(string.Format("Assert failed, multMap.Count = {0} p.Symbols().Count = {1}", multMap.Count, p.Symbols().Count)); } Debug.Assert(multMap.Count == p.Symbols().Count); _semiring = semiring; _p = p; _multMap = multMap; }
public static Parser AttrBool(Parser p, HPredicate predicate) { ulong predNo = Hammer.RegisterPredicate(predicate); return new Parser(hammer.h_tag(p.wrapped, predNo)).Pin(p).Pin(predicate); }
internal static ulong RegisterPredicate(HPredicate predicate) { ulong newPredicate = (ulong)tag_to_action.Count; tag_to_action[newPredicate] = predicate; return newPredicate; }
public static Parser AttrBool(Parser p, HPredicate predicate) { ulong predNo = Hammer.RegisterPredicate(predicate); return(new Parser(hammer.h_tag(p.wrapped, predNo)).Pin(p).Pin(predicate)); }