make ./lab4x < valid/basic.yar # tries parsing the basic.yar code exampleThe lab4x executable processes the specified file content, and displays (limited) error messages if it detects any syntax errors, and at the end it displays a final "Parsing complete." The error messages, if any, are typically accompanied by a row and column number indicating where in the source file the parser recognized it was in an error state, and an indication of what statement type it last entered and where (to the best of its knowledge).
yarrgh token types, comments, whitespace, file extensions
By convention, yarrgh files generally use the .yar extension.
Comments begin with a # and continue to the end of the line (newline: not Windows
compatible), and must be stripped out by the tokenizer
Extra whitespace between tokens is ignored.
The supported token types are:
yarrgh grammar rules For lab4, a yarrgh program has the following form:
Declaration, type, and scope rules Note that we won't be carrying out type and declaration checking in lab4, but they will be a part of lab5.
|
# program 1: your finished lab4x should accept this, assuming Dave didn't screw up the example
program
open
def x integer ;
def foo real;
set x 125;
read foo;
write 5 * (x + foo);
def sum real;
set sum 0.0;
repeat open
def y real;
read y;
if (y >= x) open
write y;
close
else open
write x;
close
set sum (sum + x + y);
close until (x < foo);
close
|
block: OPENKEY
{ updateState("entered a block", row, col); }
statements
CLOSEKEY
{ updateState("completed block", row, col); }
;
In your main routine, in the "if (errors)" block,
print out the last recorded description, row, and column,
thus letting the programmer know the last point successfully reached.