CS453 Intro and PA1 1CS453 Lecture Introduction and Lexing 2Plan for Today Motivation– Why study compilers? Programming Assignment Overview– The compiler we will be building Lexing/Scanning– Representing tokens with regular expressions– Using DFAs to recognize a string of tokensCS453 Lecture Introduction and Lexing 3CS453 Lecture Introduction and Lexing 4Structure of the MiniJava Compiler“sentences”Synthesiscanonicalizationinstruction selectionAssemIRTIR code generationIRTAnalysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTAST and symbol tablecode generationMIPSPA2PA3 and PA4PA5 and PA6PA7PA7PA8PA8CS453 Lecture Introduction and Lexing 5Specifying Tokens with SableCC Theory meets practice:– Regular expressions, formallanguages, grammars, parsing… SableCC example input file: Package minijava; Helpers all = [0..0xFFFF]; cr = 13; digit = ['0'..'9']; letter = ['a'..'z'] | ['A'..'Z']; underscore = ’_’; not_star = [all - '*']; not_star_slash = [not_star - '/']; c_comment = '/*' not_star* ('*'(not_star_slash not_star*)?)* '*/'; Tokens plus = '+'; if = 'if'; id = letter (letter | digit | underscore)*; blank = (' ' | eol | tab)+; comment = c_comment | line_comment; Ignored Tokens blank, comment;CS453 Intro and PA1 2CS453 Lecture Introduction and Lexing 6Example DFA for Recognizing a String of
View Full Document