Exemple #1
0
        public string GenerateBinaryCode(string content, Dictionary<string, string> encodeTable, DslLogDelegation logCallback)
        {
            #if FULL_VERSION
            List<DslInfo> infos = new List<DslInfo>();
            Parser.DslLog log = new Parser.DslLog();
            log.OnLog += logCallback;
            Parser.DslToken tokens = new Parser.DslToken(log, content);
            Parser.DslError error = new Parser.DslError(log, tokens);
            Parser.RuntimeAction action = new Parser.RuntimeAction(infos);
            action.onGetLastToken = () => { return tokens.getLastToken(); };
            action.onGetLastLineNumber = () => { return tokens.getLastLineNumber(); };
            action.onSetStringDelimiter = (string begin, string end) => { tokens.setStringDelimiter(begin, end); };
            action.onSetScriptDelimiter = (string begin, string end) => { tokens.setScriptDelimiter(begin, end); };
            Parser.DslParser.parse(action, tokens, error, 0);
            if (error.HasError) {
                return string.Empty;
            } else {
                MemoryStream stream = new MemoryStream();
                List<string> identifiers = new List<string>();
                foreach (DslInfo info in infos) {
                    Utility.writeBinary(stream, identifiers, (StatementData)info);
                }

                byte[] bytes = stream.ToArray();
                SortedDictionary<string, int> dict = new SortedDictionary<string, int>();
                int ct = identifiers.Count;
                if (ct > 0x00004000) {
                    System.Diagnostics.Debug.Assert(false);
                    //Console.WriteLine("Identifiers count {0} too large than 0x04000", ct);
                    return string.Empty;
                }
                for (int i = 0; i < ct; ++i) {
                    string key = identifiers[i];
                    key = Encode(key, encodeTable);
                    identifiers[i] = key;
                    if (!dict.ContainsKey(key)) {
                        dict.Add(key, 0);
                    }
                }
                List<string> keys = new List<string>(dict.Keys);
                byte[] bytes2;
                using (MemoryStream ms = new MemoryStream()) {
                    for (int i = 0; i < ct; ++i) {
                        string key = identifiers[i];
                        int ix = keys.BinarySearch(key);
                        if (ix < 0x80) {
                            ms.WriteByte((byte)ix);
                        } else {
                            ms.WriteByte((byte)((ix & 0x0000007f) | 0x00000080));
                            ms.WriteByte((byte)(ix >> 7));
                        }
                    }
                    bytes2 = ms.ToArray();
                }
                return string.Format("{0}|{1}|{2}", Convert.ToBase64String(bytes), Convert.ToBase64String(bytes2), string.Join("`", keys.ToArray()));
            }
            #else
              return string.Empty;
            #endif
        }
Exemple #2
0
        public bool LoadFromString(string content, string resourceName, DslLogDelegation logCallback)
        {
            #if FULL_VERSION
            mDslInfos.Clear();
            Parser.DslLog log = new Parser.DslLog();
            log.OnLog += logCallback;
            Parser.DslToken tokens = new Parser.DslToken(log, content);
            Parser.DslError error = new Parser.DslError(log, tokens);
            Parser.RuntimeAction action = new Parser.RuntimeAction(mDslInfos);
            action.onGetLastToken = () => { return tokens.getLastToken(); };
            action.onGetLastLineNumber = () => { return tokens.getLastLineNumber(); };
            action.onGetComment = (out bool commentOnNewLine) => { commentOnNewLine = tokens.IsCommentOnNewLine(); List<string> ret = new List<string>();ret.AddRange(tokens.GetComments()); tokens.ResetComments(); return ret; };
            action.onSetStringDelimiter = (string begin, string end) => { tokens.setStringDelimiter(begin, end); };
            action.onSetScriptDelimiter = (string begin, string end) => { tokens.setScriptDelimiter(begin, end); };

            Parser.DslParser.parse(action, tokens, error, 0);
            if (error.HasError) {
                for (int i = 0; i < mDslInfos.Count; i++) {
                    mDslInfos[i].Clear();
                }
            } else {
                for (int i = 0; i < mDslInfos.Count; i++) {
                    mDslInfos[i].SetResourceName(resourceName);
                }
            }
            return !error.HasError;
            #else
              return false;
            #endif
        }
Exemple #3
0
 internal void message(string message, ref DslToken dslToken)
 {
     mHasError = true;
     mLog.Log("[info] {0}, last token {1} line {2}, cur token {3} line {4}", message, dslToken.getLastToken(), dslToken.getLastLineNumber(), dslToken.getCurToken(), dslToken.getLineNumber());
 }
Exemple #4
0
 internal void input_left(ref DslToken dslToken)
 {
     mHasError = true;
     mLog.Log("[error] input left, last token {0} line {1}, cur token {2} line {3}", dslToken.getLastToken(), dslToken.getLastLineNumber(), dslToken.getCurToken(), dslToken.getLineNumber());
 }
Exemple #5
0
 internal short no_entry(short nonterminal, short token, int level, ref DslToken dslToken)
 {
     mHasError = true;
     mLog.Log("[error] syntax error: skipping input {0}, last token {1} line {2}, cur token {3} line {4}", DslString.GetSymbolName(token), dslToken.getLastToken(), dslToken.getLastLineNumber(), dslToken.getCurToken(), dslToken.getLineNumber());
     token = dslToken.get(); // advance the input
     return(token);
 }
Exemple #6
0
 internal short mismatch(short terminal, short token, ref DslToken dslToken)
 {
     mHasError = true;
     mLog.Log("[error] expecting {0} but found {1}, last token {2} line {3}, cur token {4} line {5}", DslString.GetSymbolName(terminal), DslString.GetSymbolName(token), dslToken.getLastToken(), dslToken.getLastLineNumber(), dslToken.getCurToken(), dslToken.getLineNumber());
     return(token);
 }
Exemple #7
0
Fichier : Dsl.cs Projet : CQiao/DSL
    public bool LoadFromString(string content, string resourceName, DslLogDelegation logCallback)
    {
#if FULL_VERSION
      mDslInfos.Clear();
      Parser.DslLog log = new Parser.DslLog();
      log.OnLog += logCallback;
		  Parser.DslToken tokens = new Parser.DslToken(log, content);
		  Parser.DslError error = new Parser.DslError(log, tokens);
      Parser.RuntimeAction action = new Parser.RuntimeAction(mDslInfos);
      action.onGetLastToken = () => { return tokens.getLastToken(); };
      action.onGetLastLineNumber = () => { return tokens.getLastLineNumber(); };
		  Parser.DslParser.parse(action,tokens,error,0);
		  if(error.HasError)
		  {
        for (int i = 0; i < mDslInfos.Count; i++ )
        {
          mDslInfos[i].Clear();
        }
		  }
      else
      {
        for (int i = 0; i < mDslInfos.Count; i++)
        {
          mDslInfos[i].SetResourceName(resourceName);
        }
		  }
		  return !error.HasError;
#else
      return false;
#endif
    }