Compiler: Difference between revisions

From 太極
Jump to navigation Jump to search
Line 20: Line 20:
* Whitespace: if___else
* Whitespace: if___else


* Classify program substrings according to role
For the last code example, the tokens are:
* Communicate tokens to the parser
if, whitespace, (, i, == , j, \t, \n, else, z, =, 1, ;
 
<pre>
<pre>
                                 Token     
                                 Token     

Revision as of 12:33, 26 November 2014

Lexical Analysis

  if (i == j)
    z = 0;
  else
    z = 1;

is indeed below in computers

\tif (i == j)\n\t\tz = 0;\n\telse\n\t\tz = 1;

Token Class

Identifier, keywords, '(', ')', Numbers, ...

  • Token classes correspond to sets of strings.
  • Identifier: A1, Foo, B17
  • Integer: 0, 99
  • Keyword: 'else' or 'if' or 'begin' or ...
  • Whitespace: if___else

For the last code example, the tokens are: if, whitespace, (, i, == , j, \t, \n, else, z, =, 1, ;

                                 Token    
   string ---> Lexical Analysis -------> Parser

Parsing

Semantic Analysis

Optimization

Code Generation

Resource

  • coursera.org