Diagnostics

SLangCC reports lexer, syntax, and semantic errors to standard error. Diagnostics include the input filename and source line when available.

Lexer error in hello.sl at line 2: illegal character '@'
Syntax error in hello.sl at line 3: Standalone variable or array access.
Semantic error in hello.sl at line 4: Undeclared identifier: 'total'.

The current diagnostic format does not include columns or a source-code excerpt.

Lexer errors

The lexer reports characters that do not begin any valid token. Common causes include:

  • malformed or unterminated string/character literals;
  • a non-ASCII or otherwise unsupported source character;
  • a single & or | instead of && or ||.

Syntax errors

Parser errors cover invalid structure, including:

  • using // instead of # for a comment;
  • a scalar declaration without an initializer;
  • missing semicolons, parentheses, braces, commas, or operands;
  • a control-flow body without braces;
  • a forward function declaration;
  • an empty statement (;);
  • an invalid increment/decrement target;
  • more than one argument to exit;
  • a standalone variable, array access, unary, or binary expression.

Semantic errors

Semantic checks cover declarations, names, types, and call contexts:

  • statements or variables at file scope;
  • a non-void main or an explicit call to main;
  • duplicate variables, parameters, or functions;
  • undeclared identifiers, arrays, or functions;
  • zero, negative, undefined, or non-integer array sizes;
  • initializer, assignment, argument, or return type mismatches;
  • invalid explicit casts;
  • incorrect function argument counts;
  • using a non-void call as a statement or a void call as an expression;
  • returning a value from void or omitting one from a non-void return statement;
  • calling print() without arguments.

Reading a failure

Fix the earliest reported error first. Later diagnostics can be consequences of an earlier malformed declaration or expression. SLangCC exits nonzero and stops before native code generation whenever the lexer, parser, or semantic analyzer records an error.