01-decaf-spec - Massachusetts Institute of Technology...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout — Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler for a language called Decaf. Decaf is a simple imperative language similar to C or Pascal. Lexical Considerations All Decaf keywords are lowercase. Keywords and identifiers are case-sensitive. For example, if is a keyword, but IF is a variable name; foo and Foo are two different names referring to two distinct variables. The reserved words are: boolean break callout class continue else false for if int return true void Note that Program (see below) is not a keyword, but an identifier with a special meaning in certain circumstances. Comments are started by // and are terminated by the end of the line. White space may appear between any lexical tokens. White space is defined as one or more spaces, tabs, page and line-breaking characters, and comments. Keywords and identifiers must be separated by white space, or a token that is neither a keyword nor an identifier. For example, thisfortrue is a single identifier, not three distinct keywords. If a sequence begins with an alphabetic character or an underscore, then it, and the longest sequence of characters following it forms a token. String literals are composed of ( char ) s enclosed in double quotes. A character literal consists of a ( char ) enclosed in single quotes. Numbers in Decaf are 32 bit signed. That is, decimal values between -2147483648 and 2147483647. If a sequence begins with 0x , then these first two characters and the longest sequence of characters drawn from [0-9a-fA-F] form a hexadecimal integer literal. If a sequence begins with a decimal digit (but not 0x ), then the longest prefix of decimal digits forms a decimal integer literal. Note that range checking is performed later. A long sequence of digits (e.g. 123456789123456789) is still scanned as a single token. A ( char ) is any printable ASCII character (ASCII values between decimal value 32 and 126, or octal 40 and 176) other than quote ( " ), single quote ( ), or backslash ( \ ), plus the 2-character sequences “ \" ” to denote quote, “ \’ ” to denote single quote, “ \\ ” to denote backslash, “ \t ” to denote a literal tab, or “ \n ” to denote newline. 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Reference Grammar Meta-notation: ( foo ) means foo is a nonterminal. foo (in bold font) means that foo is a terminal i.e., a token or a part of a token. bracketleftBig x bracketrightBig means zero or one occurrence of x , i.e., x is optional; note that brackets in quotes [ ] are terminals. x means zero or more occurrences of x . x + , a comma-separated list of one or more x’s. braceleftBig bracerightBig large braces are used for grouping; note that braces in quotes { } are terminals. | separates alternatives.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern