CSCI 330 Course project

Change in due date: the project is now due by noon (PDT) on Tuesday April 14th.
Change in grading: only 60 marks-worth of features need to be implemented, not the 75 originally specified
Help sessions: replaced by the online Q&A page/sessions
Note: there are likely to be gaps/ambiguities/conflicts in the initial language specification given below. If you find such an issue, or need clarification on the language specifications, please contact the instructor as soon as possible.
Clarifications/corrections will be posted here as the term progresses.
  1. Functions can only be declared in the global scope.
  2. Parameters in function calls/declarations must be separated by colons, e.g.
    foo ( x : y )
  3. The two indices in the substring operation must be separated by colons, e.g.
    str [ x : y ]
  4. Assignment uses just "=", not ":=" (it was shown both ways in earlier postings).
  5. Assume the power operator (^) has higher precedence than multiplication, division, and modulo

If you need some ideas for getting started, some additional code and discussion is available in the starter code page.

The course project this semester is to create, using lex and yacc, a syntax checker for a small programming language, fooish. Details are given below.

The project is worth a total of 15% of your grade, and is due at 5p.m. on Thursday April 9th.

Submissions up to 24 hours late will be penalized 10%, submissions 24-48 hours late will be penalized 25%, submissions 48-72 hours late will be penalized 40%. No submissions will be accepted more than 72 hours late.

The project will be distributed and submitted using our standard git approach, i.e. obtained using

The initial repository contents include:

Notes on code quality

While there are not official code standards for the course, this is an upper level course and as such it is expected that all code submissions will be of high quality - i.e. the code compiles without errors or warnings, does not crash when run, uses sensible and informative prompts and error messages, is well laid out, uses sensible identifiers, has reasonable commenting for complex steps, etc. Marks will be deducted for poor quality code even if the functional behaviour is correct.

Supporting reference material:

Project requirements and marking scheme

The objective is to create, using lex and yacc, an executable named fooChecker that can be applied to fooish source code to determine if the source code is a valid fooish program. (A description of the fooish language is given further below.)

To do so, you will need to create files foo.lex, foo.yacc, and a makefile that will properly build the fooChecker executable.

The fooChecker should provide a clear message if the code is valid, and appropriate error messages if the code is not valid, e.g.
./fooChecker <

Checking complete, code is valid.

Note: as you will find, generating "appropriate error messages" is pretty tricky - you'll soon see why some of the error messages generated by compilers are so cryptic. Generating any error message (when there is an error of course) is a good start.

Some examples of lex files, yacc files, and makefiles are provided for various simple languages through the course lex/yacc examples page.

The marking will be handled as follows:

Fooish language specifications

Fooish is a dynamically-typed, lexically-scoped scripting language in which functions and variables must be declared before they are used.

It requires tokens to be whitespace delimited, but any amount/type of whitespace is acceptable (e.g. the whitespace between two tokens might be a single space, a tab, a newline, multiple spaces, combinations, etc).

Identifiers (function names, variable names, parameter names) consist of alphabetic characters or underscores, are case-sensitive, and cannot match any of the language keywords (e.g. VAR while FUNC return etc).

Assignment statements, variable declarations, function calls, and return statements are terminated with a semi-colon.

The data types supported are (fixed-point) real numbers, integers, strings, and booleans - each of which is discussed below.

The language uses bash-style comments, i.e. everything from a # to the end of the line.

Features and syntax examples:

(Note that the specific choice of whitespace used in the examples below is simply for the sake of readability.)

Sample script

# sumVals ( N )
# -------------
# gets the user to enter N numeric values,
#    computes and returns the sum of them
FUNC sumVals ( N )
   VAR sum ;
   sum = 0.0 ;
   VAR i ;
   i = 0 ;
   while ( i < N ) {
      print ( "Enter a number" ) ;
      VAR num ;
      num = readr ( ) ;
      sum = sum + num ;
   return sum ;

# try calling our function and displaying the results

VAR numvals ;  # used to decide how many numbers to read
numvals = 10 ;

VAR result ;   # used to store the final sum

   # let's try the function call
result = sumVals ( numvals ) ;

print ( "The sum of your " ) ;
print ( numvals ) ;
print ( " values was " ) ;
print ( result ) ;