Interpretting - April 2013 Supposing I had a language design, and a parser which created a basic abstract syntax graph. What else is needed before I can have an interpreter which can run programs. Assume a simple source-only interpreter - no bytecode format. I need: - symbol tables - lots of them. One for every scope. Each symbol can have a type and a value. Symbol table must complain about re-definitions. - process declarations by putting things in symbol tables. This may involve loading modules, but that can happen later too. Also create proper internal representations for things like structures and assign numbers for enums. Though we need to be able to evaluate constant expressions for that, which requires type analysis. So I guess that has to come later. - type resolution. Need to determine type for each expression and for each name and make sure the types all match - or at least are compatible - Actually, we cannot separate type checking from expression evaluation as they can depend on each other: if two arrays are sized by expressions and need to be compatible. - a virtual machine with a stack of frames and a heap. Maybe several stacks for tasks or co-routines. - a 'standard library' of functions, methods, constants - memory allocation - io - formatting - threads / IPC - string handling What errors are possible: - parse errors: bad token, unexpected token (which might EOF) - type errors: access attempt doesn't match type, in lots of different ways. Is ignored return value a type error? - namespace errors: name not defined, or already defined. - enum values being reused ( { a=1, b=1} ). - some constructs only allowed when 'unsafe' - is that a type error or something else? If an 'unsafe' module provides those constructs, then it could be a type/namespace error. But that hides them from the language. - numeric value is badly formatted - string contains unknown escape Todo: - generic number handling use gmp - bignum - string processing \ b r t n a f q v 0-3 x u U \ - simple symbol table - structure to hold type info - expression structure - statement structure - stack machine