Using the Rotor C# Compiler for Teaching Elizabeth White Computer Science Department George Mason University Fairfax, VA SIGCSE '05 This work is supported by SSCLI (Rotor) RFP.

Download Report

Transcript Using the Rotor C# Compiler for Teaching Elizabeth White Computer Science Department George Mason University Fairfax, VA SIGCSE '05 This work is supported by SSCLI (Rotor) RFP.

Using the Rotor C# Compiler for
Teaching
Elizabeth White
Computer Science Department
George Mason University
Fairfax, VA
SIGCSE
'05
This work is supported by SSCLI (Rotor) RFP
2
Graduate Compilers
Typical courses in graduate compilers
include:
• Theory
– Lexical analysis, Syntax analysis (LL/LR),
Semantic analysis (type-checking,
intermediate code, …) , Optimization
• Development of a ‘compiler’ for a small
language
– Application of theory
– Tools (e.g. Flex, YACC)
SIGCSE '05
Graduate Compilers
Typical courses in graduate compilers do not
include access to ‘real’ compiler
Why?
• Real compilers are extremely large and complex
– SSCLI C# compiler
• 200,000+ lines of C++
• 138 modules
SIGCSE '05
Can we integrate ‘real’ compilers
into a class like this?
Idea:
• Show relevant details illustrating basic
theory inside the compiler tied to input
code
• Hide everything else
 Hide and Show
SIGCSE '05
Hide and Show
• Use a debugging tool on the compiler.
• Combine:
– Pre-chosen input program
– Pre-chosen breakpoints inside source code of the
appropriate compiler component
• Step through the processing of input program
and watch how the input program triggers
changes.
A carefully planned exercise of this type should
provide insights that would be difficult to provide
to the students using other techniques.
SIGCSE '05
_parseNumber: fReal = TRUE;
while (*p >= '0' && *p <= '9‘) p++;
// Number + dot + non-digit -- these are separate tokens, so don't
absorb the
// dot token into the number.
p = pszHold;
pFT->iToken = TID_NUMBER;
break; }
}
if (*p == 'E' || *p == 'e‘)
{
fReal = TRUE;
// skip exponent
p++;
if (*p == '+' || *p == '-‘) p++;
while (*p >= '0' && *p <= '9') p++;
}
…
pFT->iToken = TID_NUMBER;
break;
}
Hide and Show
SSCLI (Rotor) C# compiler
Scanner
Parser
Semantic
Analysis
Code
Target
Generator language
Optimizer
Symbol
Table
C# input
file
Concept
Demonstration
& Exploration
Instructions
(debugger commands,
breakpoints,
watch variables)
VisualStudio .net
SIGCSE '05
Hide & Show Demos
Platform:
• Rotor (SSCLI) C# compiler
(http://msdn.microsoft.com/net/sscli)
• Visual Studio .net (MSDNAA)
Two demos being used:
• Lexical Analysis –
– Token identification
• Parsing –
– LL (recursive descent)
SIGCSE '05
Demo: Lexical Analysis
Illustration: To watch the C# lexer work
• Set two variables to watch:
– Remaining input
– ‘Current’ token found
• Set six breakpoints in the lexer code (~1K lines
in module)
• Trace through scanning of C# input
This lexer is hand-coded, providing the students
with a view of this approach that they don’t
typically get.
SIGCSE '05
How should this approach be
used?
• Classroom
– Would need strong visualization tools to be
effective
• Directed exercises for individuals
– More promising
– Assignment based – students have a
worksheet they must complete
SIGCSE '05
Current Usage
• Basic concept demos shown in class and
then given as assignments
– Lexical Analysis
– Parsing
• Students can install and run on own
resources or go to lab setting with TA
• My goal: work on integration of this idea
with the existing course structure
SIGCSE '05
Fall 2004/Spring 2005 – The
Reviews
• Love/Hate
– Love – access to a real system where they
could see ‘all that theory’ in action
– Hate – setup mechanics – some went to lab
after frustration with setup
• Assuming we can streamline the setup,
there may be value added.
SIGCSE '05
What’s next?
• How effective is this approach? Is there
value added?
• What additional tools (such as
visualization) would make this approach
more effective?
• Expand to see how hide and show can be
used in other courses/areas.
– Distributed systems
– Follow-on class to compilers
SIGCSE '05
Questions?
Contact info:
[email protected]
http://cs.gmu.edu/~white/HideAndShow
SIGCSE '05