The only information the compiler provides is about lexical and syntax errors. If there are no errors, the compiler shuts up, and exits successfully:
/* An array type and an array variable. */
let
type arrtype = array of int
var arr1 : arrtype := arrtype [10] of 0
in
arr1[2]
end
File 8: test01.tig
$ tc test01.tig Example 9: tc test01.tig
If there are lexical errors, the exit status is 2, and a an error message is output on the standard error output. Note that its format is standard and mandatory: file, (precise) location, and then the message (voir Errors).
1
/* This comments starts at /* 2.2 */
File 10: unterminated-comment.tig
$ tc unterminated-comment.tig error-->unterminated-comment.tig:2.1-3.0: unexpected end of file in a comment =>2 Example 11: tc unterminated-comment.tig
If there are syntax errors, the exit status is set to 3:
let var a : nil := ()
in
1
end
File 12: type-nil.tig
$ tc type-nil.tig error-->type-nil.tig:1.12-14: syntax error, unexpected "nil", expecting "identifier" error-->Parsing Failed =>3 Example 13: tc type-nil.tig
If there are errors which are non lexical, nor syntactic (Windows will not pass by me):
$ tc C:/TIGER/SAMPLE.TIG error-->tc: cannot open `C:/TIGER/SAMPLE.TIG': No such file or directory =>1 Example 14: tc C:/TIGER/SAMPLE.TIG
The option --parse-trace, which relies on Bison's %debug
directive, and the use of YYPRINT
, must work properly:
a + "a"
File 15: a+a.tig
$ tc --parse-trace --parse a+a.tig error-->Starting parse error-->Entering state 0 error-->Reading a token: Next token is 259 ("identifier" a+a.tig:1.0: a) error-->Shifting token 259 ("identifier"), Entering state 2 error-->Reading a token: Next token is 271 ("+" a+a.tig:1.2) error-->Reducing via rule 76 (line 382), "identifier" -> varid error-->state stack now 0 error-->Entering state 17 error-->Reducing via rule 38 (line 259), varid -> lvalue error-->state stack now 0 error-->Entering state 14 error-->Next token is 271 ("+" a+a.tig:1.2) error-->Reducing via rule 37 (line 255), lvalue -> exp error-->state stack now 0 error-->Entering state 13 error-->Next token is 271 ("+" a+a.tig:1.2) error-->Shifting token 271 ("+"), Entering state 43 error-->Reading a token: Next token is 258 ("string" a+a.tig:1.4-6: a) error-->Shifting token 258 ("string"), Entering state 1 error-->Reducing via rule 19 (line 213), "string" -> exp error-->state stack now 43 13 0 error-->Entering state 81 error-->Reading a token: Now at end of input. error-->Reducing via rule 31 (line 244), exp "+" exp -> exp error-->state stack now 0 error-->Entering state 13 error-->Now at end of input. error-->Reducing via rule 1 (line 163), exp -> program error-->state stack now 0 error-->Entering state 12 error-->Now at end of input. Example 16: tc --parse-trace --parse a+a.tig
Note that (i), --parse is needed, (ii), it cannot see that the variable is not declared nor that there is a type checking error, since type checking... is not implemented, and (iii), the output might be slightly different, depending upon the version of Bison you use. But what matters is that one can see the items: "identifier" a, "string" a.