// -*- c-basic-offset: 4 -*-
#include "options.hh"
#include "symbol_checking.hh"
#include "type_checking.hh"
#include "ast.hh"
#include <iostream>
int yyparse();
ast::DProg *dprog = 0;
int
main (int argc, char *argv[])
{
yyparse();
if (!dprog) return 2; // parse error!
// (too?) simple option parsing...
int opt = 1;
if (argc > 1 && (strcmp(argv[1],"-s") == 0) )
{
// strict symbol checking
options::strict_decl = 1;
opt++;
}
else if (argc > 1 && (strcmp(argv[1],"-su") == 0) )
{
// strict symbol checking
options::strict_decl = 1;
options::strict_upd_decl = 1;
opt++;
}
if (argc == 1 || (options::strict_decl && argc == 2))
{
type_checking::check(dprog); // successfull typecheck
return 0;
}
if (strcmp(argv[opt],"-u") == 0)
try {
type_checking::check(dprog);
assert(false);
} catch (type_checking::UndefinedSymbol *ex) {
// expected exception
delete ex;
}
else if (strcmp(argv[opt],"-r") == 0)
try {
type_checking::check(dprog);
assert(false);
} catch (symbol_checking::Redefinition *ex) {
// expected exception
delete ex;
}
else if (strcmp(argv[opt],"-t") == 0)
try {
type_checking::check(dprog);
assert(false);
} catch (type_checking::WrongType *ex) {
// expected exception
delete ex;
}
else if (strcmp(argv[opt],"-b") == 0)
try {
type_checking::check(dprog);
assert(false);
} catch (type_checking::BuiltinNotDefined *ex) {
// expected exception
delete ex;
}
else
{
std::cerr << "expected option [-s|-su] [-u|-r|-t|-b]\n";
exit(2);
}
}
syntax highlighted by Code2HTML, v. 0.9.1