Albrecht W Hanspeter Mssenbck Markus Lberbauer Johannes Kepler
Albrecht Wöß Hanspeter Mössenböck Markus Löberbauer Johannes Kepler University Linz, Austria System. Soft. Ware Group Compiler Generation Tools for C# April 23, 2003 Compiler Generation Tools for C#
What's Coco/R? What's the Project? • Coco/R: – is an easy-to-use compiler generator – Input: attributed, context-free EBNF grammar – Output: scanner & recursive descent parser • "Compiler Generation – Extension of Coco/R • • Tools" Project: to use Coco/R for non-LL(1) grammars to use semantic information to resolve LL(1) conflicts – ATG template for C# • • April 23, 2003 provides complete parsing facilities for C# programs add attributes and semantic actions for customized applications Compiler Generation Tools for C# 2
Architecture of Coco/R April 23, 2003 Compiler Generation Tools for C# 3
Coco/R 2. 0 b - What's new? • LL(1) conflict resolution – new keyword: IF ( boolean expression ) – peek functionality in Scanner • user-defined names for tokens – new keyword: TOKENNAMES • user-defined namespace for – new keyword: NAMESPACE April 23, 2003 generated types Compiler Generation Tools for C# 4
NAMESPACE CSharp. atg using System. Collections; NAMESPACE at. jku. ssw. Coco COMPILER CS. . . Scanner. cs Parser. cs using System. Collection; namespace at. jku. ssw. Coco { public class Token {. . . } public class Buffer {. . . } public class Scanner {. . . } public class Errors {. . . } } using System. Collections; namespace at. jku. ssw. Coco { public class Tokens {. . . } public class Parser {. . . } } April 23, 2003 Compiler Generation Tools for C# 5
LL(1) Conflicts • LL(1) conflicts: – explicit alternatives: – options: – iterations: e. g. A = a b | a c. A = [ a ] a b. A = { a } a b. • Conflict resolution: – factorization: e. g. A = ab | ac. A = a ( b | c ). – transform left recursion into iteration: e. g. A = Ab | c. A = c { b }. April 23, 2003 Compiler Generation Tools for C# 6
LL(1) Conflicts (cont. ) • Conflict resolution (cont. ): but sometimes transformations – do not help Ident. List = ident { ", " ident } [ ", " ]. – are undesireable Using. Clause = "using" [ ident "=" ] Qualident "; ". Qualident = ident { ". " ident }. Using. Clause = "using" ident ( { ". " ident } | "=" Qualident ) "; ". April 23, 2003 Compiler Generation Tools for C# 7
Conflict Resolvers CSharp. atg COMPILER CS. . . static bool Not. Final. Comma () { Scanner. Start. Peek(); return la. kind == Tokens. Comma && Scanner. Peek(). kind == Tokens. Ident; } in Parser. cs. . . static void Ident. List () { PRODUCTIONS Expect(ident); while (Not. Final. Comma()) {. . . Expect(", "); Ident. List Expect(ident); = ident { IF (Not. Final. Comma()) } ", " ident if (la. kind == ", ") Get(); } [ ", " ]. }. . . April 23, 2003 Compiler Generation Tools for C# 8
Peek functionality CSharp. atg COMPILER CS. . . static bool Not. Final. Comma () { Scanner. Start. Peek(); () return la. kind == Tokens. Comma && Scanner. Peek(). kind == Tokens. Ident; Scanner. Peek() }. . . Scanner Interface: public static Token Scan (). . . returns next token, moves current token & peek token ahead public static Token Peek (). . . returns next peek token, moves peek token ahead (not current token) public static Token Start. Peek (). . . makes sure peeking starts from current token April 23, 2003 Compiler Generation Tools for C# 9
TOKENNAMES CSharp. atg COMPILER CS. . . static bool Not. Final. Comma () { Scanner. Start. Peek(); return la. kind == Tokens. Comma && Scanner. Peek(). kind == Tokens. Ident; Ident } in Parser. cs. . . public class Tokens () { TOKENNAMES public const int Comma = 2; ", " = Comma public const int Ident = 1; ident = Ident public const int LPar = 3; public const int RPar = 4; "(" = LPar. . . ")" = RPar }. . . April 23, 2003 Compiler Generation Tools for C# 10
Applications (on-going projects) • White-Box-Testing Tool • Code. DOM-Parser (System. Code. Dom. Compiler. ICode. Parser) • C#-Source-Code-Analyzer – gathers static information about a program • • Lines of Code (with / without comments) Number of instructions, selections, loops, method calls, . . . Complexity measures: Mc. Cabe, Rechenberg, . . . • Online-C#-Syntaxhighlighter (produces HTML) – at http: //dotnet. jku. at/applications/cs 2 html – major update coming soon! April 23, 2003 Compiler Generation Tools for C# 11
White-Box-Testing Tool • supports testing by measuring and visualizing path coverage of test runs • client/server architecture via HTTP – client: WBT tool – server: instrumented program under test C# source code (with Coco/R generated parser) to log covered paths • visualizes the paths in • instruments – a control flow graph – the source code April 23, 2003 Compiler Generation Tools for C# 12
WBT Tool (highlighted path in CFG) April 23, 2003 Compiler Generation Tools for C# 13
WBT Tool (highlighted path in code) April 23, 2003 Compiler Generation Tools for C# 14
Plans for WBT Tool • use Code. DOM-Tree – as model for visualization – to do instrumentation there • improve path visualization • redesign GUI • single process (instead of client/server architecture) to – increase speed – simplify usage April 23, 2003 Compiler Generation Tools for C# 15
Links • Main Project Site: http: //dotnet. jku. at/Projects/Rotor • Rotor Community Site Project "cocotools": http: //cocotools. sscli. net • Questions, April 23, 2003 comments, . . . ? Thanks to Werner Vogels & Co. Compiler Generation Tools for C# 16
Screenshot: cocotools. sscli. net April 23, 2003 Compiler Generation Tools for C# 17
- Slides: 17