100 likes | 212 Views
This assignment aims to develop a scanner for the Table Processing Language (TPL) using JFlex at Ben-Gurion University. Students will utilize provided Java skeleton code and are encouraged to automate build tasks with Ant. You will need to complete the TPL lexer to recognize all token types, handle comments, quoted strings, escape sequences, and both correct and erroneous code. Testing will involve creating your own suite of TPL programs, ensuring the scanner is robust and functional.
E N D
Winter 2012-2013Compiler PrinciplesScanning Assignment Mayer Goldberg and Roman Manevich Ben-Gurion University
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
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 }}
Assertions // A constraint on the number of columns in the input table.assert COLS == 3 : "Number of columns should be:t3“
Constants COLS2 = COLS * 2 // This defines a constant COLS2
Functions // This is a function definition. x and y a argument variables.def weirdAverage(x, y) = { x * y / (x + y)}
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}*/
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 }}
Grammar - tokens idIdentiertoken num Number token quote Quoted string token