Documentation ¶
Overview ¶
package inter constains lexer, parser and interpreter.
Index ¶
- Constants
- Variables
- func Compare(n, m Number) int
- func IsKeyword(s string) bool
- func IsLitteral(t Term) bool
- func NewLexer(input io.Reader, fileName string) *myLex
- func Register(keyword string, evalArgFirst bool, primitive Primitive, help []string)
- func ToString(t any) string
- func Welcome() string
- type Bool
- type Environnement
- type Error
- type Inter
- type Number
- func (n Number) Div(m Number) Number
- func (Number) IsBool() bool
- func (Number) IsError() bool
- func (Number) IsNumber() bool
- func (Number) IsPair() bool
- func (Number) IsProcedure() bool
- func (Number) IsString() bool
- func (Number) IsSymbol() bool
- func (n Number) Minus(m Number) Number
- func (n Number) Mul(m Number) Number
- func (n Number) Normalize() Number
- func (n Number) Plus(m Number) Number
- func (n Number) String() string
- type Pair
- type Primitive
- type Procedure
- type String
- type Symbol
- type Term
- func MustParse1String(input string, sourcename string) Term
- func MustParseNString(input string, sourcename string) []Term
- func Parse1(rdr io.Reader, sourcename string) (Term, error)
- func Parse1File(filename string) (Term, error)
- func Parse1String(input string, sourcename string) (Term, error)
- func ParseN(rdr io.Reader, sourcename string) ([]Term, error)
- func ParseNFile(filename string) ([]Term, error)
- func ParseNString(input string, sourcename string) ([]Term, error)
Constants ¶
const ( VERSION = "0.3.0" COPYRIGHT = "(c) Xavier Gandillot (aka xavier268) 2023" )
const BOOL = 57349
const ERROR = 57350
const IDENT = 57347
const NUMBER = 57346
const SKIP = 57351
const STRING = 57348
Variables ¶
var DEBUG int = 0
0 - off, 1 - on, 2 - on with trace
var ErrCannotPopENv = fmt.Errorf("cannot pop environement, stack is empty")
var ErrDisplayTooManyArguments = fmt.Errorf("display: too many arguments")
var ErrEval = fmt.Errorf("cannot evaluate provided input")
var ErrInvalidArgumentListFormat = fmt.Errorf("invalid argument list format")
var ErrInvalidLambaFormals = fmt.Errorf("lambda: formals must be a a list of symbols, possibly empty")
var ErrLoadArgument = fmt.Errorf("load expects a single, String, argument")
var ErrNaN = fmt.Errorf("term is not a number")
var ErrNotAList = fmt.Errorf("not a list")
var ErrParenthesisUnbalanced = fmt.Errorf("too many closing parenthesis")
var ErrVariableNotBound = fmt.Errorf("variable is not bound")
var ErrVariableUnassigned = fmt.Errorf("variable is bound but unassigned")
var NumberNaN = Number{1, 0}
var NumberOne = Number{1, 1}
var NumberZero = Number{0, 1}
var PAT_OPERATOR = regexp.MustCompile(`^[()'.]$`) // tell if an ident is an operator, once identified as IDENT
Functions ¶
func IsLitteral ¶
Types ¶
type Environnement ¶
type Environnement struct {
// contains filtered or unexported fields
}
func (*Environnement) Dump ¶
func (s *Environnement) Dump()
Dump the current environnement and its ancestors
func (*Environnement) Fork ¶
func (ev *Environnement) Fork() *Environnement
func (*Environnement) Get ¶
func (ev *Environnement) Get(sym Symbol) (res Term, ok bool)
get symbol binding in environements, recursively. Ok if found.
func (*Environnement) Set ¶
func (ev *Environnement) Set(sym Symbol, t Term)
Set symbol in current environement, creating it if needed
func (*Environnement) SetBang ¶
func (ev *Environnement) SetBang(sym Symbol, t Term) error
Try to find the specified variable in one of the environements, and set this specific variable in this specific environement to the value. Variable is NEVER created if not found, but an error will be returned. A existing variable will NEVER be shadowed, but will be changed.
func (Environnement) String ¶
func (s Environnement) String() string
type Inter ¶
type Inter struct { OnQuit func() // a function hook, called when the interpreter is quitting. // contains filtered or unexported fields }
type Number ¶
numbers are rational numbers Num & Den are always prime among them, Num is always > 0, except to represent NaN with 1/0.
func NumberFromString ¶
type Primitive ¶
All primitive, built in functions or macros must have this signature. They will be called with args containing the cdr of the form ( keyword .... ). detailed format depends on the function.
type Procedure ¶
type Procedure struct {
// contains filtered or unexported fields
}
A procedure is a Term that cannot be entered directly by the user, but is created by a lambda application. All procedures evaluate their arguments. Doc says : Procedures are created by evaluating lambda expressions (see Lambda Expressions); the lambda may either be explicit or may be implicit as in a “procedure define” (see Definitions).
type Term ¶
type Term interface { String() string IsPair() bool IsSymbol() bool IsString() bool IsNumber() bool IsBool() bool IsProcedure() bool IsError() bool }
func MustParse1String ¶
func MustParseNString ¶
func Parse1File ¶
func ParseNFile ¶
Source Files ¶
- def.bool.go
- def.error.go
- def.number.go
- def.pair.go
- def.procedure.go
- def.string.go
- def.symbol.go
- def.term.go
- env.go
- eval.go
- eval.keywords.go
- eval.literal.go
- eval.procedure.go
- eval.sp.ariths.go
- eval.sp.begin.go
- eval.sp.define.go
- eval.sp.display.go
- eval.sp.files.go
- eval.sp.go
- eval.sp.help.go
- eval.sp.keywords.go
- eval.sp.lambda.go
- eval.sp.let.go
- eval.sp.list.go
- eval.sp.quit.go
- eval.sp.quote.go
- eval.var.go
- gcd.go
- grammar.y
- inter.go
- lexer.go
- parser.utils.go
- repl.go
- utils.go
- version.go