1 / 10

Winter 2012-2013 Compiler Principles Scanning Assignment

Winter 2012-2013 Compiler Principles Scanning Assignment. Mayer Goldberg and Roman Manevich Ben-Gurion University. Overview. Goal: implement scanner using Jflex for Table Processing Language (TPL) Use supplied skeleton Java sources

milla
Download Presentation

Winter 2012-2013 Compiler Principles Scanning Assignment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Winter 2012-2013Compiler PrinciplesScanning Assignment Mayer Goldberg and Roman Manevich Ben-Gurion University

  2. Overview • Goal: implement scanner using Jflex forTable Processing Language (TPL) • Use supplied skeleton Java sources • Optionally (recommended) use build.xml to automate tasks with Ant • Complete TPL.lex to handle all token kinds • Test on example programs • Write your own test suite of TPL programs • Correct and erroneous • Don’t forget to handle comments, quoted strings + escape sequences, errors

  3. Example program // A constraint on the number of columns in the input table.assert COLS == 3 : "Number of columns should be:t3“COLS2 = COLS * 2 // This defines a constant COLS2// This is a function definition. x and y a argument variables.def weirdAverage(x, y) = { x * y / (x + y)}// This is the definition of the first column.def TABLE[i==1][j] = {TABLE[1][j] * -18.7}// This column definition simply copies the values from the first input column.def TABLE[i==2]ji] = {TABLE[1][j]}/* This is a multi-line comment.def TABLE[i==2][j] = {TABLE[1][j] * -1}*/def TABLE[i==3][j] = {if (TABLE[2][j] + TABLE[3][j] > 0) {weirdAverage(TABLE[2][j], TABLE[3][j]) }else { 0 }}def TABLE[i==4][j] = {if (j < ROWS) { 0 }else {sum = 0for (k = 1..ROWS)sum += TABLE[1][k]average /= ROWS }}

  4. Assertions // A constraint on the number of columns in the input table.assert COLS == 3 : "Number of columns should be:t3“

  5. Constants COLS2 = COLS * 2 // This defines a constant COLS2

  6. Functions // This is a function definition. x and y a argument variables.def weirdAverage(x, y) = { x * y / (x + y)}

  7. Columns // This is the definition of the first column.def TABLE[i==1][j] = {TABLE[1][j] * -18.7}// This column definition simply copies the values from the first input column.def TABLE[i==2]ji] = {TABLE[1][j]}/* This is a multi-line comment.def TABLE[i==2][j] = {TABLE[1][j] * -1}*/

  8. Columns def TABLE[i==3][j] = {if (TABLE[2][j] + TABLE[3][j] > 0) {weirdAverage(TABLE[2][j], TABLE[3][j]) }else { 0 }}def TABLE[i==4][j] = {if (j < ROWS) { 0 }else {sum = 0for (k = 1..ROWS)sum += TABLE[1][k]average /= ROWS }}

  9. Grammar - tokens idIdentiertoken num Number token quote Quoted string token

  10. Grammar - productions

More Related