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); } }
public CParser(ParserState parserState, CLexer lexer) { this.ParserState = parserState; this.lexer = new LookAheadLexer( new CDirectiveLexer(parserState, lexer)); this.grammar = new CGrammar(); }
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; }
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; } }
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); } }
public CDirectiveLexer(ParserState state, CLexer lexer) { this.state = state; this.lexer = lexer; this.tokenPrev = new CToken(CTokenType.EOF); }
private void Lex(string str) { lexer = new CLexer(new StringReader(str)); parser = new CParser(parserState, lexer); }
public CDirectiveLexer(ParserState state, CLexer lexer) { this.state = state; this.lexer = lexer; this.tokenPrev = new CToken( CTokenType.EOF); }
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; } }
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; } }
private void Lex(string str) { this.lex = new CLexer(new StringReader(str)); }
private void CreateLexer(string text) { parserState = new ParserState(); lexer = new CLexer(new StringReader(text)); }