> Lines of code; easy. just count non-empty trimmed lines; separate comment lines from actual lines with executable instructions.
Cyclomatic complexity; that's probably a job for a parse tree listener. not exactly a walk in the park, I'm not sure how I'd calculate this metric, but it's certainly feasible.
Maintainability index; even harder, requires the above two metrics, and some "Halstead Volume" figure.
Nesting; report how deeply nested the code is.