Exemple #1
0
        private void IgnoreString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;

            do
            {
                curChar = charStream.ReadChar();
            }while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                   curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#');
            charStream.Backup(1);
        }
Exemple #2
0
        private void IgnoreSpace(SimpleCharStream charStream)
        {
            char curChar;

            do
            {
                curChar = charStream.ReadChar();
                if (curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }while(curChar == ' ' || curChar == '\t' || curChar == '\n' || curChar == '\r');
            charStream.Backup(1);
        }
Exemple #3
0
 public SMParser(System.IO.TextReader stream)
 {
     mcc_input_stream = new SimpleCharStream(stream, 1, 1);
     token_source     = new SMParserTokenManager(mcc_input_stream);
     token            = new Token();
     mcc_ntk          = -1;
     mcc_gen          = 0;
     for (int i = 0; i < 13; i++)
     {
         mcc_la1[i] = -1;
     }
     for (int i = 0; i < mcc_2_rtns.Length; i++)
     {
         mcc_2_rtns[i] = new MccCalls();
     }
 }
Exemple #4
0
        private void IgnoreOther(SimpleCharStream charStream)
        {
            char curChar;

            do
            {
                curChar = charStream.ReadChar();
                if (curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }while(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                     curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'));
            charStream.Backup(1);
        }
Exemple #5
0
        private String ReadString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char          curChar;
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                curChar = charStream.ReadChar();
                if (!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                      curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'))
                {
                    break;
                }
                sb.Append(curChar);
            }
            charStream.Backup(1);
            return(sb.ToString());
        }
Exemple #6
0
        private String ReadQuotedString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            MatchCharOrThrow(charStream, '\"');

            char          curChar;
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                curChar = charStream.ReadChar();
                if (curChar == '\"')
                {
                    break;
                }
                sb.Append(curChar);
            }
            return(sb.ToString());
        }
Exemple #7
0
        private bool MatchString(SimpleCharStream charStream, String str)
        {
            IgnoreSpace(charStream);

            char curChar;

            for (int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if (curChar != str[i])
                {
                    charStream.Backup(i + 1);       // unread chars
                    return(false);
                }
            }
            curChar = charStream.ReadChar();
            if (curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                charStream.Backup(str.Length + 1);  // unread chars
                return(false);
            }
            return(true);
        }
Exemple #8
0
        // scans through a gm on the search for model usages
        private void GetNeededFiles(String basePath, String modelName, List<String> neededFiles,
            Dictionary<String, object> processedModelFiles)
        {
            processedModelFiles[modelName] = null;

            if(!File.Exists(modelName))
                throw new FileNotFoundException("Used model file \"" + modelName + "\" does not exist!");

            using(StreamReader reader = new StreamReader(modelName))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char curChar;
                try
                {
                    if(MatchString(charStream, "#using"))
                    {
                        String usedModelName = ReadQuotedString(charStream);
                        usedModelName = basePath + FixDirectorySeparators(usedModelName);
                        neededFiles.Add(usedModelName);
                        GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                    }

                    if(MatchString(charStream, "using"))
                    {
                        while(true)
                        {
                            String usedModelName = ReadString(charStream);
                            neededFiles.Add(basePath + usedModelName + ".gm");
                            GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if(curChar == ';') break;
                            if(curChar != ',')
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                    + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                        }
                    }

                    // search the rest of the file for include tokens
                    while(true)
                    {
                        curChar = charStream.ReadChar();
 
                        if(curChar == '\\') charStream.ReadChar();			// skip escape sequences
                        else if(curChar == '/') IgnoreComment(charStream);
                        else if(curChar == '"')
                        {
                            while(true)
                            {
                                curChar = charStream.ReadChar();
                                if(curChar == '"') break;
                                else if(curChar == '\\') charStream.ReadChar();		// skip escape sequence
                            }
                        }
                        else if(MatchString(charStream, "#using"))
                        {
                            String usedModelName = ReadQuotedString(charStream);
                            usedModelName = basePath + FixDirectorySeparators(usedModelName);
                            neededFiles.Add(usedModelName);
                            GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                        }
                        else if(curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while(true)
                            {
                                String usedModelName = ReadString(charStream);
                                neededFiles.Add(basePath + usedModelName + ".gm");
                                GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if(curChar == ';') break;
                                if(curChar != ',')
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                        + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }
                }
                catch(IOException)
                {
                    // end of file reached
                }
            }
        }
Exemple #9
0
        private void IgnoreString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;
            do
            {
                curChar = charStream.ReadChar();
            }
            while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#');
            charStream.Backup(1);
        }
Exemple #10
0
        private void IgnoreOther(SimpleCharStream charStream)
        {
            char curChar;
            do
            {
                curChar = charStream.ReadChar();
                if(curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }
            while(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'));
            charStream.Backup(1);
        }
Exemple #11
0
        private String ReadString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;
            StringBuilder sb = new StringBuilder();
            while(true)
            {
                curChar = charStream.ReadChar();
                if(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
						|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'))
                    break;
                sb.Append(curChar);
            }
            charStream.Backup(1);
            return sb.ToString();
        }
Exemple #12
0
        /// <summary>
        /// Ignores the rest of a string.
        /// </summary>
        /// <param name="charStream">The SimpleCharStream object.</param>
        /// <param name="curChar">The last character read. Set to '\0' to ignore.</param>
        private void IgnoreRest(SimpleCharStream charStream, char curChar)
        {
            while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#')
            {
                curChar = charStream.ReadChar();
            }
            charStream.Backup(1);
        }
Exemple #13
0
 private void IgnoreSpace(SimpleCharStream charStream)
 {
     char curChar;
     do
     {
         curChar = charStream.ReadChar();
         if(curChar == '/')
         {
             IgnoreComment(charStream);
             curChar = ' ';
             continue;
         }
     }
     while(curChar == ' ' || curChar == '\t' || curChar == '\n' || curChar == '\r');
     charStream.Backup(1);
 }
Exemple #14
0
        private String ReadQuotedString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            MatchCharOrThrow(charStream, '\"');

            char curChar;
            StringBuilder sb = new StringBuilder();
            while(true)
            {
                curChar = charStream.ReadChar();
                if(curChar == '\"')
                    break;
                sb.Append(curChar);
            }
            return sb.ToString();
        }
public void ReInit(SimpleCharStream stream)
{
   jjmatchedPos = jjnewStateCnt = 0;
   curLexState = defaultLexState;
   input_stream = stream;
   ReInitRounds();
}
 /// <summary>Constructor.</summary>
 public SMARTSParserTokenManager(SimpleCharStream stream, int lexState)
     : this(stream)
 {
     SwitchTo(lexState);
 }
 public IDLParser(System.IO.StreamReader stream) {
   jj_input_stream = new SimpleCharStream(stream, 1, 1);
   token_source = new IDLParserTokenManager(jj_input_stream);
   token = new Token();
   jj_ntk = -1;
   jj_gen = 0;
   for (int i = 0; i < 88; i++) jj_la1[i] = -1;
   for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
 }
public IDLParserTokenManager(SimpleCharStream stream)
{
   if (SimpleCharStream.staticFlag)
      throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
   input_stream = stream;
}
Exemple #19
0
        // scans through a grg on the search for model usages and rule file inclusions
        // processedActionFiles are for preventing circular includes, full path
        // processedModelFiles are for determining the amount of models, getting the name of the one model in case it's only one
        private void GetNeededFiles(String basePath, String grgFilename, List <String> neededFiles,
                                    Dictionary <String, object> processedActionFiles, Dictionary <String, object> processedModelFiles)
        {
            if (processedActionFiles.ContainsKey(grgFilename))
            {
                throw new Exception("Circular include detected with file \"" + grgFilename + "\"!");
            }
            processedActionFiles[grgFilename] = null;

            if (!File.Exists(grgFilename))
            {
                throw new FileNotFoundException("Included file \"" + grgFilename + "\" does not exist!");
            }

            using (StreamReader reader = new StreamReader(grgFilename))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char             curChar;
                try
                {
                    // check optional header

                    bool needSemicolon = false;

                    // read optional "actions <name>"
                    if (MatchString(charStream, "actions"))
                    {
                        needSemicolon = true;
                        IgnoreString(charStream);                                       // ignore actions name
                    }

                    if (MatchString(charStream, "#include"))
                    {
                        String includedGRG = ReadQuotedString(charStream);
                        includedGRG = basePath + FixDirectorySeparators(includedGRG);
                        neededFiles.Add(includedGRG);
                        GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
                    }

                    if (MatchString(charStream, "#using"))
                    {
                        String modelName = ReadQuotedString(charStream);
                        modelName = basePath + FixDirectorySeparators(modelName);
                        neededFiles.Add(modelName);
                        GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                    }

                    if (MatchString(charStream, "using"))
                    {
                        while (true)
                        {
                            String modelName = ReadString(charStream);
                            neededFiles.Add(basePath + modelName + ".gm");
                            GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if (curChar == ';')
                            {
                                break;
                            }
                            if (curChar != ',')
                            {
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                    + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }
                    else if (needSemicolon)
                    {
                        IgnoreSpace(charStream);
                        MatchCharOrThrow(charStream, ';');
                    }

                    // search the rest of the file for includes and usings
                    while (true)
                    {
                        curChar = charStream.ReadChar();

                        if (curChar == '#' && MatchString(charStream, "include"))
                        {
                            String includedGRG = ReadQuotedString(charStream);
                            includedGRG = basePath + FixDirectorySeparators(includedGRG);
                            neededFiles.Add(includedGRG);
                            GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
                        }
                        else if (curChar == '\\')
                        {
                            charStream.ReadChar();                      // skip escape sequences
                        }
                        else if (curChar == '/')
                        {
                            IgnoreComment(charStream);
                        }
                        else if (curChar == '"')
                        {
                            while (true)
                            {
                                curChar = charStream.ReadChar();
                                if (curChar == '"')
                                {
                                    break;
                                }
                                else if (curChar == '\\')
                                {
                                    charStream.ReadChar();              // skip escape sequence
                                }
                            }
                        }
                        else if (curChar == '#' && MatchString(charStream, "using"))
                        {
                            String modelName = ReadQuotedString(charStream);
                            modelName = basePath + FixDirectorySeparators(modelName);
                            neededFiles.Add(modelName);
                            GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                        }
                        else if (curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while (true)
                            {
                                String modelName = ReadString(charStream);
                                neededFiles.Add(basePath + modelName + ".gm");
                                GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if (curChar == ';')
                                {
                                    break;
                                }
                                if (curChar != ',')
                                {
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                        + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                                }
                            }
                        }
                    }
                }
                catch (IOException)
                {
                    // end of file reached
                }
            }
        }
Exemple #20
0
        // scans through a grg on the search for model usages and rule file inclusions
        // processedActionFiles are for preventing circular includes, full path
        // processedModelFiles are for determining the amount of models, getting the name of the one model in case it's only one
        private void GetNeededFiles(String basePath, String grgFilename, List<String> neededFiles,
            Dictionary<String, object> processedActionFiles, Dictionary<String, object> processedModelFiles)
        {
            if(processedActionFiles.ContainsKey(grgFilename))
                throw new Exception("Circular include detected with file \"" + grgFilename + "\"!");
            processedActionFiles[grgFilename] = null;

            if(!File.Exists(grgFilename))
				throw new FileNotFoundException("Included file \"" + grgFilename + "\" does not exist!");

            using(StreamReader reader = new StreamReader(grgFilename))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char curChar;
                try
                {
                    // check optional header

                    bool needSemicolon = false;

                    // read optional "actions <name>"
                    if(MatchString(charStream, "actions"))
                    {
                        needSemicolon = true;
                        IgnoreString(charStream);                                       // ignore actions name
                    }

					if(MatchString(charStream, "#include"))
					{
						String includedGRG = ReadQuotedString(charStream);
						includedGRG = basePath + FixDirectorySeparators(includedGRG);
						neededFiles.Add(includedGRG);
						GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
					}

                    if(MatchString(charStream, "#using"))
                    {
                        String modelName = ReadQuotedString(charStream);
                        modelName = basePath + FixDirectorySeparators(modelName);
                        neededFiles.Add(modelName);
                        GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                    }

                    if(MatchString(charStream, "using"))
                    {
                        while(true)
                        {
                            String modelName = ReadString(charStream);
                            neededFiles.Add(basePath + modelName + ".gm");
                            GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if(curChar == ';') break;
                            if(curChar != ',')
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                    + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                        }
                    }
                    else if(needSemicolon)
                    {
                        IgnoreSpace(charStream);
                        MatchCharOrThrow(charStream, ';');
                    }

                    // search the rest of the file for includes and usings
                    while(true)
                    {
                        curChar = charStream.ReadChar();
						
                        if(curChar == '#' && MatchString(charStream, "include"))
						{
							String includedGRG = ReadQuotedString(charStream);
							includedGRG = basePath + FixDirectorySeparators(includedGRG);
							neededFiles.Add(includedGRG);
                            GetNeededFiles(basePath, includedGRG, neededFiles, processedActionFiles, processedModelFiles);
						}
                        else if(curChar == '\\') charStream.ReadChar();			// skip escape sequences
						else if(curChar == '/') IgnoreComment(charStream);
						else if(curChar == '"')
						{
							while(true)
							{
								curChar = charStream.ReadChar();
								if(curChar == '"') break;
								else if(curChar == '\\') charStream.ReadChar();		// skip escape sequence
							}
						}
                        else if(curChar == '#' && MatchString(charStream, "using"))
                        {
                            String modelName = ReadQuotedString(charStream);
                            modelName = basePath + FixDirectorySeparators(modelName);
                            neededFiles.Add(modelName);
                            GetNeededFiles(basePath, modelName, neededFiles, processedModelFiles);
                        }
                        else if(curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while(true)
                            {
                                String modelName = ReadString(charStream);
                                neededFiles.Add(basePath + modelName + ".gm");
                                GetNeededFiles(basePath, basePath + modelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if(curChar == ';') break;
                                if(curChar != ',')
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                        + "' in '" + grgFilename + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }
                }
                catch(IOException)
                {
                    // end of file reached
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// Tries to match a string at the current position of a SimpleCharStream.
        /// If the string at the current position does not match, it is skipped.
        /// Here all characters other than A-Z, a-z, 0-9, _, and # are skipped.
        /// </summary>
        /// <param name="charStream">The char stream.</param>
        /// <param name="str">The string to be matched.</param>
        /// <returns>True, iff the string was found.</returns>
        private bool MatchStringOrIgnoreOther(SimpleCharStream charStream, String str)
        {
            IgnoreOther(charStream);

            char curChar;
            for(int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if(curChar != str[i])
                {
                    IgnoreRest(charStream, curChar);
                    return false;
                }
            }

            // Does the string really end here?
            curChar = charStream.ReadChar();
            if(curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                IgnoreRest(charStream, curChar);
                return false;
            }
            return true;
        }
Exemple #22
0
        private bool MatchString(SimpleCharStream charStream, String str)
        {
            IgnoreSpace(charStream);

            char curChar;
            for(int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if(curChar != str[i])
                {
                    charStream.Backup(i + 1);       // unread chars
                    return false;
                }
            }
            curChar = charStream.ReadChar();
            if(curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                charStream.Backup(str.Length + 1);  // unread chars
                return false;
            }
            return true;
        }
Exemple #23
0
 private void MatchCharOrThrow(SimpleCharStream charStream, char ch)
 {
     char curChar = charStream.ReadChar();
     if(curChar != ch)
         throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar) + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
 }
Exemple #24
0
        // scans through a gm on the search for model usages
        private void GetNeededFiles(String basePath, String modelName, List <String> neededFiles,
                                    Dictionary <String, object> processedModelFiles)
        {
            processedModelFiles[modelName] = null;

            if (!File.Exists(modelName))
            {
                throw new FileNotFoundException("Used model file \"" + modelName + "\" does not exist!");
            }

            using (StreamReader reader = new StreamReader(modelName))
            {
                SimpleCharStream charStream = new SimpleCharStream(reader);
                char             curChar;
                try
                {
                    if (MatchString(charStream, "#using"))
                    {
                        String usedModelName = ReadQuotedString(charStream);
                        usedModelName = basePath + FixDirectorySeparators(usedModelName);
                        neededFiles.Add(usedModelName);
                        GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                    }

                    if (MatchString(charStream, "using"))
                    {
                        while (true)
                        {
                            String usedModelName = ReadString(charStream);
                            neededFiles.Add(basePath + usedModelName + ".gm");
                            GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                            IgnoreSpace(charStream);
                            curChar = charStream.ReadChar();
                            if (curChar == ';')
                            {
                                break;
                            }
                            if (curChar != ',')
                            {
                                throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                    + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                            }
                        }
                    }

                    // search the rest of the file for include tokens
                    while (true)
                    {
                        curChar = charStream.ReadChar();

                        if (curChar == '\\')
                        {
                            charStream.ReadChar();                      // skip escape sequences
                        }
                        else if (curChar == '/')
                        {
                            IgnoreComment(charStream);
                        }
                        else if (curChar == '"')
                        {
                            while (true)
                            {
                                curChar = charStream.ReadChar();
                                if (curChar == '"')
                                {
                                    break;
                                }
                                else if (curChar == '\\')
                                {
                                    charStream.ReadChar();              // skip escape sequence
                                }
                            }
                        }
                        else if (MatchString(charStream, "#using"))
                        {
                            String usedModelName = ReadQuotedString(charStream);
                            usedModelName = basePath + FixDirectorySeparators(usedModelName);
                            neededFiles.Add(usedModelName);
                            GetNeededFiles(basePath, usedModelName, neededFiles, processedModelFiles);
                        }
                        else if (curChar == 'u' && MatchString(charStream, "sing"))
                        {
                            while (true)
                            {
                                String usedModelName = ReadString(charStream);
                                neededFiles.Add(basePath + usedModelName + ".gm");
                                GetNeededFiles(basePath, basePath + usedModelName + ".gm", neededFiles, processedModelFiles);
                                IgnoreSpace(charStream);
                                curChar = charStream.ReadChar();
                                if (curChar == ';')
                                {
                                    break;
                                }
                                if (curChar != ',')
                                {
                                    throw new Exception("Parse error: Unexpected token '" + GetPrintable(curChar)
                                                        + "' in '" + basePath + modelName + ".gm" + "' at line " + charStream.EndLine + ":" + charStream.EndColumn + "!");
                                }
                            }
                        }
                    }
                }
                catch (IOException)
                {
                    // end of file reached
                }
            }
        }
Exemple #25
0
 /// <summary>Constructor with Stream</summary>
 public TsurgeonParser( /*java.io.InputStream*/ Stream stream, string encoding)
 {
     try
     {
         jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1);
     }
     catch ( /*java.io.UnsupportedEncodingException*/Exception e)
     {
         throw new SystemException(e.Message);
     }
     token_source = new TsurgeonParserTokenManager(jj_input_stream);
     token = new Token();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 10; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls();
 }
Exemple #26
0
        public bool Include(String filename, String from, String to)
        {
            try
            {
                if (showIncludes)
                {
                    impl.debugOut.WriteLine("Including " + filename);
                }

                TextReader reader = null;
                if (filename.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase))
                {
                    FileStream filereader = new FileStream(filename, FileMode.Open, FileAccess.Read);
                    reader = new StreamReader(new GZipStream(filereader, CompressionMode.Decompress));
                }
                else
                {
                    reader = new StreamReader(filename);
                }
                if (from != null || to != null)
                {
                    reader = new FromToReader(reader, from, to);
                }

                using (reader)
                {
                    SimpleCharStream    charStream  = new SimpleCharStream(reader);
                    GrShellTokenManager tokenSource = new GrShellTokenManager(charStream);
                    tokenSources.Push(tokenSource);

                    try
                    {
                        grShell.ReInit(tokenSource);

                        while (!Quitting && !Eof)
                        {
                            if (!grShell.ParseShellCommand())
                            {
                                impl.errOut.WriteLine("Shell command parsing failed in include of \"" + filename + "\" (at nesting level " + tokenSources.Count + ")");
                                return(false);
                            }
                        }
                        Eof = false;
                    }
                    finally
                    {
                        if (showIncludes)
                        {
                            impl.debugOut.WriteLine("Leaving " + filename);
                        }

                        tokenSources.Pop();
                        grShell.ReInit(tokenSources.Peek());
                    }
                }
            }
            catch (Exception e)
            {
                impl.errOut.WriteLine("Error during include of \"" + filename + "\": " + e.Message);
                return(false);
            }

            return(true);
        }
Exemple #27
0
        /** Reinitialise. */
        /*public void ReInit(java.io.InputStream stream) {
             ReInit(stream, null);
          }*/
                /** Reinitialise. */
                /*public void ReInit(java.io.InputStream stream, string encoding) {
            try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new SystemException(e); }
            token_source.ReInit(jj_input_stream);
            token = new Token();
            jj_ntk = -1;
            jjtree.reset();
            jj_gen = 0;
            for (int i = 0; i < 10; i++) jj_la1[i] = -1;
            for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
          }*/

        /// <summary>Constructor with TextReader</summary>
        public TsurgeonParser(TextReader stream)
        {
            jj_input_stream = new SimpleCharStream(stream, 1, 1);
            token_source = new TsurgeonParserTokenManager(jj_input_stream);
            token = new Token();
            jj_ntk = -1;
            jj_gen = 0;
            for (int i = 0; i < 10; i++) jj_la1[i] = -1;
            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls();
        }
public IDLParserTokenManager(SimpleCharStream stream, int lexState) : this(stream)
{
   SwitchTo(lexState);
}
        /// <summary>Constructor</summary>
        public TsurgeonParserTokenManager(SimpleCharStream stream)
        {

            if (SimpleCharStream.staticFlag)
                throw new Exception("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");

            InputStream = stream;
        }
public void ReInit(SimpleCharStream stream, int lexState)
{
   ReInit(stream);
   SwitchTo(lexState);
}
 /// <summary>Constructor</summary>
 public TsurgeonParserTokenManager(SimpleCharStream stream, int lexState)
 {
     ReInit(stream);
     SwitchTo(lexState);
 }
 /// <summary>Reinitialise parser.</summary>
 public void ReInit(SimpleCharStream stream, int lexState)
 {
     ReInit(stream);
     SwitchTo(lexState);
 }
Exemple #33
0
 private void IgnoreComment(SimpleCharStream charStream)
 {
     char curChar = charStream.ReadChar();
     if(curChar == '/')
     {
         do
         {
             curChar = charStream.ReadChar();
         }
         while(curChar != '\n' && curChar != '\r');
     }
     else if(curChar == '*')
     {
         bool foundStar = false;
         while(true)
         {
             curChar = charStream.ReadChar();
             if(foundStar && curChar == '/') break;
             foundStar = curChar == '*';
         }
     }
     // otherwise its just not a comment
 }