예제 #1
0
        public GlobalDataItem_v2?ParseGlobalDeclaration(string txtGlobal)
        {
            try
            {
                var lexer   = new CLexer(new StringReader(txtGlobal + ";"), CLexer.GccKeywords); //$REVIEW: what's the right thing?
                var symbols = program.CreateSymbolTable();
                var oldVars = symbols.Variables.Count;
                var cstate  = new ParserState(symbols);
                var cParser = new CParser(cstate, lexer);
                var decl    = cParser.Parse_ExternalDecl();
                if (decl == null)
                {
                    return(null);
                }

                //$HACK: Relying on a side effect here to
                // get both the global type. Ew.
                symbols.AddDeclaration(decl);
                if (symbols.Variables.Count == oldVars)
                {
                    return(null);
                }
                return(symbols.Variables.Last());
            }
            catch (Exception ex)
            {
                Debug.Print("{0}\r\n{1}", ex.Message, ex.StackTrace);
                return(null);
            }
        }
예제 #2
0
파일: CParser.cs 프로젝트: MavenRain/reko
 public CParser(ParserState parserState, CLexer lexer)
 {
     this.ParserState = parserState;
     this.lexer = new LookAheadLexer(
         new CDirectiveLexer(parserState, lexer));
     this.grammar = new CGrammar();
 }
예제 #3
0
 public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib)
 {
     var rdr = new StreamReader(new MemoryStream(bytes));
     var lexer = new CLexer(rdr);
     var state = new ParserState();
     var parser = new CParser(state, lexer);
     var symbolTable = new SymbolTable(platform);
     var declarations = parser.Parse();
     var tldser = new TypeLibraryDeserializer(platform, true, dstLib);
     foreach (var decl in declarations)
     {
         ProcessDeclaration(decl, platform, tldser, symbolTable);
     }
     return dstLib;
 }
예제 #4
0
 public ProcedureSignature BuildSignature(string str, Frame frame)
 {
     try {
         var lexer = new CLexer(new StringReader(str + ";"));
         var cstate = new ParserState();
         var cParser = new CParser(cstate, lexer);
         var decl = cParser.Parse_ExternalDecl();
         var sSig = symbolTable.AddDeclaration(decl)
             .OfType<SerializedSignature>()
             .FirstOrDefault();
         if (sSig == null)
             return null;
         var ser = program.Platform.CreateProcedureSerializer();
         return ser.Deserialize(sSig, frame);
     }
     catch (Exception ex)
     {
         Debug.Print("{0}\r\n{1}", ex.Message, ex.StackTrace);
         return null;
     }
 }
예제 #5
0
        public ProcedureBase_v1?ParseFunctionDeclaration(string?fnDecl)
        {
            if (string.IsNullOrEmpty(fnDecl))
            {
                return(null);
            }
            try {
                var lexer    = new CLexer(new StringReader(fnDecl + ";"), CLexer.GccKeywords);
                var symbols  = program.CreateSymbolTable();
                var oldProcs = symbols.Procedures.Count;
                var cstate   = new ParserState(symbols);
                var cParser  = new CParser(cstate, lexer);
                var decl     = cParser.Parse_ExternalDecl();
                if (decl == null)
                {
                    return(null);
                }

                //$HACK: Relying on a side effect here to
                // get both the procedure name and the signature. Ew.
                symbols.AddDeclaration(decl);
                if (symbols.Procedures.Count == oldProcs)
                {
                    return(null);
                }
                return(symbols.Procedures.Last());
            }
            catch (Exception ex)
            {
                //$TODO: if user has supplied a signature that can't parse,
                // we must notify them in the diagnostics window with a
                // WARNING.
                Debug.Print("{0}\r\n{1}", ex.Message, ex.StackTrace);
                return(null);
            }
        }
예제 #6
0
 public CDirectiveLexer(ParserState state, CLexer lexer)
 {
     this.state     = state;
     this.lexer     = lexer;
     this.tokenPrev = new CToken(CTokenType.EOF);
 }
예제 #7
0
 private void Lex(string str)
 {
     lexer = new CLexer(new StringReader(str));
     parser = new CParser(parserState, lexer);
 }
예제 #8
0
 public CDirectiveLexer(ParserState state, CLexer lexer)
 {
     this.state = state;
     this.lexer = lexer;
     this.tokenPrev = new CToken(    CTokenType.EOF);
 }
예제 #9
0
        public GlobalDataItem_v2 ParseGlobalDeclaration(string txtGlobal)
        {
            try
            {
                var lexer = new CLexer(new StringReader(txtGlobal + ";"));
                var symbols = program.CreateSymbolTable();
                var oldVars = symbols.Variables.Count;
                var cstate = new ParserState(symbols.NamedTypes.Keys);
                var cParser = new CParser(cstate, lexer);
                var decl = cParser.Parse_ExternalDecl();
                if (decl == null)
                    return null;

                //$HACK: Relying on a side effect here to
                // get both the global type. Ew.
                symbols.AddDeclaration(decl);
                if (symbols.Variables.Count == oldVars)
                    return null;
                return symbols.Variables.Last();
            }
            catch (Exception ex)
            {
                Debug.Print("{0}\r\n{1}", ex.Message, ex.StackTrace);
                return null;
            }
        }
예제 #10
0
        public ProcedureBase_v1 ParseFunctionDeclaration(string fnDecl)
        {
            try {
                var lexer = new CLexer(new StringReader(fnDecl + ";"));
                var symbols = program.CreateSymbolTable();
                var oldProcs = symbols.Procedures.Count;
                var cstate = new ParserState(symbols.NamedTypes.Keys);
                var cParser = new CParser(cstate, lexer);
                var decl = cParser.Parse_ExternalDecl();
                if (decl == null)
                    return null;

                //$HACK: Relying on a side effect here to
                // get both the procedure name and the signature. Ew.
                symbols.AddDeclaration(decl);
                if (symbols.Procedures.Count == oldProcs)
                    return null;
                return symbols.Procedures.Last();
            }
            catch (Exception ex)
            {
                //$TODO: if user has supplied a signature that can't parse,
                // we must notify them in the diagnostics window with a 
                // WARNING.
                Debug.Print("{0}\r\n{1}", ex.Message, ex.StackTrace);
                return null;
            }
        }
예제 #11
0
파일: CLexerTests.cs 프로젝트: relaxar/reko
 private void Lex(string str)
 {
     this.lex = new CLexer(new StringReader(str));
 }
예제 #12
0
        private void CreateLexer(string text)
        {
            parserState = new ParserState();

            lexer = new CLexer(new StringReader(text));
        }