| @ -1,54 +0,0 @@ | |||||
| package main | |||||
| import ( | |||||
| "fmt" | |||||
| "os" | |||||
| "github.com/brettlangdon/gython/ast" | |||||
| "github.com/brettlangdon/gython/compiler" | |||||
| "github.com/brettlangdon/gython/grammar" | |||||
| "github.com/brettlangdon/gython/scanner" | |||||
| "github.com/brettlangdon/gython/token" | |||||
| ) | |||||
| func tokenize() { | |||||
| tokenizer := scanner.NewScanner(os.Stdin) | |||||
| for { | |||||
| tok := tokenizer.NextToken() | |||||
| tokenRange := fmt.Sprintf("%d,%d-%d,%d:", tok.LineStart, tok.ColumnStart, tok.LineEnd, tok.ColumnEnd) | |||||
| literalRep := fmt.Sprintf("%#v", tok.Literal) | |||||
| fmt.Printf("%-20s%-15s%-15s\n", tokenRange, tok.String(), literalRep) | |||||
| if tok.ID == token.ENDMARKER || tok.ID == token.ERRORTOKEN { | |||||
| break | |||||
| } | |||||
| } | |||||
| } | |||||
| func parseGrammar() *grammar.FileInput { | |||||
| tokenizer := scanner.NewScanner(os.Stdin) | |||||
| gp := grammar.NewGrammarParser(tokenizer) | |||||
| return gp.Parse() | |||||
| } | |||||
| func parseAST() ast.Mod { | |||||
| start := parseGrammar() | |||||
| mod, err := ast.ASTFromGrammar(start) | |||||
| if err != nil { | |||||
| panic(err) | |||||
| } | |||||
| return mod | |||||
| } | |||||
| func compile() { | |||||
| root := parseAST() | |||||
| codeobject := compiler.CompileAST(root) | |||||
| fmt.Println(codeobject) | |||||
| } | |||||
| func main() { | |||||
| // start := parseGrammar() | |||||
| // fmt.Println(start.Repr()) | |||||
| // root := parseAST() | |||||
| // fmt.Println(root) | |||||
| compile() | |||||
| } | |||||
| @ -0,0 +1,10 @@ | |||||
| package gython | |||||
| type Bytes struct { | |||||
| } | |||||
| func (bytes *Bytes) object() {} | |||||
| func NewBytes() *Bytes { | |||||
| return &Bytes{} | |||||
| } | |||||
| @ -1,8 +1,27 @@ | |||||
| package gython | package gython | ||||
| type CodeObject struct { | type CodeObject struct { | ||||
| ArgCount int64 | |||||
| KeywordOnlyArgCount int64 | |||||
| LocalsCount int64 | |||||
| StackSize int64 | |||||
| Flags int64 | |||||
| Code *Bytes | |||||
| Constants *Tuple | |||||
| Names *Tuple | |||||
| VariableNames *Tuple | |||||
| FreeVariableNames *Tuple | |||||
| CellVariableNames *Tuple | |||||
| Filename *Unicode | |||||
| Name *Unicode | |||||
| FirstLineNumber int64 | |||||
| LineNumberTable *Bytes | |||||
| } | } | ||||
| func NewCodeObject() *CodeObject { | |||||
| func NewCodeObject(filename []byte, name []byte, firstLineNumber int64) *CodeObject { | |||||
| return &CodeObject{} | return &CodeObject{} | ||||
| } | } | ||||
| func (codeobject *CodeObject) object() {} | |||||
| @ -0,0 +1,5 @@ | |||||
| package gython | |||||
| type Float struct { | |||||
| Value float64 | |||||
| } | |||||
| @ -0,0 +1,5 @@ | |||||
| package gython | |||||
| type Long struct { | |||||
| Value float64 | |||||
| } | |||||
| @ -0,0 +1,5 @@ | |||||
| package gython | |||||
| type Object interface { | |||||
| object() | |||||
| } | |||||
| @ -0,0 +1,10 @@ | |||||
| package gython | |||||
| type Tuple struct { | |||||
| } | |||||
| func (tuple *Tuple) object() {} | |||||
| func NewTuple() *Tuple { | |||||
| return &Tuple{} | |||||
| } | |||||
| @ -0,0 +1,10 @@ | |||||
| package gython | |||||
| type Unicode struct { | |||||
| } | |||||
| func (unicode *Unicode) object() {} | |||||
| func NewUnicode() *Unicode { | |||||
| return &Unicode{} | |||||
| } | |||||