Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            textBox3.Clear();
            textBox4.Clear();
            if (m_Tokens == null)
            {
                return;
            }
            Parser2 parser = new Parser2(null, "rest");
            LinkedList <Tokenizer.Token> _Tokens = new LinkedList <Tokenizer.Token>();

            _Tokens.AddLast(m_Tokens);
            parser.ParseTokens(_Tokens);
            LinkedList <Parser2.Context.Log> .Enumerator x = parser.GetLogs().GetEnumerator();
            while (x.MoveNext())
            {
                if (x.Current.m_Error > 0)
                {
                    textBox4.Text += x.Current.m_Text + " at " + x.Current.m_Cmd.AsText() + "\r\n";
                }
            }
            LinkedList <Parser2.CmdBase> .Enumerator Result = parser.GetCmds("").GetEnumerator();
            while (Result.MoveNext())
            {
                textBox3.Text += (Result.Current.AsText() + "\r\n");
            }
        }
Exemple #2
0
        // Constructor

        public SemanticAnalyzer(Parser2 in_parse)
        {
            parse = in_parse;

            //tables = new SymbolTable ();
            prog     = new StringBuilder();
            tableNum = 0;

            operators   = new Stack();
            operands    = new Stack();
            operandType = new Stack();

            semanticError = false;
            errors        = new ArrayList();

            negFlag = false;
        }
Exemple #3
0
    static void Main(string[] args)
    {
        int count = 100;

        Console.WriteLine("[usage]RichTextParser textfile count");
        Console.WriteLine();
        Console.WriteLine("Now run {0} parses with preset text ...", count);
        string text = ParserValue.c_TestText;

        if (args.Length > 0)
        {
            string file = args[0];
            if (File.Exists(file))
            {
                text = File.ReadAllText(file);
            }
            else
            {
                Console.WriteLine("Can't read file '{0}'", file);
                return;
            }
            if (args.Length > 1)
            {
                try {
                    count = int.Parse(args[1]);
                } catch {
                    Console.WriteLine("arg '{0}' error", args[1]);
                    return;
                }
            }
        }
        var       parser = new Parser2();
        Stopwatch w      = new Stopwatch();

        w.Start();
        for (int i = 0; i < count; ++i)
        {
            var result = parser.Parse(text);
        }
        double t = w.ElapsedTicks * 1000.0 / Stopwatch.Frequency;

        Console.WriteLine("elapsed {0}ms for {1} parses, {2}ms/parse", t, count, t / count);
    }
    public static IParser Create(string type)
    {
        IParser parser;

        switch (type)
        {
        case "1":
            parser = new Parser1();
            break;

        case "2":
            parser = new Parser2();
            break;

        default:
            throw new ArgumentOutOfRangeException("type");
        }

        return(parser);
    }
Exemple #5
0
        public static void Main(string[] args)
        {
            //try to grab the file out of args[0]

            try{
                string contents = File.ReadAllText(args[0]);
                string output   = Scanner.Dispatcher(contents);
                Scanner.PrintTokies();

                ArrayList outies = Scanner.GetTokenArray();
                Console.WriteLine(output);

                Parser2 parser = new Parser2(output, outies, args[0]);
                parser.Parse();
            } catch (IOException) {
                Console.WriteLine("Couldn't open file.");
            } catch (IndexOutOfRangeException) {
                Console.WriteLine("Expecting a file argument.");
            }
        }
Exemple #6
0
                public static long Evaluate(string formula)
                {
                    var p = new Parser2(formula);

                    return(p._ret);
                }
Exemple #7
0
 protected virtual void OnData(byte[] data)
 {
     this.OnPacket(Parser2.DecodePacket(data));
 }
Exemple #8
0
 protected virtual void OnData(string data)
 {
     this.OnPacket(Parser2.DecodePacket(data, false));
 }
        void RebuildObjList()
        {
            // add the basic types to Intelisense
            ObjDecl _A;

            for (int i = 0; i < BASIC_TYPES.Count; i++)
            {
                _A = new ObjDecl(BASIC_TYPES[i], ObjDecl.TClassType.tCTType, "", "", "", "", 0, 0);
                UpdateObjDecl(_A);
            }
            DateTime _start = DateTime.Now;
            //Log.getInstance().Add("collecting files ", Log.EnuSeverity.Info, "");
            Tokenizer _tokenizer = new Tokenizer();
            LinkedList <Tokenizer.Token> _Tokens = new LinkedList <Tokenizer.Token>();
            List <String> Dirs = new List <String>(); //stack of directories relative to _path
            int           k    = 0;

            try {
                String[] _SubProj = getSubProj();
                for (int i = 0; i < _SubProj.Length; i++)
                {
                    Dirs.Add(Path.Combine(m_ProjectDir, getSeqDir(_SubProj[i])));
                }

                while (k < Dirs.Count)
                {
                    FileInfo[] _files = new DirectoryInfo(Dirs[k]).GetFiles();
                    for (int i = 0; i < _files.Length; i++)
                    {
                        if (_files[i].Extension.Equals(".seq", StringComparison.OrdinalIgnoreCase))
                        {
                            _Tokens.AddLast(_tokenizer.TokenizeFile(_files[i].FullName));
                        }
                    }
                    DirectoryInfo[] _Dirs = new DirectoryInfo(Dirs[k]).GetDirectories();
                    for (int i = 0; i < _Dirs.Length; i++)
                    {
                        // If the file is a directory (or is in some way invalid) we'll skip it
                        Dirs.Insert(k + 1, _Dirs[i].FullName);
                    }
                    k++;
                }
                //Log.getInstance().Add("Tokenized all" , Log.EnuSeverity.Info, "");
                Parser2 _parser2 = new Parser2(this, m_ProjectDir);
                _parser2.ParseTokens(_Tokens);
                LinkedList <Parser2.Context.Log> .Enumerator _l = _parser2.GetLogs().GetEnumerator();
                while (_l.MoveNext())
                {
                    Log.getInstance().Add(_l.Current.m_Text, Log.EnuSeverity.Warn, _l.Current.m_Cmd.AsText());
                }
                //update database with parserresult
                LinkedList <Parser2.CmdBase> .Enumerator _Cmds;
                List <String> .Enumerator _Scopes = _parser2.GetScopes().GetEnumerator();
                while (_Scopes.MoveNext())
                {
                    //Log.getInstance().Add("write DB " + _Scopes.Current, Log.EnuSeverity.Info, "");
                    // if(!m_IsClassDef) {
                    { //each SEQ includes itself
                        this.UpdateObjList(new Obj(_Scopes.Current, "", _Scopes.Current, "", 0, 0));
                    }
                    _Cmds = _parser2.GetCmds(_Scopes.Current).GetEnumerator();
                    while (_Cmds.MoveNext())
                    {
                        PublishCmdToDB(_Scopes.Current, _Cmds.Current);
                    }
                }
                Log.getInstance().Add("Parsing done ", Log.EnuSeverity.Info, "");
            } catch (Exception ex) {
                Log.getInstance().Add(ex.Message, Log.EnuSeverity.Error, "");
            }
            finally {
            }
        }