mirror of
https://github.com/golang/go.git
synced 2026-02-13 19:04:41 +00:00
change *map to map; *chan to chan; new(T) to new(*T)
fix bugs left over from *[] to [] conversion. TBR=r OCL=21576 CL=21581
This commit is contained in:
parent
d47d888ba6
commit
08ca30bbfa
111 changed files with 814 additions and 845 deletions
|
|
@ -33,7 +33,7 @@ func (x *Literal) typ() *Globals.Type {
|
|||
|
||||
|
||||
export func NewLiteral(pos int, typ *Globals.Type) *Literal {
|
||||
x := new(Literal);
|
||||
x := new(*Literal);
|
||||
x.pos_ = pos;
|
||||
x.typ_ = typ;
|
||||
return x;
|
||||
|
|
@ -63,7 +63,7 @@ func (x *Object) typ() *Globals.Type {
|
|||
|
||||
|
||||
export func NewObject(pos int, obj* Globals.Object) *Object {
|
||||
x := new(Object);
|
||||
x := new(*Object);
|
||||
x.pos_ = pos;
|
||||
x.obj = obj;
|
||||
return x;
|
||||
|
|
@ -88,7 +88,7 @@ func (x *Selector) typ() *Globals.Type {
|
|||
|
||||
|
||||
export func NewSelector(pos int, typ *Globals.Type) *Selector {
|
||||
x := new(Selector);
|
||||
x := new(*Selector);
|
||||
x.pos_ = pos;
|
||||
x.typ_ = typ;
|
||||
return x;
|
||||
|
|
|
|||
|
|
@ -93,16 +93,16 @@ export func Compile(comp *Globals.Compilation, src_file string) {
|
|||
print(src_file, "\n");
|
||||
}
|
||||
|
||||
scanner := new(Scanner.Scanner);
|
||||
scanner := new(*Scanner.Scanner);
|
||||
scanner.Open(src_file, src);
|
||||
|
||||
var tstream *chan *Scanner.Token;
|
||||
var tstream chan *Scanner.Token;
|
||||
if comp.flags.token_chan {
|
||||
tstream = new(chan *Scanner.Token, 100);
|
||||
go scanner.Server(tstream);
|
||||
}
|
||||
|
||||
parser := new(Parser.Parser);
|
||||
parser := new(*Parser.Parser);
|
||||
parser.Open(comp, scanner, tstream);
|
||||
|
||||
parser.ParseProgram();
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ type T8 chan <- *T6
|
|||
|
||||
type T9 struct {
|
||||
p *T9;
|
||||
q [] *map [int] *T9;
|
||||
q [] map [int] *T9;
|
||||
f *(x, y *T9) *T9;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export type List struct {
|
|||
export type Scope struct {
|
||||
parent *Scope;
|
||||
entries *List;
|
||||
// entries *map[string] *Object; // doesn't work properly
|
||||
// entries map[string] *Object; // doesn't work properly
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ type Elem struct {
|
|||
export var Universe_void_t *Type // initialized by Universe to Universe.void_t
|
||||
|
||||
export func NewObject(pos, kind int, ident string) *Object {
|
||||
obj := new(Object);
|
||||
obj := new(*Object);
|
||||
obj.exported = false;
|
||||
obj.pos = pos;
|
||||
obj.kind = kind;
|
||||
|
|
@ -141,7 +141,7 @@ export func NewObject(pos, kind int, ident string) *Object {
|
|||
|
||||
|
||||
export func NewType(form int) *Type {
|
||||
typ := new(Type);
|
||||
typ := new(*Type);
|
||||
typ.ref = -1; // not yet exported
|
||||
typ.form = form;
|
||||
return typ;
|
||||
|
|
@ -149,7 +149,7 @@ export func NewType(form int) *Type {
|
|||
|
||||
|
||||
export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
|
||||
pkg := new(Package);
|
||||
pkg := new(*Package);
|
||||
pkg.ref = -1; // not yet exported
|
||||
pkg.file_name = file_name;
|
||||
pkg.key = "<the package key>"; // empty key means package forward declaration
|
||||
|
|
@ -160,12 +160,12 @@ export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
|
|||
|
||||
|
||||
export func NewList() *List {
|
||||
return new(List);
|
||||
return new(*List);
|
||||
}
|
||||
|
||||
|
||||
export func NewScope(parent *Scope) *Scope {
|
||||
scope := new(Scope);
|
||||
scope := new(*Scope);
|
||||
scope.parent = parent;
|
||||
scope.entries = NewList();
|
||||
return scope;
|
||||
|
|
@ -176,7 +176,7 @@ export func NewScope(parent *Scope) *Scope {
|
|||
// Object methods
|
||||
|
||||
func (obj *Object) Copy() *Object {
|
||||
copy := new(Object);
|
||||
copy := new(*Object);
|
||||
copy.exported = obj.exported;
|
||||
copy.pos = obj.pos;
|
||||
copy.kind = obj.kind;
|
||||
|
|
@ -211,7 +211,7 @@ func (L *List) Clear() {
|
|||
|
||||
func (L *List) Add() *Elem {
|
||||
L.len_++;
|
||||
e := new(Elem);
|
||||
e := new(*Elem);
|
||||
if L.first == nil {
|
||||
L.first = e;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ func Next() string {
|
|||
|
||||
func main() {
|
||||
arg := Next();
|
||||
|
||||
|
||||
if arg == "" {
|
||||
PrintHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
// collect flags and files
|
||||
flags := new(Globals.Flags);
|
||||
flags := new(*Globals.Flags);
|
||||
files := Globals.NewList();
|
||||
for arg != "" {
|
||||
switch arg {
|
||||
|
|
@ -81,20 +81,20 @@ func main() {
|
|||
}
|
||||
arg = Next();
|
||||
}
|
||||
|
||||
|
||||
// setup environment
|
||||
env := new(Globals.Environment);
|
||||
env := new(*Globals.Environment);
|
||||
env.Import = &Compilation.Import;
|
||||
env.Export = &Compilation.Export;
|
||||
env.Compile = &Compilation.Compile;
|
||||
|
||||
|
||||
// compile files
|
||||
for p := files.first; p != nil; p = p.next {
|
||||
// setup compilation
|
||||
comp := new(Globals.Compilation);
|
||||
comp := new(*Globals.Compilation);
|
||||
comp.flags = flags;
|
||||
comp.env = env;
|
||||
|
||||
|
||||
// compile
|
||||
Compilation.Compile(comp, p.str);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -26,24 +26,24 @@ export const (
|
|||
RBRACK;
|
||||
LBRACE;
|
||||
RBRACE;
|
||||
|
||||
|
||||
ASSIGN;
|
||||
DEFINE;
|
||||
|
||||
|
||||
INC;
|
||||
DEC;
|
||||
NOT;
|
||||
|
||||
|
||||
AND;
|
||||
OR;
|
||||
XOR;
|
||||
|
||||
|
||||
ADD;
|
||||
SUB;
|
||||
MUL;
|
||||
QUO;
|
||||
REM;
|
||||
|
||||
|
||||
EQL;
|
||||
NEQ;
|
||||
LSS;
|
||||
|
|
@ -53,7 +53,7 @@ export const (
|
|||
|
||||
SHL;
|
||||
SHR;
|
||||
|
||||
|
||||
ARROW;
|
||||
|
||||
ADD_ASSIGN;
|
||||
|
|
@ -65,13 +65,13 @@ export const (
|
|||
AND_ASSIGN;
|
||||
OR_ASSIGN;
|
||||
XOR_ASSIGN;
|
||||
|
||||
|
||||
SHL_ASSIGN;
|
||||
SHR_ASSIGN;
|
||||
|
||||
LAND;
|
||||
LOR;
|
||||
|
||||
|
||||
// IDENT must be immediately before keywords
|
||||
IDENT;
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ export const (
|
|||
)
|
||||
|
||||
|
||||
var Keywords *map [string] int;
|
||||
var Keywords map [string] int;
|
||||
var VerboseMsgs bool; // error message customization
|
||||
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ export func TokenName(tok int) string {
|
|||
|
||||
case ASSIGN: return "=";
|
||||
case DEFINE: return ":=";
|
||||
|
||||
|
||||
case INC: return "++";
|
||||
case DEC: return "--";
|
||||
case NOT: return "!";
|
||||
|
|
@ -145,13 +145,13 @@ export func TokenName(tok int) string {
|
|||
case AND: return "&";
|
||||
case OR: return "|";
|
||||
case XOR: return "^";
|
||||
|
||||
|
||||
case ADD: return "+";
|
||||
case SUB: return "-";
|
||||
case MUL: return "*";
|
||||
case QUO: return "/";
|
||||
case REM: return "%";
|
||||
|
||||
|
||||
case EQL: return "==";
|
||||
case NEQ: return "!=";
|
||||
case LSS: return "<";
|
||||
|
|
@ -161,7 +161,7 @@ export func TokenName(tok int) string {
|
|||
|
||||
case SHL: return "<<";
|
||||
case SHR: return ">>";
|
||||
|
||||
|
||||
case ARROW: return "<-";
|
||||
|
||||
case ADD_ASSIGN: return "+=";
|
||||
|
|
@ -213,18 +213,18 @@ export func TokenName(tok int) string {
|
|||
case TYPE: return "type";
|
||||
case VAR: return "var";
|
||||
}
|
||||
|
||||
|
||||
return "???";
|
||||
}
|
||||
|
||||
|
||||
func init() {
|
||||
Keywords = new(map [string] int);
|
||||
|
||||
|
||||
for i := KEYWORDS_BEG; i <= KEYWORDS_END; i++ {
|
||||
Keywords[TokenName(i)] = i;
|
||||
}
|
||||
|
||||
|
||||
// Provide column information in error messages for gri only...
|
||||
VerboseMsgs = Platform.USER == "gri";
|
||||
}
|
||||
|
|
@ -258,7 +258,7 @@ export type Scanner struct {
|
|||
filename string; // error reporting only
|
||||
nerrors int; // number of errors
|
||||
errpos int; // last error position
|
||||
|
||||
|
||||
src string; // scanned source
|
||||
pos int; // current reading position
|
||||
ch int; // one char look-ahead
|
||||
|
|
@ -296,7 +296,7 @@ func (S *Scanner) Next() {
|
|||
src := S.src;
|
||||
lim := len(src);
|
||||
pos := S.pos;
|
||||
|
||||
|
||||
// 1-byte sequence
|
||||
// 0000-007F => T1
|
||||
if pos >= lim {
|
||||
|
|
@ -371,7 +371,7 @@ bad:
|
|||
func (S *Scanner) LineCol(pos int) (line, col int) {
|
||||
line = 1;
|
||||
lpos := 0;
|
||||
|
||||
|
||||
src := S.src;
|
||||
if pos > len(src) {
|
||||
pos = len(src);
|
||||
|
|
@ -383,7 +383,7 @@ func (S *Scanner) LineCol(pos int) (line, col int) {
|
|||
lpos = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return line, pos - lpos;
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +409,7 @@ func (S *Scanner) Error(pos int, msg string) {
|
|||
S.nerrors++;
|
||||
S.errpos = pos;
|
||||
}
|
||||
|
||||
|
||||
if S.nerrors >= 10 {
|
||||
sys.exit(1);
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ func (S *Scanner) Open(filename, src string) {
|
|||
S.filename = filename;
|
||||
S.nerrors = 0;
|
||||
S.errpos = 0;
|
||||
|
||||
|
||||
S.src = src;
|
||||
S.pos = 0;
|
||||
S.Next();
|
||||
|
|
@ -467,7 +467,7 @@ func (S *Scanner) SkipComment() {
|
|||
for S.ch != '\n' && S.ch >= 0 {
|
||||
S.Next();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
/* comment */
|
||||
pos := S.chpos - 1;
|
||||
|
|
@ -491,13 +491,13 @@ func (S *Scanner) ScanIdentifier() (tok int, val string) {
|
|||
S.Next();
|
||||
}
|
||||
val = S.src[pos : S.chpos];
|
||||
|
||||
|
||||
var present bool;
|
||||
tok, present = Keywords[val];
|
||||
if !present {
|
||||
tok = IDENT;
|
||||
}
|
||||
|
||||
|
||||
return tok, val;
|
||||
}
|
||||
|
||||
|
|
@ -512,14 +512,14 @@ func (S *Scanner) ScanMantissa(base int) {
|
|||
func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) {
|
||||
pos := S.chpos;
|
||||
tok = INT;
|
||||
|
||||
|
||||
if seen_decimal_point {
|
||||
tok = FLOAT;
|
||||
pos--; // '.' is one byte
|
||||
S.ScanMantissa(10);
|
||||
goto exponent;
|
||||
}
|
||||
|
||||
|
||||
if S.ch == '0' {
|
||||
// int or float
|
||||
S.Next();
|
||||
|
|
@ -539,18 +539,18 @@ func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) {
|
|||
}
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
mantissa:
|
||||
// decimal int or float
|
||||
S.ScanMantissa(10);
|
||||
|
||||
|
||||
if S.ch == '.' {
|
||||
// float
|
||||
tok = FLOAT;
|
||||
S.Next();
|
||||
S.ScanMantissa(10)
|
||||
}
|
||||
|
||||
|
||||
exponent:
|
||||
if S.ch == 'e' || S.ch == 'E' {
|
||||
// float
|
||||
|
|
@ -561,7 +561,7 @@ exponent:
|
|||
}
|
||||
S.ScanMantissa(10);
|
||||
}
|
||||
|
||||
|
||||
exit:
|
||||
return tok, S.src[pos : S.chpos];
|
||||
}
|
||||
|
|
@ -580,22 +580,22 @@ func (S *Scanner) ScanDigits(n int, base int) {
|
|||
|
||||
func (S *Scanner) ScanEscape() string {
|
||||
// TODO: fix this routine
|
||||
|
||||
|
||||
ch := S.ch;
|
||||
pos := S.chpos;
|
||||
S.Next();
|
||||
switch (ch) {
|
||||
case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"':
|
||||
return string(ch);
|
||||
|
||||
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7':
|
||||
S.ScanDigits(3 - 1, 8); // 1 char already read
|
||||
return ""; // TODO fix this
|
||||
|
||||
|
||||
case 'x':
|
||||
S.ScanDigits(2, 16);
|
||||
return ""; // TODO fix this
|
||||
|
||||
|
||||
case 'u':
|
||||
S.ScanDigits(4, 16);
|
||||
return ""; // TODO fix this
|
||||
|
|
@ -642,7 +642,7 @@ func (S *Scanner) ScanString() string {
|
|||
S.ScanEscape();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
S.Next();
|
||||
return S.src[pos : S.chpos];
|
||||
}
|
||||
|
|
@ -707,11 +707,11 @@ func (S *Scanner) Select4(tok0, tok1, ch2, tok2, tok3 int) int {
|
|||
|
||||
func (S *Scanner) Scan() (tok, pos int, val string) {
|
||||
S.SkipWhitespace();
|
||||
|
||||
|
||||
ch := S.ch;
|
||||
tok = ILLEGAL;
|
||||
pos = S.chpos;
|
||||
|
||||
|
||||
switch {
|
||||
case is_letter(ch): tok, val = S.ScanIdentifier();
|
||||
case digit_val(ch) < 10: tok, val = S.ScanNumber(false);
|
||||
|
|
@ -767,7 +767,7 @@ func (S *Scanner) Scan() (tok, pos int, val string) {
|
|||
tok = ILLEGAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return tok, pos, val;
|
||||
}
|
||||
|
||||
|
|
@ -779,9 +779,9 @@ export type Token struct {
|
|||
}
|
||||
|
||||
|
||||
func (S *Scanner) Server(c *chan *Token) {
|
||||
func (S *Scanner) Server(c chan *Token) {
|
||||
for {
|
||||
t := new(Token);
|
||||
t := new(*Token);
|
||||
t.tok, t.pos, t.val = S.Scan();
|
||||
c <- t;
|
||||
if t.tok == EOF {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import Scanner "scanner"
|
|||
|
||||
|
||||
func Scan1(filename, src string) {
|
||||
S := new(Scanner.Scanner);
|
||||
S := new(*Scanner.Scanner);
|
||||
S.Open(filename, src);
|
||||
for {
|
||||
tok, pos, val := S.Scan();
|
||||
|
|
@ -25,7 +25,7 @@ func Scan1(filename, src string) {
|
|||
|
||||
|
||||
func Scan2(filename, src string) {
|
||||
S := new(Scanner.Scanner);
|
||||
S := new(*Scanner.Scanner);
|
||||
S.Open(filename, src);
|
||||
c := new(chan *Scanner.Token, 32);
|
||||
go S.Server(c);
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ func Error(msg string) {
|
|||
|
||||
type Verifier struct {
|
||||
comp *Globals.Compilation;
|
||||
|
||||
|
||||
// various sets for marking the graph (and thus avoid cycles)
|
||||
objs *map[*Globals.Object] bool;
|
||||
typs *map[*Globals.Type] bool;
|
||||
pkgs *map[*Globals.Package] bool;
|
||||
objs map[*Globals.Object] bool;
|
||||
typs map[*Globals.Type] bool;
|
||||
pkgs map[*Globals.Package] bool;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -39,11 +39,11 @@ func (V *Verifier) VerifyType(typ *Globals.Type) {
|
|||
return; // already verified
|
||||
}
|
||||
V.typs[typ] = true;
|
||||
|
||||
|
||||
if typ.obj != nil {
|
||||
V.VerifyObject(typ.obj, 0);
|
||||
}
|
||||
|
||||
|
||||
switch typ.form {
|
||||
case Type.VOID:
|
||||
break; // TODO for now - remove eventually
|
||||
|
|
@ -95,10 +95,10 @@ func (V *Verifier) VerifyObject(obj *Globals.Object, pnolev int) {
|
|||
return; // already verified
|
||||
}
|
||||
V.objs[obj] = true;
|
||||
|
||||
|
||||
// all objects have a non-nil type
|
||||
V.VerifyType(obj.typ);
|
||||
|
||||
|
||||
switch obj.kind {
|
||||
case Object.CONST:
|
||||
break;
|
||||
|
|
@ -130,7 +130,7 @@ func (V *Verifier) VerifyPackage(pkg *Globals.Package, pno int) {
|
|||
return; // already verified
|
||||
}
|
||||
V.pkgs[pkg] = true;
|
||||
|
||||
|
||||
V.VerifyObject(pkg.obj, pno);
|
||||
V.VerifyScope(pkg.scope);
|
||||
}
|
||||
|
|
@ -158,6 +158,6 @@ func (V *Verifier) Verify(comp *Globals.Compilation) {
|
|||
|
||||
|
||||
export func Verify(comp *Globals.Compilation) {
|
||||
V := new(Verifier);
|
||||
V := new(*Verifier);
|
||||
V.Verify(comp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,14 +56,14 @@ export func NewExpr(pos, tok int, x, y *Expr) *Expr {
|
|||
if x != nil && x.tok == Scanner.TYPE || y != nil && y.tok == Scanner.TYPE {
|
||||
panic("no type expression allowed");
|
||||
}
|
||||
e := new(Expr);
|
||||
e := new(*Expr);
|
||||
e.pos, e.tok, e.x, e.y = pos, tok, x, y;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
export func NewLit(pos, tok int, s string) *Expr {
|
||||
e := new(Expr);
|
||||
e := new(*Expr);
|
||||
e.pos, e.tok, e.s = pos, tok, s;
|
||||
return e;
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ func (t *Type) nfields() int {
|
|||
|
||||
|
||||
export func NewType(pos, tok int) *Type {
|
||||
t := new(Type);
|
||||
t := new(*Type);
|
||||
t.pos, t.tok = pos, tok;
|
||||
return t;
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ export func NewType(pos, tok int) *Type {
|
|||
|
||||
// requires complete Type type
|
||||
export func NewTypeExpr(t *Type) *Expr {
|
||||
e := new(Expr);
|
||||
e := new(*Expr);
|
||||
e.pos, e.tok, e.t = t.pos, Scanner.TYPE, t;
|
||||
return e;
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ export type Stat struct {
|
|||
|
||||
|
||||
export func NewStat(pos, tok int) *Stat {
|
||||
s := new(Stat);
|
||||
s := new(*Stat);
|
||||
s.pos, s.tok = pos, tok;
|
||||
return s;
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ export type Decl struct {
|
|||
|
||||
|
||||
export func NewDecl(pos, tok int, exported bool) *Decl {
|
||||
d := new(Decl);
|
||||
d := new(*Decl);
|
||||
d.pos, d.tok, d.exported = pos, tok, exported;
|
||||
return d;
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ export type Comment struct {
|
|||
|
||||
|
||||
export func NewComment(pos int, text string) *Comment {
|
||||
c := new(Comment);
|
||||
c := new(*Comment);
|
||||
c.pos, c.text = pos, text;
|
||||
return c;
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ export type Program struct {
|
|||
|
||||
|
||||
export func NewProgram(pos int) *Program {
|
||||
p := new(Program);
|
||||
p := new(*Program);
|
||||
p.pos = pos;
|
||||
return p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func (h *ErrorHandler) Init(filename, src string, columns bool) {
|
|||
func (h *ErrorHandler) LineCol(pos int) (line, col int) {
|
||||
line = 1;
|
||||
lpos := 0;
|
||||
|
||||
|
||||
src := h.src;
|
||||
if pos > len(src) {
|
||||
pos = len(src);
|
||||
|
|
@ -66,7 +66,7 @@ func (h *ErrorHandler) LineCol(pos int) (line, col int) {
|
|||
lpos = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return line, pos - lpos;
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ func (h *ErrorHandler) ErrorMsg(pos int, msg string) {
|
|||
}
|
||||
}
|
||||
print(" ", msg, "\n");
|
||||
|
||||
|
||||
h.nerrors++;
|
||||
h.errpos = pos;
|
||||
|
||||
|
|
@ -100,10 +100,10 @@ func (h *ErrorHandler) Error(pos int, msg string) {
|
|||
if delta < 0 {
|
||||
delta = -delta;
|
||||
}
|
||||
|
||||
|
||||
if delta > errdist || h.nerrors == 0 /* always report first error */ {
|
||||
h.ErrorMsg(pos, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -118,14 +118,14 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
|
|||
print("cannot open ", src_file, "\n");
|
||||
return nil, 1;
|
||||
}
|
||||
|
||||
|
||||
var err ErrorHandler;
|
||||
err.Init(src_file, src, flags.columns);
|
||||
|
||||
var scanner Scanner.Scanner;
|
||||
scanner.Init(&err, src, true, flags.testmode);
|
||||
|
||||
var tstream *<-chan *Scanner.Token;
|
||||
var tstream <-chan *Scanner.Token;
|
||||
if flags.tokenchan {
|
||||
tstream = scanner.TokenStream();
|
||||
}
|
||||
|
|
@ -134,11 +134,11 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
|
|||
parser.Open(flags.verbose, flags.sixg, flags.deps, &scanner, tstream);
|
||||
|
||||
prog := parser.ParseProgram();
|
||||
|
||||
|
||||
if err.nerrors == 0 {
|
||||
TypeChecker.CheckProgram(prog);
|
||||
}
|
||||
|
||||
|
||||
return prog, err.nerrors;
|
||||
}
|
||||
|
||||
|
|
@ -153,27 +153,27 @@ func FileExists(name string) bool {
|
|||
}
|
||||
|
||||
|
||||
func AddDeps(globalset *map [string] bool, wset *array.Array, src_file string, flags *Flags) {
|
||||
func AddDeps(globalset map [string] bool, wset *array.Array, src_file string, flags *Flags) {
|
||||
dummy, found := globalset[src_file];
|
||||
if !found {
|
||||
globalset[src_file] = true;
|
||||
|
||||
|
||||
prog, nerrors := Compile(src_file, flags);
|
||||
if nerrors > 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
nimports := prog.decls.Len();
|
||||
if nimports > 0 {
|
||||
print(src_file, ".6:\t");
|
||||
|
||||
|
||||
localset := new(map [string] bool);
|
||||
for i := 0; i < nimports; i++ {
|
||||
decl := prog.decls.At(i).(*AST.Decl);
|
||||
assert(decl.tok == Scanner.IMPORT && decl.val.tok == Scanner.STRING);
|
||||
src := decl.val.s;
|
||||
src = src[1 : len(src) - 1]; // strip "'s
|
||||
|
||||
|
||||
// ignore files when they are seen a 2nd time
|
||||
dummy, found := localset[src];
|
||||
if !found {
|
||||
|
|
@ -184,7 +184,7 @@ func AddDeps(globalset *map [string] bool, wset *array.Array, src_file string, f
|
|||
} else if
|
||||
FileExists(Platform.GOROOT + "/pkg/" + src + ".6") ||
|
||||
FileExists(Platform.GOROOT + "/pkg/" + src + ".a") {
|
||||
|
||||
|
||||
} else {
|
||||
// TODO should collect these and print later
|
||||
//print("missing file: ", src, "\n");
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export type Package struct {
|
|||
|
||||
export type Scope struct {
|
||||
parent *Scope;
|
||||
entries *map[string] *Object;
|
||||
entries map[string] *Object;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -72,15 +72,15 @@ export type Environment struct {
|
|||
export type OldCompilation struct {
|
||||
// environment
|
||||
env *Environment;
|
||||
|
||||
|
||||
// TODO rethink the need for this here
|
||||
src_file string;
|
||||
src string;
|
||||
|
||||
|
||||
// Error handling
|
||||
nerrors int; // number of errors reported
|
||||
errpos int; // last error position
|
||||
|
||||
|
||||
// TODO use open arrays eventually
|
||||
pkg_list [256] *Package; // pkg_list[0] is the current package
|
||||
pkg_ref int;
|
||||
|
|
@ -119,7 +119,7 @@ export type Elem struct {
|
|||
export var Universe_void_typ *Type // initialized by Universe to Universe.void_typ
|
||||
|
||||
export func NewObject(pos, kind int, ident string) *Object {
|
||||
obj := new(Object);
|
||||
obj := new(*Object);
|
||||
obj.exported = false;
|
||||
obj.pos = pos;
|
||||
obj.kind = kind;
|
||||
|
|
@ -131,7 +131,7 @@ export func NewObject(pos, kind int, ident string) *Object {
|
|||
|
||||
|
||||
export func NewType(form int) *Type {
|
||||
typ := new(Type);
|
||||
typ := new(*Type);
|
||||
typ.ref = -1; // not yet exported
|
||||
typ.form = form;
|
||||
return typ;
|
||||
|
|
@ -139,7 +139,7 @@ export func NewType(form int) *Type {
|
|||
|
||||
|
||||
export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
|
||||
pkg := new(Package);
|
||||
pkg := new(*Package);
|
||||
pkg.ref = -1; // not yet exported
|
||||
pkg.file_name = file_name;
|
||||
pkg.key = "<the package key>"; // empty key means package forward declaration
|
||||
|
|
@ -150,7 +150,7 @@ export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
|
|||
|
||||
|
||||
export func NewScope(parent *Scope) *Scope {
|
||||
scope := new(Scope);
|
||||
scope := new(*Scope);
|
||||
scope.parent = parent;
|
||||
scope.entries = new(map[string]*Object, 8);
|
||||
return scope;
|
||||
|
|
@ -161,7 +161,7 @@ export func NewScope(parent *Scope) *Scope {
|
|||
// Object methods
|
||||
|
||||
func (obj *Object) Copy() *Object {
|
||||
copy := new(Object);
|
||||
copy := new(*Object);
|
||||
copy.exported = obj.exported;
|
||||
copy.pos = obj.pos;
|
||||
copy.kind = obj.kind;
|
||||
|
|
|
|||
|
|
@ -13,17 +13,17 @@ export type Parser struct {
|
|||
// Tracing/debugging
|
||||
verbose, sixg, deps bool;
|
||||
indent uint;
|
||||
|
||||
|
||||
// Scanner
|
||||
scanner *Scanner.Scanner;
|
||||
tokchan *<-chan *Scanner.Token;
|
||||
tokchan <-chan *Scanner.Token;
|
||||
comments *array.Array;
|
||||
|
||||
|
||||
// Scanner.Token
|
||||
pos int; // token source position
|
||||
tok int; // one token look-ahead
|
||||
val string; // token value (for IDENT, NUMBER, STRING only)
|
||||
|
||||
|
||||
// Non-syntactic parser control
|
||||
opt_semi bool; // true if semicolon is optional
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ func (P *Parser) Next0() {
|
|||
P.tok, P.pos, P.val = t.tok, t.pos, t.val;
|
||||
}
|
||||
P.opt_semi = false;
|
||||
|
||||
|
||||
if P.verbose {
|
||||
P.PrintIndent();
|
||||
print("[", P.pos, "] ", Scanner.TokenString(P.tok), "\n");
|
||||
|
|
@ -84,16 +84,16 @@ func (P *Parser) Next() {
|
|||
}
|
||||
|
||||
|
||||
func (P *Parser) Open(verbose, sixg, deps bool, scanner *Scanner.Scanner, tokchan *<-chan *Scanner.Token) {
|
||||
func (P *Parser) Open(verbose, sixg, deps bool, scanner *Scanner.Scanner, tokchan <-chan *Scanner.Token) {
|
||||
P.verbose = verbose;
|
||||
P.sixg = sixg;
|
||||
P.deps = deps;
|
||||
P.indent = 0;
|
||||
|
||||
|
||||
P.scanner = scanner;
|
||||
P.tokchan = tokchan;
|
||||
P.comments = array.New(0);
|
||||
|
||||
|
||||
P.Next();
|
||||
P.expr_lev = 0;
|
||||
P.scope_lev = 0;
|
||||
|
|
@ -182,7 +182,7 @@ func (P *Parser) ParseIdent() *AST.Expr {
|
|||
} else {
|
||||
P.Expect(Scanner.IDENT); // use Expect() error handling
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -214,13 +214,13 @@ func (P *Parser) ParseIdentList() *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseType() *AST.Type {
|
||||
P.Trace("Type");
|
||||
|
||||
|
||||
t := P.TryType();
|
||||
if t == nil {
|
||||
P.Error(P.pos, "type expected");
|
||||
t = AST.BadType;
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return t;
|
||||
}
|
||||
|
|
@ -228,9 +228,9 @@ func (P *Parser) ParseType() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseVarType() *AST.Type {
|
||||
P.Trace("VarType");
|
||||
|
||||
|
||||
typ := P.ParseType();
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return typ;
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ func (P *Parser) ParseQualifiedIdent() *AST.Expr {
|
|||
y := P.ParseIdent();
|
||||
x = P.NewExpr(pos, Scanner.PERIOD, x, y);
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -254,7 +254,7 @@ func (P *Parser) ParseQualifiedIdent() *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseTypeName() *AST.Type {
|
||||
P.Trace("TypeName");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, P.tok);
|
||||
t.expr = P.ParseQualifiedIdent();
|
||||
|
||||
|
|
@ -265,7 +265,7 @@ func (P *Parser) ParseTypeName() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseArrayType() *AST.Type {
|
||||
P.Trace("ArrayType");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.LBRACK);
|
||||
P.Expect(Scanner.LBRACK);
|
||||
if P.tok != Scanner.RBRACK {
|
||||
|
|
@ -281,7 +281,7 @@ func (P *Parser) ParseArrayType() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseChannelType() *AST.Type {
|
||||
P.Trace("ChannelType");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.CHAN);
|
||||
t.mode = AST.FULL;
|
||||
if P.tok == Scanner.CHAN {
|
||||
|
|
@ -340,13 +340,13 @@ func (P *Parser) ParseVarDeclList(list *array.Array, ellipsis_ok bool) {
|
|||
typ = AST.NewType(P.pos, Scanner.ELLIPSIS);
|
||||
P.Next();
|
||||
}
|
||||
|
||||
|
||||
if ellipsis_ok /* param list */ && i0 > 0 && typ == nil {
|
||||
// not the first parameter section; we must have a type
|
||||
P.Error(P.pos, "type expected");
|
||||
typ = AST.BadType;
|
||||
}
|
||||
|
||||
|
||||
// convert the list into a list of (type) expressions
|
||||
if typ != nil {
|
||||
// all list entries must be identifiers
|
||||
|
|
@ -371,21 +371,21 @@ func (P *Parser) ParseVarDeclList(list *array.Array, ellipsis_ok bool) {
|
|||
list.Set(i, AST.NewTypeExpr(t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
}
|
||||
|
||||
|
||||
func (P *Parser) ParseParameterList(ellipsis_ok bool) *array.Array {
|
||||
P.Trace("ParameterList");
|
||||
|
||||
|
||||
list := array.New(0);
|
||||
P.ParseVarDeclList(list, ellipsis_ok);
|
||||
for P.tok == Scanner.COMMA {
|
||||
P.Next();
|
||||
P.ParseVarDeclList(list, ellipsis_ok);
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return list;
|
||||
}
|
||||
|
|
@ -393,7 +393,7 @@ func (P *Parser) ParseParameterList(ellipsis_ok bool) *array.Array {
|
|||
|
||||
func (P *Parser) ParseParameters(ellipsis_ok bool) *AST.Type {
|
||||
P.Trace("Parameters");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.STRUCT);
|
||||
P.Expect(Scanner.LPAREN);
|
||||
if P.tok != Scanner.RPAREN {
|
||||
|
|
@ -401,7 +401,7 @@ func (P *Parser) ParseParameters(ellipsis_ok bool) *AST.Type {
|
|||
}
|
||||
t.end = P.pos;
|
||||
P.Expect(Scanner.RPAREN);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return t;
|
||||
}
|
||||
|
|
@ -425,7 +425,7 @@ func (P *Parser) ParseResultList() {
|
|||
|
||||
func (P *Parser) ParseResult() *AST.Type {
|
||||
P.Trace("Result");
|
||||
|
||||
|
||||
var t *AST.Type;
|
||||
if P.tok == Scanner.LPAREN {
|
||||
t = P.ParseParameters(false);
|
||||
|
|
@ -452,12 +452,12 @@ func (P *Parser) ParseResult() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseFunctionType() *AST.Type {
|
||||
P.Trace("FunctionType");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.LPAREN);
|
||||
t.list = P.ParseParameters(true).list; // TODO find better solution
|
||||
t.end = P.pos;
|
||||
t.elt = P.ParseResult();
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return t;
|
||||
}
|
||||
|
|
@ -465,7 +465,7 @@ func (P *Parser) ParseFunctionType() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseMethodSpec(list *array.Array) {
|
||||
P.Trace("MethodDecl");
|
||||
|
||||
|
||||
list.Push(P.ParseIdentList());
|
||||
t := AST.BadType;
|
||||
if P.sixg {
|
||||
|
|
@ -474,14 +474,14 @@ func (P *Parser) ParseMethodSpec(list *array.Array) {
|
|||
t = P.ParseFunctionType();
|
||||
}
|
||||
list.Push(AST.NewTypeExpr(t));
|
||||
|
||||
|
||||
P.Ecart();
|
||||
}
|
||||
|
||||
|
||||
func (P *Parser) ParseInterfaceType() *AST.Type {
|
||||
P.Trace("InterfaceType");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.INTERFACE);
|
||||
P.Expect(Scanner.INTERFACE);
|
||||
if P.tok == Scanner.LBRACE {
|
||||
|
|
@ -504,14 +504,14 @@ func (P *Parser) ParseInterfaceType() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseMapType() *AST.Type {
|
||||
P.Trace("MapType");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.MAP);
|
||||
P.Expect(Scanner.MAP);
|
||||
P.Expect(Scanner.LBRACK);
|
||||
t.key = P.ParseVarType();
|
||||
P.Expect(Scanner.RBRACK);
|
||||
t.elt = P.ParseVarType();
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return t;
|
||||
}
|
||||
|
|
@ -551,11 +551,11 @@ func (P *Parser) ParseStructType() *AST.Type {
|
|||
|
||||
func (P *Parser) ParsePointerType() *AST.Type {
|
||||
P.Trace("PointerType");
|
||||
|
||||
|
||||
t := AST.NewType(P.pos, Scanner.MUL);
|
||||
P.Expect(Scanner.MUL);
|
||||
t.elt = P.ParseType();
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return t;
|
||||
}
|
||||
|
|
@ -563,7 +563,7 @@ func (P *Parser) ParsePointerType() *AST.Type {
|
|||
|
||||
func (P *Parser) TryType() *AST.Type {
|
||||
P.Trace("Type (try)");
|
||||
|
||||
|
||||
t := AST.BadType;
|
||||
switch P.tok {
|
||||
case Scanner.IDENT: t = P.ParseTypeName();
|
||||
|
|
@ -587,7 +587,7 @@ func (P *Parser) TryType() *AST.Type {
|
|||
|
||||
func (P *Parser) ParseStatementList() *array.Array {
|
||||
P.Trace("StatementList");
|
||||
|
||||
|
||||
list := array.New(0);
|
||||
for P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE && P.tok != Scanner.EOF {
|
||||
s := P.ParseStatement();
|
||||
|
|
@ -603,7 +603,7 @@ func (P *Parser) ParseStatementList() *array.Array {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Try to provide a good error message
|
||||
if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE && P.tok != Scanner.EOF {
|
||||
P.Error(P.pos, "expected end of statement list (semicolon missing?)");
|
||||
|
|
@ -616,13 +616,13 @@ func (P *Parser) ParseStatementList() *array.Array {
|
|||
|
||||
func (P *Parser) ParseBlock() (slist *array.Array, end int) {
|
||||
P.Trace("Block");
|
||||
|
||||
|
||||
P.Expect(Scanner.LBRACE);
|
||||
slist = P.ParseStatementList();
|
||||
end = P.pos;
|
||||
P.Expect(Scanner.RBRACE);
|
||||
P.opt_semi = true;
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return slist, end;
|
||||
}
|
||||
|
|
@ -654,7 +654,7 @@ func (P *Parser) ParseExpressionList() *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseFunctionLit() *AST.Expr {
|
||||
P.Trace("FunctionLit");
|
||||
|
||||
|
||||
x := AST.NewLit(P.pos, Scanner.FUNC, "");
|
||||
P.Expect(Scanner.FUNC);
|
||||
x.t = P.ParseFunctionType();
|
||||
|
|
@ -663,7 +663,7 @@ func (P *Parser) ParseFunctionLit() *AST.Expr {
|
|||
x.block, x.end = P.ParseBlock();
|
||||
P.scope_lev--;
|
||||
P.expr_lev--;
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -672,7 +672,7 @@ func (P *Parser) ParseFunctionLit() *AST.Expr {
|
|||
/*
|
||||
func (P *Parser) ParseNewCall() *AST.Expr {
|
||||
P.Trace("NewCall");
|
||||
|
||||
|
||||
x := AST.NewExpr(P.pos, Scanner.NEW, nil, nil);
|
||||
P.Next();
|
||||
P.Expect(Scanner.LPAREN);
|
||||
|
|
@ -684,7 +684,7 @@ func (P *Parser) ParseNewCall() *AST.Expr {
|
|||
}
|
||||
P.expr_lev--;
|
||||
P.Expect(Scanner.RPAREN);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -698,9 +698,9 @@ func (P *Parser) ParseOperand() *AST.Expr {
|
|||
switch P.tok {
|
||||
case Scanner.IDENT:
|
||||
x = P.ParseIdent();
|
||||
|
||||
|
||||
case Scanner.LPAREN:
|
||||
// TODO we could have a function type here as in: new(*())
|
||||
// TODO we could have a function type here as in: new(**())
|
||||
// (currently not working)
|
||||
P.Next();
|
||||
P.expr_lev++;
|
||||
|
|
@ -745,16 +745,16 @@ func (P *Parser) ParseSelectorOrTypeGuard(x *AST.Expr) *AST.Expr {
|
|||
|
||||
x = P.NewExpr(P.pos, Scanner.PERIOD, x, nil);
|
||||
P.Expect(Scanner.PERIOD);
|
||||
|
||||
|
||||
if P.tok == Scanner.IDENT {
|
||||
x.y = P.ParseIdent();
|
||||
|
||||
|
||||
} else {
|
||||
P.Expect(Scanner.LPAREN);
|
||||
x.t = P.ParseType();
|
||||
P.Expect(Scanner.RPAREN);
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -762,14 +762,14 @@ func (P *Parser) ParseSelectorOrTypeGuard(x *AST.Expr) *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseIndex(x *AST.Expr) *AST.Expr {
|
||||
P.Trace("IndexOrSlice");
|
||||
|
||||
|
||||
pos := P.pos;
|
||||
P.Expect(Scanner.LBRACK);
|
||||
P.expr_lev++;
|
||||
i := P.ParseExpression(0);
|
||||
P.expr_lev--;
|
||||
P.Expect(Scanner.RBRACK);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return P.NewExpr(pos, Scanner.LBRACK, x, i);
|
||||
}
|
||||
|
|
@ -786,7 +786,7 @@ func (P *Parser) ParseCall(x0 *AST.Expr) *AST.Expr {
|
|||
P.expr_lev++;
|
||||
var t *AST.Type;
|
||||
if x0.tok == Scanner.IDENT && x0.s == "new" {
|
||||
// heuristic: assume it's a new(T, ...) call, try to parse a type
|
||||
// heuristic: assume it's a new(*T, ...) call, try to parse a type
|
||||
t = P.TryType();
|
||||
}
|
||||
if t != nil {
|
||||
|
|
@ -808,7 +808,7 @@ func (P *Parser) ParseCall(x0 *AST.Expr) *AST.Expr {
|
|||
P.expr_lev--;
|
||||
}
|
||||
P.Expect(Scanner.RPAREN);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -819,13 +819,13 @@ func (P *Parser) ParseCompositeElements() *AST.Expr {
|
|||
if P.tok == Scanner.COMMA {
|
||||
pos := P.pos;
|
||||
P.Next();
|
||||
|
||||
|
||||
// first element determines mode
|
||||
singles := true;
|
||||
if x.tok == Scanner.COLON {
|
||||
singles = false;
|
||||
}
|
||||
|
||||
|
||||
for first := true; P.tok != Scanner.RBRACE && P.tok != Scanner.EOF; {
|
||||
y := P.ParseExpression(0);
|
||||
|
||||
|
|
@ -838,13 +838,13 @@ func (P *Parser) ParseCompositeElements() *AST.Expr {
|
|||
P.Error(y.pos, "key:value pair expected; found single value");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if first {
|
||||
x = P.NewExpr(pos, Scanner.COMMA, x, y);
|
||||
} else {
|
||||
x.y = P.NewExpr(pos, Scanner.COMMA, x.y, y);
|
||||
}
|
||||
|
||||
|
||||
if P.tok == Scanner.COMMA {
|
||||
pos = P.pos;
|
||||
P.Next();
|
||||
|
|
@ -860,7 +860,7 @@ func (P *Parser) ParseCompositeElements() *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr {
|
||||
P.Trace("CompositeLit");
|
||||
|
||||
|
||||
x := P.NewExpr(P.pos, Scanner.LBRACE, nil, nil);
|
||||
x.t = t;
|
||||
P.Expect(Scanner.LBRACE);
|
||||
|
|
@ -868,7 +868,7 @@ func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr {
|
|||
x.y = P.ParseCompositeElements();
|
||||
}
|
||||
P.Expect(Scanner.RBRACE);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -876,7 +876,7 @@ func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr {
|
|||
|
||||
func (P *Parser) ParsePrimaryExpr() *AST.Expr {
|
||||
P.Trace("PrimaryExpr");
|
||||
|
||||
|
||||
x := P.ParseOperand();
|
||||
for {
|
||||
switch P.tok {
|
||||
|
|
@ -899,7 +899,7 @@ func (P *Parser) ParsePrimaryExpr() *AST.Expr {
|
|||
default: goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
exit:
|
||||
P.Ecart();
|
||||
return x;
|
||||
|
|
@ -908,7 +908,7 @@ exit:
|
|||
|
||||
func (P *Parser) ParseUnaryExpr() *AST.Expr {
|
||||
P.Trace("UnaryExpr");
|
||||
|
||||
|
||||
x := AST.BadExpr;
|
||||
switch P.tok {
|
||||
case Scanner.ADD, Scanner.SUB, Scanner.MUL, Scanner.NOT, Scanner.XOR, Scanner.ARROW, Scanner.AND:
|
||||
|
|
@ -923,11 +923,11 @@ func (P *Parser) ParseUnaryExpr() *AST.Expr {
|
|||
} else {
|
||||
x = P.NewExpr(pos, tok, nil, y);
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
x = P.ParsePrimaryExpr();
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -935,7 +935,7 @@ func (P *Parser) ParseUnaryExpr() *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseBinaryExpr(prec1 int) *AST.Expr {
|
||||
P.Trace("BinaryExpr");
|
||||
|
||||
|
||||
x := P.ParseUnaryExpr();
|
||||
for prec := Scanner.Precedence(P.tok); prec >= prec1; prec-- {
|
||||
for Scanner.Precedence(P.tok) == prec {
|
||||
|
|
@ -945,7 +945,7 @@ func (P *Parser) ParseBinaryExpr(prec1 int) *AST.Expr {
|
|||
x = P.NewExpr(pos, tok, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return x;
|
||||
}
|
||||
|
|
@ -973,10 +973,10 @@ func (P *Parser) ParseExpression(prec int) *AST.Expr {
|
|||
|
||||
func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat {
|
||||
P.Trace("SimpleStat");
|
||||
|
||||
|
||||
s := AST.BadStat;
|
||||
x := P.ParseExpressionList();
|
||||
|
||||
|
||||
is_range := false;
|
||||
if range_ok && P.tok == Scanner.COLON {
|
||||
pos := P.pos;
|
||||
|
|
@ -989,7 +989,7 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat {
|
|||
P.Error(pos, "expected initialization, found ':'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch P.tok {
|
||||
case Scanner.COLON:
|
||||
// label declaration
|
||||
|
|
@ -1052,7 +1052,7 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat {
|
|||
P.Error(x.pos, "only one expression allowed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1060,11 +1060,11 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseGoStat() *AST.Stat {
|
||||
P.Trace("GoStat");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, Scanner.GO);
|
||||
P.Expect(Scanner.GO);
|
||||
s.expr = P.ParseExpression(1);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1072,13 +1072,13 @@ func (P *Parser) ParseGoStat() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseReturnStat() *AST.Stat {
|
||||
P.Trace("ReturnStat");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, Scanner.RETURN);
|
||||
P.Expect(Scanner.RETURN);
|
||||
if P.tok != Scanner.SEMICOLON && P.tok != Scanner.RBRACE {
|
||||
s.expr = P.ParseExpressionList();
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1086,13 +1086,13 @@ func (P *Parser) ParseReturnStat() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseControlFlowStat(tok int) *AST.Stat {
|
||||
P.Trace("ControlFlowStat");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, tok);
|
||||
P.Expect(tok);
|
||||
if tok != Scanner.FALLTHROUGH && P.tok == Scanner.IDENT {
|
||||
s.expr = P.ParseIdent();
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1100,7 +1100,7 @@ func (P *Parser) ParseControlFlowStat(tok int) *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseControlClause(keyword int) *AST.Stat {
|
||||
P.Trace("ControlClause");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, keyword);
|
||||
P.Expect(keyword);
|
||||
if P.tok != Scanner.LBRACE {
|
||||
|
|
@ -1163,7 +1163,7 @@ func (P *Parser) ParseIfStat() *AST.Stat {
|
|||
}
|
||||
s.post = s1;
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1171,10 +1171,10 @@ func (P *Parser) ParseIfStat() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseForStat() *AST.Stat {
|
||||
P.Trace("ForStat");
|
||||
|
||||
|
||||
s := P.ParseControlClause(Scanner.FOR);
|
||||
s.block, s.end = P.ParseBlock();
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1182,7 +1182,7 @@ func (P *Parser) ParseForStat() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseCase() *AST.Stat {
|
||||
P.Trace("Case");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, P.tok);
|
||||
if P.tok == Scanner.CASE {
|
||||
P.Next();
|
||||
|
|
@ -1191,7 +1191,7 @@ func (P *Parser) ParseCase() *AST.Stat {
|
|||
P.Expect(Scanner.DEFAULT);
|
||||
}
|
||||
P.Expect(Scanner.COLON);
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1204,7 +1204,7 @@ func (P *Parser) ParseCaseClause() *AST.Stat {
|
|||
if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE {
|
||||
s.block = P.ParseStatementList();
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1212,7 +1212,7 @@ func (P *Parser) ParseCaseClause() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseSwitchStat() *AST.Stat {
|
||||
P.Trace("SwitchStat");
|
||||
|
||||
|
||||
s := P.ParseControlClause(Scanner.SWITCH);
|
||||
s.block = array.New(0);
|
||||
P.Expect(Scanner.LBRACE);
|
||||
|
|
@ -1258,12 +1258,12 @@ func (P *Parser) ParseCommCase() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseCommClause() *AST.Stat {
|
||||
P.Trace("CommClause");
|
||||
|
||||
|
||||
s := P.ParseCommCase();
|
||||
if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE {
|
||||
s.block = P.ParseStatementList();
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1271,7 +1271,7 @@ func (P *Parser) ParseCommClause() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseSelectStat() *AST.Stat {
|
||||
P.Trace("SelectStat");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, Scanner.SELECT);
|
||||
s.block = array.New(0);
|
||||
P.Expect(Scanner.SELECT);
|
||||
|
|
@ -1281,7 +1281,7 @@ func (P *Parser) ParseSelectStat() *AST.Stat {
|
|||
}
|
||||
P.Expect(Scanner.RBRACE);
|
||||
P.opt_semi = true;
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1289,14 +1289,14 @@ func (P *Parser) ParseSelectStat() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseRangeStat() *AST.Stat {
|
||||
P.Trace("RangeStat");
|
||||
|
||||
|
||||
s := AST.NewStat(P.pos, Scanner.RANGE);
|
||||
P.Expect(Scanner.RANGE);
|
||||
P.ParseIdentList();
|
||||
P.Expect(Scanner.DEFINE);
|
||||
s.expr = P.ParseExpression(1);
|
||||
s.block, s.end = P.ParseBlock();
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return s;
|
||||
}
|
||||
|
|
@ -1358,7 +1358,7 @@ func (P *Parser) ParseStatement() *AST.Stat {
|
|||
|
||||
func (P *Parser) ParseImportSpec(pos int) *AST.Decl {
|
||||
P.Trace("ImportSpec");
|
||||
|
||||
|
||||
d := AST.NewDecl(pos, Scanner.IMPORT, false);
|
||||
if P.tok == Scanner.PERIOD {
|
||||
P.Error(P.pos, `"import ." not yet handled properly`);
|
||||
|
|
@ -1366,7 +1366,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl {
|
|||
} else if P.tok == Scanner.IDENT {
|
||||
d.ident = P.ParseIdent();
|
||||
}
|
||||
|
||||
|
||||
if P.tok == Scanner.STRING {
|
||||
// TODO eventually the scanner should strip the quotes
|
||||
d.val = AST.NewLit(P.pos, Scanner.STRING, P.val);
|
||||
|
|
@ -1374,7 +1374,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl {
|
|||
} else {
|
||||
P.Expect(Scanner.STRING); // use Expect() error handling
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
|
@ -1382,7 +1382,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl {
|
|||
|
||||
func (P *Parser) ParseConstSpec(exported bool, pos int) *AST.Decl {
|
||||
P.Trace("ConstSpec");
|
||||
|
||||
|
||||
d := AST.NewDecl(pos, Scanner.CONST, exported);
|
||||
d.ident = P.ParseIdentList();
|
||||
d.typ = P.TryType();
|
||||
|
|
@ -1390,7 +1390,7 @@ func (P *Parser) ParseConstSpec(exported bool, pos int) *AST.Decl {
|
|||
P.Next();
|
||||
d.val = P.ParseExpressionList();
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
|
@ -1403,7 +1403,7 @@ func (P *Parser) ParseTypeSpec(exported bool, pos int) *AST.Decl {
|
|||
d.ident = P.ParseIdent();
|
||||
d.typ = P.ParseType();
|
||||
P.opt_semi = true;
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
|
@ -1411,7 +1411,7 @@ func (P *Parser) ParseTypeSpec(exported bool, pos int) *AST.Decl {
|
|||
|
||||
func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl {
|
||||
P.Trace("VarSpec");
|
||||
|
||||
|
||||
d := AST.NewDecl(pos, Scanner.VAR, exported);
|
||||
d.ident = P.ParseIdentList();
|
||||
if P.tok == Scanner.ASSIGN {
|
||||
|
|
@ -1424,7 +1424,7 @@ func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl {
|
|||
d.val = P.ParseExpressionList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
|
@ -1445,7 +1445,7 @@ func (P *Parser) ParseSpec(exported bool, pos int, keyword int) *AST.Decl {
|
|||
|
||||
func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl {
|
||||
P.Trace("Decl");
|
||||
|
||||
|
||||
d := AST.BadDecl;
|
||||
pos := P.pos;
|
||||
P.Expect(keyword);
|
||||
|
|
@ -1464,11 +1464,11 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl {
|
|||
d.end = P.pos;
|
||||
P.Expect(Scanner.RPAREN);
|
||||
P.opt_semi = true;
|
||||
|
||||
|
||||
} else {
|
||||
d = P.ParseSpec(exported, pos, keyword);
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
|
@ -1485,10 +1485,10 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl {
|
|||
|
||||
func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl {
|
||||
P.Trace("FunctionDecl");
|
||||
|
||||
|
||||
d := AST.NewDecl(P.pos, Scanner.FUNC, exported);
|
||||
P.Expect(Scanner.FUNC);
|
||||
|
||||
|
||||
var recv *AST.Type;
|
||||
if P.tok == Scanner.LPAREN {
|
||||
pos := P.pos;
|
||||
|
|
@ -1497,7 +1497,7 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl {
|
|||
P.Error(pos, "must have exactly one receiver");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
d.ident = P.ParseIdent();
|
||||
d.typ = P.ParseFunctionType();
|
||||
d.typ.key = recv;
|
||||
|
|
@ -1507,7 +1507,7 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl {
|
|||
d.list, d.end = P.ParseBlock();
|
||||
P.scope_lev--;
|
||||
}
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
|
@ -1515,7 +1515,7 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl {
|
|||
|
||||
func (P *Parser) ParseExportDecl() *AST.Decl {
|
||||
P.Trace("ExportDecl");
|
||||
|
||||
|
||||
d := AST.NewDecl(P.pos, Scanner.EXPORT, false);
|
||||
d.ident = P.ParseIdentList();
|
||||
|
||||
|
|
@ -1527,7 +1527,7 @@ func (P *Parser) ParseExportDecl() *AST.Decl {
|
|||
func (P *Parser) ParseDeclaration() *AST.Decl {
|
||||
P.Trace("Declaration");
|
||||
indent := P.indent;
|
||||
|
||||
|
||||
d := AST.BadDecl;
|
||||
exported := false;
|
||||
// TODO don't use bool flag for export
|
||||
|
|
@ -1539,7 +1539,7 @@ func (P *Parser) ParseDeclaration() *AST.Decl {
|
|||
}
|
||||
P.Next();
|
||||
}
|
||||
|
||||
|
||||
switch P.tok {
|
||||
case Scanner.CONST, Scanner.TYPE, Scanner.VAR:
|
||||
d = P.ParseDecl(exported, P.tok);
|
||||
|
|
@ -1573,26 +1573,26 @@ func (P *Parser) ParseDeclaration() *AST.Decl {
|
|||
|
||||
func (P *Parser) ParseProgram() *AST.Program {
|
||||
P.Trace("Program");
|
||||
|
||||
|
||||
p := AST.NewProgram(P.pos);
|
||||
P.Expect(Scanner.PACKAGE);
|
||||
p.ident = P.ParseIdent();
|
||||
|
||||
|
||||
p.decls = array.New(0);
|
||||
for P.tok == Scanner.IMPORT {
|
||||
p.decls.Push(P.ParseDecl(false, Scanner.IMPORT));
|
||||
P.OptSemicolon();
|
||||
}
|
||||
|
||||
|
||||
if !P.deps {
|
||||
for P.tok != Scanner.EOF {
|
||||
p.decls.Push(P.ParseDeclaration());
|
||||
P.OptSemicolon();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
p.comments = P.comments;
|
||||
|
||||
|
||||
P.Ecart();
|
||||
return p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ export const (
|
|||
MUL;
|
||||
QUO;
|
||||
REM;
|
||||
|
||||
|
||||
AND;
|
||||
OR;
|
||||
XOR;
|
||||
SHL;
|
||||
SHR;
|
||||
|
||||
|
||||
ADD_ASSIGN;
|
||||
SUB_ASSIGN;
|
||||
MUL_ASSIGN;
|
||||
|
|
@ -48,7 +48,7 @@ export const (
|
|||
ARROW;
|
||||
INC;
|
||||
DEC;
|
||||
|
||||
|
||||
EQL;
|
||||
NEQ;
|
||||
LSS;
|
||||
|
|
@ -60,14 +60,14 @@ export const (
|
|||
DEFINE;
|
||||
NOT;
|
||||
ELLIPSIS;
|
||||
|
||||
|
||||
LPAREN;
|
||||
RPAREN;
|
||||
LBRACK;
|
||||
RBRACK;
|
||||
LBRACE;
|
||||
RBRACE;
|
||||
|
||||
|
||||
COMMA;
|
||||
SEMICOLON;
|
||||
COLON;
|
||||
|
|
@ -80,32 +80,32 @@ export const (
|
|||
CHAN;
|
||||
CONST;
|
||||
CONTINUE;
|
||||
|
||||
|
||||
DEFAULT;
|
||||
ELSE;
|
||||
EXPORT;
|
||||
FALLTHROUGH;
|
||||
FOR;
|
||||
|
||||
|
||||
FUNC;
|
||||
GO;
|
||||
GOTO;
|
||||
IF;
|
||||
IMPORT;
|
||||
|
||||
|
||||
INTERFACE;
|
||||
MAP;
|
||||
PACKAGE;
|
||||
RANGE;
|
||||
RETURN;
|
||||
|
||||
|
||||
SELECT;
|
||||
STRUCT;
|
||||
SWITCH;
|
||||
TYPE;
|
||||
VAR;
|
||||
KEYWORDS_END;
|
||||
|
||||
|
||||
// AST use only
|
||||
EXPRSTAT;
|
||||
)
|
||||
|
|
@ -114,7 +114,7 @@ export const (
|
|||
export func TokenString(tok int) string {
|
||||
switch tok {
|
||||
case ILLEGAL: return "ILLEGAL";
|
||||
|
||||
|
||||
case IDENT: return "IDENT";
|
||||
case INT: return "INT";
|
||||
case FLOAT: return "FLOAT";
|
||||
|
|
@ -128,13 +128,13 @@ export func TokenString(tok int) string {
|
|||
case MUL: return "*";
|
||||
case QUO: return "/";
|
||||
case REM: return "%";
|
||||
|
||||
|
||||
case AND: return "&";
|
||||
case OR: return "|";
|
||||
case XOR: return "^";
|
||||
case SHL: return "<<";
|
||||
case SHR: return ">>";
|
||||
|
||||
|
||||
case ADD_ASSIGN: return "+=";
|
||||
case SUB_ASSIGN: return "-=";
|
||||
case MUL_ASSIGN: return "+=";
|
||||
|
|
@ -206,10 +206,10 @@ export func TokenString(tok int) string {
|
|||
case SWITCH: return "switch";
|
||||
case TYPE: return "type";
|
||||
case VAR: return "var";
|
||||
|
||||
|
||||
case EXPRSTAT: return "EXPRSTAT";
|
||||
}
|
||||
|
||||
|
||||
return "token(" + Utils.IntToString(tok, 10) + ")";
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ export func Precedence(tok int) int {
|
|||
}
|
||||
|
||||
|
||||
var Keywords *map [string] int;
|
||||
var Keywords map [string] int;
|
||||
|
||||
|
||||
func init() {
|
||||
|
|
@ -325,7 +325,7 @@ func (S *Scanner) Error(pos int, msg string) {
|
|||
S.testpos = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
S.err.Error(pos, msg);
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +397,7 @@ func (S *Scanner) SkipWhitespace() {
|
|||
func (S *Scanner) ScanComment() string {
|
||||
// first '/' already consumed
|
||||
pos := S.chpos - 1;
|
||||
|
||||
|
||||
if S.ch == '/' {
|
||||
//-style comment
|
||||
S.Next();
|
||||
|
|
@ -410,7 +410,7 @@ func (S *Scanner) ScanComment() string {
|
|||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
/*-style comment */
|
||||
S.Expect('*');
|
||||
|
|
@ -423,7 +423,7 @@ func (S *Scanner) ScanComment() string {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
S.Error(pos, "comment not terminated");
|
||||
|
||||
exit:
|
||||
|
|
@ -443,7 +443,7 @@ exit:
|
|||
oldpos = S.testpos;
|
||||
S.ExpectNoErrors();
|
||||
}
|
||||
|
||||
|
||||
if 0 <= oldpos && oldpos <= len(S.src) {
|
||||
// the previous error was not found
|
||||
S.Error(oldpos, "ERROR not found"); // TODO this should call ErrorMsg
|
||||
|
|
@ -460,13 +460,13 @@ func (S *Scanner) ScanIdentifier() (tok int, val string) {
|
|||
S.Next();
|
||||
}
|
||||
val = S.src[pos : S.chpos];
|
||||
|
||||
|
||||
var present bool;
|
||||
tok, present = Keywords[val];
|
||||
if !present {
|
||||
tok = IDENT;
|
||||
}
|
||||
|
||||
|
||||
return tok, val;
|
||||
}
|
||||
|
||||
|
|
@ -481,14 +481,14 @@ func (S *Scanner) ScanMantissa(base int) {
|
|||
func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) {
|
||||
pos := S.chpos;
|
||||
tok = INT;
|
||||
|
||||
|
||||
if seen_decimal_point {
|
||||
tok = FLOAT;
|
||||
pos--; // '.' is one byte
|
||||
S.ScanMantissa(10);
|
||||
goto exponent;
|
||||
}
|
||||
|
||||
|
||||
if S.ch == '0' {
|
||||
// int or float
|
||||
S.Next();
|
||||
|
|
@ -508,18 +508,18 @@ func (S *Scanner) ScanNumber(seen_decimal_point bool) (tok int, val string) {
|
|||
}
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
mantissa:
|
||||
// decimal int or float
|
||||
S.ScanMantissa(10);
|
||||
|
||||
|
||||
if S.ch == '.' {
|
||||
// float
|
||||
tok = FLOAT;
|
||||
S.Next();
|
||||
S.ScanMantissa(10)
|
||||
}
|
||||
|
||||
|
||||
exponent:
|
||||
if S.ch == 'e' || S.ch == 'E' {
|
||||
// float
|
||||
|
|
@ -530,7 +530,7 @@ exponent:
|
|||
}
|
||||
S.ScanMantissa(10);
|
||||
}
|
||||
|
||||
|
||||
exit:
|
||||
return tok, S.src[pos : S.chpos];
|
||||
}
|
||||
|
|
@ -549,22 +549,22 @@ func (S *Scanner) ScanDigits(n int, base int) {
|
|||
|
||||
func (S *Scanner) ScanEscape(quote int) string {
|
||||
// TODO: fix this routine
|
||||
|
||||
|
||||
ch := S.ch;
|
||||
pos := S.chpos;
|
||||
S.Next();
|
||||
switch ch {
|
||||
case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\':
|
||||
return string(ch);
|
||||
|
||||
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7':
|
||||
S.ScanDigits(3 - 1, 8); // 1 char already read
|
||||
return ""; // TODO fix this
|
||||
|
||||
|
||||
case 'x':
|
||||
S.ScanDigits(2, 16);
|
||||
return ""; // TODO fix this
|
||||
|
||||
|
||||
case 'u':
|
||||
S.ScanDigits(4, 16);
|
||||
return ""; // TODO fix this
|
||||
|
|
@ -580,7 +580,7 @@ func (S *Scanner) ScanEscape(quote int) string {
|
|||
}
|
||||
S.Error(pos, "illegal char escape");
|
||||
}
|
||||
|
||||
|
||||
return ""; // TODO fix this
|
||||
}
|
||||
|
||||
|
|
@ -615,7 +615,7 @@ func (S *Scanner) ScanString() string {
|
|||
S.ScanEscape('"');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
S.Next();
|
||||
return S.src[pos : S.chpos];
|
||||
}
|
||||
|
|
@ -680,9 +680,9 @@ func (S *Scanner) Select4(tok0, tok1, ch2, tok2, tok3 int) int {
|
|||
|
||||
func (S *Scanner) Scan() (pos, tok int, val string) {
|
||||
L: S.SkipWhitespace();
|
||||
|
||||
|
||||
pos, tok = S.chpos, ILLEGAL;
|
||||
|
||||
|
||||
switch ch := S.ch; {
|
||||
case is_letter(ch): tok, val = S.ScanIdentifier();
|
||||
case digit_val(ch) < 10: tok, val = S.ScanNumber(false);
|
||||
|
|
@ -746,7 +746,7 @@ L: S.SkipWhitespace();
|
|||
tok = ILLEGAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return pos, tok, val;
|
||||
}
|
||||
|
||||
|
|
@ -758,11 +758,11 @@ export type Token struct {
|
|||
}
|
||||
|
||||
|
||||
func (S *Scanner) TokenStream() *<-chan *Token {
|
||||
func (S *Scanner) TokenStream() <-chan *Token {
|
||||
ch := new(chan *Token, 100);
|
||||
go func(S *Scanner, ch *chan <- *Token) {
|
||||
go func(S *Scanner, ch chan <- *Token) {
|
||||
for {
|
||||
t := new(Token);
|
||||
t := new(*Token);
|
||||
t.pos, t.tok, t.val = S.Scan();
|
||||
ch <- t;
|
||||
if t.tok == EOF {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func f2(tag int) {
|
|||
}
|
||||
|
||||
|
||||
func f3(a *[]int, m *map[string] int) {
|
||||
func f3(a *[]int, m map[string] int) {
|
||||
println("A1");
|
||||
for i := range a {
|
||||
println(i);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue