summaryrefslogtreecommitdiff
path: root/usr/gri/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/gri/src')
-rw-r--r--usr/gri/src/globals.go66
-rwxr-xr-xusr/gri/src/object.go29
-rw-r--r--usr/gri/src/parser.go1058
-rw-r--r--usr/gri/src/scanner.go777
-rw-r--r--usr/gri/src/scope.go14
-rw-r--r--usr/gri/src/test_parser.go42
-rw-r--r--usr/gri/src/test_scanner.go35
-rw-r--r--usr/gri/src/type.go33
8 files changed, 0 insertions, 2054 deletions
diff --git a/usr/gri/src/globals.go b/usr/gri/src/globals.go
deleted file mode 100644
index f8d0c116b..000000000
--- a/usr/gri/src/globals.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package Globals;
-
-
-// The following types should really be in their respective files
-// object.go, type.go, and scope.go but they refer to each other
-// and we don't know how to handle forward-declared pointers across
-// packages yet.
-
-
-// ----------------------------------------------------------------------------
-
-export Object
-type Object struct {
- mark bool; // mark => object marked for export
- kind int;
- name string;
- type_ *Type;
- pnolev int; // >= 0: package no., <= 0: level, 0: global level of compilation
-}
-
-
-// ----------------------------------------------------------------------------
-
-export Type
-type Type struct {
- ref int; // for exporting only: >= 0 means already exported
- form int;
- flags int; // channels, functions
- size int; // in bytes
- len_ int; // array length, no. of parameters (w/o recv)
- obj *Object; // primary type object or NULL
- key *Object; // maps
- elt *Object; // arrays, maps, channels, pointers, references
- scope *Scope; // incomplete types, structs, interfaces, functions, packages
-}
-
-
-// ----------------------------------------------------------------------------
-
-export Scope
-type Scope struct {
- parent *Scope;
- // list ObjList
-
-}
-
-
-func (scope *Scope) Lookup(ident string) *Object {
- panic "UNIMPLEMENTED";
- return nil;
-}
-
-
-func (scope *Scope) Insert(obj *Object) {
- panic "UNIMPLEMENTED";
-}
-
-
-func (scope *Scope) InsertImport(obj *Object) *Object {
- panic "UNIMPLEMENTED";
- return nil;
-}
diff --git a/usr/gri/src/object.go b/usr/gri/src/object.go
deleted file mode 100755
index cf1a432aa..000000000
--- a/usr/gri/src/object.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package Object
-
-import Globals "globals"
-
-
-export BAD, CONST, TYPE, VAR, FUNC, PACKAGE
-const /* kind */ (
- BAD = iota; // error handling
- CONST; TYPE; VAR; FUNC; PACKAGE;
- PTYPE; // primary type (import/export only)
-)
-
-
-type Object Globals.Object
-
-
-func NewObject(kind int, name string) *Object {
- obj := new(Object);
- obj.mark = false;
- obj.kind = kind;
- obj.name = name;
- obj.type_ = nil; // Universe::undef_t;
- obj.pnolev = 0;
- return obj;
-}
diff --git a/usr/gri/src/parser.go b/usr/gri/src/parser.go
deleted file mode 100644
index 49b0f6ab2..000000000
--- a/usr/gri/src/parser.go
+++ /dev/null
@@ -1,1058 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package Parser
-
-import Scanner "scanner"
-
-
-export Parser
-type Parser struct {
- verbose, indent int;
- S *Scanner.Scanner;
- tok int; // one token look-ahead
- beg, end int; // token position
- ident string; // last ident seen
-}
-
-
-func (P *Parser) PrintIndent() {
- for i := P.indent; i > 0; i-- {
- print ". ";
- }
-}
-
-
-func (P *Parser) Trace(msg string) {
- if P.verbose > 0 {
- P.PrintIndent();
- print msg, " {\n";
- P.indent++;
- }
-}
-
-
-func (P *Parser) Ecart() {
- if P.verbose > 0 {
- P.indent--;
- P.PrintIndent();
- print "}\n";
- }
-}
-
-
-func (P *Parser) Next() {
- P.tok, P.beg, P.end = P.S.Scan();
- if P.tok == Scanner.IDENT {
- P.ident = P.S.src[P.beg : P.end];
- }
- if P.verbose > 1 {
- P.PrintIndent();
- print Scanner.TokenName(P.tok), "\n";
- }
-}
-
-
-func (P *Parser) Open(S *Scanner.Scanner, verbose int) {
- P.verbose = verbose;
- P.indent = 0;
- P.S = S;
- P.Next();
-}
-
-
-func (P *Parser) Error(pos int, msg string) {
- P.S.Error(pos, msg);
- P.Next(); // make progress
-}
-
-
-func (P *Parser) Expect(tok int) {
- if P.tok == tok {
- P.Next()
- } else {
- P.Error(P.beg, "expected '" + Scanner.TokenName(tok) + "', found '" + Scanner.TokenName(P.tok) + "'");
- }
-}
-
-
-func (P *Parser) Optional(tok int) {
- if P.tok == tok {
- P.Next();
- }
-}
-
-
-func (P *Parser) TryType() bool;
-func (P *Parser) ParseExpression();
-
-
-func (P *Parser) ParseIdent() {
- if P.verbose > 0 {
- P.PrintIndent();
- print "Ident = \"", P.ident, "\"\n";
- }
- P.Expect(Scanner.IDENT);
-}
-
-
-func (P *Parser) ParseIdentList() {
- P.Trace("IdentList");
- P.ParseIdent();
- for P.tok == Scanner.COMMA {
- P.Next();
- P.ParseIdent();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseQualifiedIdent() {
- P.Trace("QualifiedIdent");
- P.ParseIdent();
- if P.tok == Scanner.PERIOD {
- P.Next();
- P.ParseIdent();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseTypeName() {
- P.Trace("TypeName");
- P.ParseQualifiedIdent();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseType() {
- P.Trace("Type");
- if !P.TryType() {
- P.Error(P.beg, "type expected");
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseArrayType() {
- P.Trace("ArrayType");
- P.Expect(Scanner.LBRACK);
- if P.tok != Scanner.RBRACK {
- P.ParseExpression();
- }
- P.Expect(Scanner.RBRACK);
- P.ParseType();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseChannelType() {
- P.Trace("ChannelType");
- P.Expect(Scanner.CHAN);
- switch P.tok {
- case Scanner.LSS: fallthrough
- case Scanner.GTR:
- P.Next();
- }
- P.ParseType();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseParameters();
-func (P *Parser) TryResult() bool;
-
-
-func (P *Parser) ParseMethodDecl() {
- P.Trace("MethodDecl");
- P.ParseIdent();
- P.ParseParameters();
- P.TryResult();
- P.Optional(Scanner.SEMICOLON);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseInterfaceType() {
- P.Trace("InterfaceType");
- P.Expect(Scanner.INTERFACE);
- P.Expect(Scanner.LBRACE);
- for P.tok != Scanner.RBRACE {
- P.ParseMethodDecl();
- }
- P.Next();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseAnonymousSignature();
-
-
-func (P *Parser) ParseFunctionType() {
- P.Trace("FunctionType");
- P.Expect(Scanner.FUNC);
- P.ParseAnonymousSignature();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseMapType() {
- P.Trace("MapType");
- P.Expect(Scanner.MAP);
- P.Expect(Scanner.LBRACK);
- P.ParseType();
- P.Expect(Scanner.RBRACK);
- P.ParseType();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseFieldDecl() {
- P.Trace("FieldDecl");
- P.ParseIdentList();
- P.ParseType();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseStructType() {
- P.Trace("StructType");
- P.Expect(Scanner.STRUCT);
- P.Expect(Scanner.LBRACE);
- for P.tok != Scanner.RBRACE {
- P.ParseFieldDecl();
- if P.tok != Scanner.RBRACE {
- P.Expect(Scanner.SEMICOLON);
- }
- }
- P.Optional(Scanner.SEMICOLON);
- P.Expect(Scanner.RBRACE);
- P.Ecart();
-}
-
-
-func (P *Parser) ParsePointerType() {
- P.Trace("PointerType");
- P.Expect(Scanner.MUL);
- P.ParseType();
- P.Ecart();
-}
-
-
-func (P *Parser) TryType() bool {
- P.Trace("Type (try)");
- switch P.tok {
- case Scanner.IDENT:
- P.ParseTypeName();
- case Scanner.LBRACK:
- P.ParseArrayType();
- case Scanner.CHAN:
- P.ParseChannelType();
- case Scanner.INTERFACE:
- P.ParseInterfaceType();
- case Scanner.FUNC:
- P.ParseFunctionType();
- case Scanner.MAP:
- P.ParseMapType();
- case Scanner.STRUCT:
- P.ParseStructType();
- case Scanner.MUL:
- P.ParsePointerType();
- default:
- P.Ecart();
- return false;
- }
- P.Ecart();
- return true;
-}
-
-
-func (P *Parser) ParseImportSpec() {
- P.Trace("ImportSpec");
- if P.tok == Scanner.PERIOD {
- P.Next();
- } else if P.tok == Scanner.IDENT {
- P.Next();
- }
- P.Expect(Scanner.STRING);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseImportDecl() {
- P.Trace("ImportDecl");
- P.Expect(Scanner.IMPORT);
- if P.tok == Scanner.LPAREN {
- P.Next();
- for P.tok != Scanner.RPAREN {
- P.ParseImportSpec();
- P.Optional(Scanner.SEMICOLON); // TODO this seems wrong
- }
- P.Next();
- } else {
- P.ParseImportSpec();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseExpressionList() {
- P.Trace("ExpressionList");
- P.ParseExpression();
- for P.tok == Scanner.COMMA {
- P.Next();
- P.ParseExpression();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseConstSpec() {
- P.Trace("ConstSpec");
- P.ParseIdent();
- P.TryType();
- if P.tok == Scanner.ASSIGN {
- P.Next();
- P.ParseExpression();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseConstDecl() {
- P.Trace("ConstDecl");
- P.Expect(Scanner.CONST);
- if P.tok == Scanner.LPAREN {
- P.Next();
- for P.tok != Scanner.RPAREN {
- P.ParseConstSpec();
- if P.tok != Scanner.RPAREN {
- P.Expect(Scanner.SEMICOLON);
- }
- }
- P.Next();
- } else {
- P.ParseConstSpec();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseTypeSpec() {
- P.Trace("TypeSpec");
- P.ParseIdent();
- P.TryType();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseTypeDecl() {
- P.Trace("TypeDecl");
- P.Expect(Scanner.TYPE);
- if P.tok == Scanner.LPAREN {
- P.Next();
- for P.tok != Scanner.RPAREN {
- P.ParseTypeSpec();
- if P.tok != Scanner.RPAREN {
- P.Expect(Scanner.SEMICOLON);
- }
- }
- P.Next();
- } else {
- P.ParseTypeSpec();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseVarSpec() {
- P.Trace("VarSpec");
- P.ParseIdentList();
- if P.tok == Scanner.ASSIGN {
- P.Next();
- P.ParseExpressionList();
- } else {
- P.ParseType();
- if P.tok == Scanner.ASSIGN {
- P.Next();
- P.ParseExpressionList();
- }
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseVarDecl() {
- P.Trace("VarDecl");
- P.Expect(Scanner.VAR);
- if P.tok == Scanner.LPAREN {
- P.Next();
- for P.tok != Scanner.RPAREN {
- P.ParseVarSpec();
- if P.tok != Scanner.RPAREN {
- P.Expect(Scanner.SEMICOLON);
- }
- }
- P.Next();
- } else {
- P.ParseVarSpec();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseParameterSection() {
- P.Trace("ParameterSection");
- P.ParseIdentList();
- P.ParseType();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseParameterList() {
- P.Trace("ParameterList");
- P.ParseParameterSection();
- for P.tok == Scanner.COMMA {
- P.Next();
- P.ParseParameterSection();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseParameters() {
- P.Trace("Parameters");
- P.Expect(Scanner.LPAREN);
- if P.tok != Scanner.RPAREN {
- P.ParseParameterList();
- }
- P.Expect(Scanner.RPAREN);
- P.Ecart();
-}
-
-
-func (P *Parser) TryResult() bool {
- P.Trace("Result (try)");
- res := false;
- if P.tok == Scanner.LPAREN {
- // TODO: here we allow empty returns - should proably fix this
- P.ParseParameters();
- res = true;
- } else {
- res = P.TryType();
- }
- P.Ecart();
- return res;
-}
-
-
-// Anonymous signatures
-//
-// (params)
-// (params) type
-// (params) (results)
-// (recv) . (params)
-// (recv) . (params) type
-// (recv) . (params) (results)
-
-func (P *Parser) ParseAnonymousSignature() {
- P.Trace("AnonymousSignature");
- P.ParseParameters();
- if P.tok == Scanner.PERIOD {
- P.Next();
- P.ParseParameters();
- }
- P.TryResult();
- P.Ecart();
-}
-
-
-// Named signatures
-//
-// name (params)
-// name (params) type
-// name (params) (results)
-// (recv) name (params)
-// (recv) name (params) type
-// (recv) name (params) (results)
-
-func (P *Parser) ParseNamedSignature() {
- P.Trace("NamedSignature");
- if P.tok == Scanner.LPAREN {
- P.ParseParameters();
- }
- P.ParseIdent(); // function name
- P.ParseParameters();
- P.TryResult();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseDeclaration();
-func (P *Parser) TryStatement() bool;
-func (P *Parser) ParseStatementList();
-func (P *Parser) ParseBlock();
-func (P *Parser) ParsePrimaryExpr();
-
-
-func (P *Parser) ParsePrimaryExprList() {
- P.Trace("PrimaryExprList");
- P.ParsePrimaryExpr();
- for P.tok == Scanner.COMMA {
- P.Next();
- P.ParsePrimaryExpr();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseBuiltinStat() {
- P.Trace("BuiltinStat");
- P.Expect(Scanner.IDENT);
- P.ParseExpressionList(); // TODO should be optional
- P.Ecart();
-}
-
-
-func (P *Parser) ParseSimpleStat() {
- P.Trace("SimpleStat");
- P.ParseExpression();
- if P.tok == Scanner.COLON {
- P.Next();
- P.Ecart();
- return;
- }
- if P.tok == Scanner.COMMA {
- P.Next();
- P.ParsePrimaryExprList();
- }
- switch P.tok {
- case Scanner.ASSIGN: fallthrough;
- case Scanner.DEFINE: fallthrough;
- case Scanner.ADD_ASSIGN: fallthrough;
- case Scanner.SUB_ASSIGN: fallthrough;
- case Scanner.MUL_ASSIGN: fallthrough;
- case Scanner.QUO_ASSIGN: fallthrough;
- case Scanner.REM_ASSIGN: fallthrough;
- case Scanner.AND_ASSIGN: fallthrough;
- case Scanner.OR_ASSIGN: fallthrough;
- case Scanner.XOR_ASSIGN: fallthrough;
- case Scanner.SHL_ASSIGN: fallthrough;
- case Scanner.SHR_ASSIGN:
- P.Next();
- P.ParseExpressionList();
- case Scanner.INC:
- P.Next();
- case Scanner.DEC:
- P.Next();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseGoStat() {
- P.Trace("GoStat");
- P.Expect(Scanner.GO);
- P.ParseExpression();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseReturnStat() {
- P.Trace("ReturnStat");
- P.Expect(Scanner.RETURN);
- if P.tok != Scanner.SEMICOLON && P.tok != Scanner.RBRACE {
- P.ParseExpressionList();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseControlFlowStat(tok int) {
- P.Trace("ControlFlowStat");
- P.Expect(tok);
- if P.tok == Scanner.IDENT {
- P.ParseIdent();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseStatement() {
- P.Trace("Statement");
- if !P.TryStatement() {
- P.Error(P.beg, "statement expected");
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseIfStat() {
- P.Trace("IfStat");
- P.Expect(Scanner.IF);
- if P.tok != Scanner.LBRACE {
- P.ParseSimpleStat();
- if P.tok == Scanner.SEMICOLON {
- P.Next();
- P.ParseExpression();
- }
- }
- P.ParseBlock();
- if P.tok == Scanner.ELSE {
- P.Next();
- if P.tok == Scanner.IF {
- P.ParseIfStat();
- } else {
- // TODO should be P.ParseBlock()
- P.ParseStatement();
- }
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseForStat() {
- P.Trace("ForStat");
- P.Expect(Scanner.FOR);
- if P.tok != Scanner.LBRACE {
- if P.tok != Scanner.SEMICOLON {
- P.ParseSimpleStat();
- }
- if P.tok == Scanner.SEMICOLON {
- P.Next();
- if P.tok != Scanner.SEMICOLON {
- P.ParseExpression();
- }
- P.Expect(Scanner.SEMICOLON);
- if P.tok != Scanner.LBRACE {
- P.ParseSimpleStat();
- }
- }
- }
- P.ParseBlock();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseCase() {
- P.Trace("Case");
- if P.tok == Scanner.CASE {
- P.Next();
- P.ParseExpressionList();
- } else {
- P.Expect(Scanner.DEFAULT);
- }
- P.Expect(Scanner.COLON);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseCaseList() {
- P.Trace("CaseList");
- P.ParseCase();
- for P.tok == Scanner.CASE || P.tok == Scanner.DEFAULT {
- P.ParseCase();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseCaseClause() {
- P.Trace("CaseClause");
- P.ParseCaseList();
- if P.tok != Scanner.FALLTHROUGH && P.tok != Scanner.RBRACE {
- P.ParseStatementList();
- P.Optional(Scanner.SEMICOLON);
- }
- if P.tok == Scanner.FALLTHROUGH {
- P.Next();
- P.Optional(Scanner.SEMICOLON);
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseSwitchStat() {
- P.Trace("SwitchStat");
- P.Expect(Scanner.SWITCH);
- if P.tok != Scanner.LBRACE {
- P.ParseSimpleStat();
- if P.tok == Scanner.SEMICOLON {
- P.Next();
- P.ParseExpression();
- }
- }
- P.Expect(Scanner.LBRACE);
- for P.tok != Scanner.RBRACE {
- P.ParseCaseClause();
- }
- P.Expect(Scanner.RBRACE);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseCommCase() {
- P.Trace("CommCase");
- if P.tok == Scanner.CASE {
- P.Next();
- if P.tok == Scanner.GTR {
- // send
- P.Next();
- P.ParseExpression();
- P.Expect(Scanner.EQL);
- P.ParseExpression();
- } else {
- // receive
- if P.tok != Scanner.LSS {
- P.ParseIdent();
- P.Expect(Scanner.ASSIGN);
- }
- P.Expect(Scanner.LSS);
- P.ParseExpression();
- }
- } else {
- P.Expect(Scanner.DEFAULT);
- }
- P.Expect(Scanner.COLON);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseCommClause() {
- P.Trace("CommClause");
- P.ParseCommCase();
- if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE {
- P.ParseStatementList();
- P.Optional(Scanner.SEMICOLON);
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseRangeStat() bool {
- P.Trace("RangeStat");
- P.Expect(Scanner.RANGE);
- P.ParseIdentList();
- P.Expect(Scanner.DEFINE);
- P.ParseExpression();
- P.ParseBlock();
- P.Ecart();
-}
-
-
-func (P *Parser) ParseSelectStat() bool {
- P.Trace("SelectStat");
- P.Expect(Scanner.SELECT);
- P.Expect(Scanner.LBRACE);
- for P.tok != Scanner.RBRACE {
- P.ParseCommClause();
- }
- P.Next();
- P.Ecart();
-}
-
-
-func (P *Parser) TryStatement() bool {
- P.Trace("Statement (try)");
- indent := P.indent;
- res := true;
- switch P.tok {
- case Scanner.CONST: fallthrough;
- case Scanner.TYPE: fallthrough;
- case Scanner.VAR: fallthrough;
- case Scanner.FUNC:
- P.ParseDeclaration();
- case Scanner.GTR:
- P.ParseSimpleStat(); // send
- case Scanner.IDENT:
- switch P.ident {
- case "print", "panic":
- P.ParseBuiltinStat();
- default:
- P.ParseSimpleStat();
- }
- case Scanner.GO:
- P.ParseGoStat();
- case Scanner.RETURN:
- P.ParseReturnStat();
- case Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO:
- P.ParseControlFlowStat(P.tok);
- case Scanner.LBRACE:
- P.ParseBlock();
- case Scanner.IF:
- P.ParseIfStat();
- case Scanner.FOR:
- P.ParseForStat();
- case Scanner.SWITCH:
- P.ParseSwitchStat();
- case Scanner.RANGE:
- P.ParseRangeStat();
- case Scanner.SELECT:
- P.ParseSelectStat();
- default:
- // no statement found
- res = false;
- }
- if indent != P.indent {
- panic "imbalanced tracing code"
- }
- P.Ecart();
- return res;
-}
-
-
-func (P *Parser) ParseStatementList() {
- P.Trace("StatementList");
- for P.TryStatement() {
- P.Optional(Scanner.SEMICOLON);
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseBlock() {
- P.Trace("Block");
- P.Expect(Scanner.LBRACE);
- if P.tok != Scanner.RBRACE && P.tok != Scanner.SEMICOLON {
- P.ParseStatementList();
- }
- P.Optional(Scanner.SEMICOLON);
- P.Expect(Scanner.RBRACE);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseFuncDecl() {
- P.Trace("FuncDecl");
- P.Expect(Scanner.FUNC);
- P.ParseNamedSignature();
- if P.tok == Scanner.SEMICOLON {
- // forward declaration
- P.Next();
- } else {
- P.ParseBlock();
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseExportDecl() {
- P.Trace("ExportDecl");
- P.Expect(Scanner.EXPORT);
- if P.tok == Scanner.LPAREN {
- P.Next();
- for P.tok != Scanner.RPAREN {
- P.ParseIdent();
- P.Optional(Scanner.COMMA); // TODO this seems wrong
- }
- P.Next();
- } else {
- P.ParseIdent();
- for P.tok == Scanner.COMMA {
- P.Next();
- P.ParseIdent();
- }
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseDeclaration() {
- P.Trace("Declaration");
- indent := P.indent;
- switch P.tok {
- case Scanner.CONST:
- P.ParseConstDecl();
- case Scanner.TYPE:
- P.ParseTypeDecl();
- case Scanner.VAR:
- P.ParseVarDecl();
- case Scanner.FUNC:
- P.ParseFuncDecl();
- case Scanner.EXPORT:
- P.ParseExportDecl();
- default:
- P.Error(P.beg, "declaration expected");
- }
- if indent != P.indent {
- panic "imbalanced tracing code"
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseNew() {
- P.Trace("New");
- P.Expect(Scanner.NEW);
- P.Expect(Scanner.LPAREN);
- P.ParseType();
- if P.tok == Scanner.COMMA {
- P.Next();
- P.ParseExpressionList()
- }
- P.Expect(Scanner.RPAREN);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseOperand() {
- P.Trace("Operand");
- switch P.tok {
- case Scanner.IDENT:
- P.ParseQualifiedIdent();
- case Scanner.LPAREN:
- P.Next();
- P.ParseExpression();
- P.Expect(Scanner.RPAREN);
- case Scanner.STRING: fallthrough;
- case Scanner.NUMBER: fallthrough;
- case Scanner.NIL: fallthrough;
- case Scanner.IOTA: fallthrough;
- case Scanner.TRUE: fallthrough;
- case Scanner.FALSE:
- P.Next();
- case Scanner.NEW:
- P.ParseNew();
- default:
- P.Error(P.beg, "operand expected");
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseSelectorOrTypeAssertion() {
- P.Trace("SelectorOrTypeAssertion");
- P.Expect(Scanner.PERIOD);
- if P.tok == Scanner.IDENT {
- P.ParseIdent();
- } else {
- P.Expect(Scanner.LPAREN);
- P.ParseType();
- P.Expect(Scanner.RPAREN);
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseIndexOrSlice() {
- P.Trace("IndexOrSlice");
- P.Expect(Scanner.LBRACK);
- P.ParseExpression();
- if P.tok == Scanner.COLON {
- P.Next();
- P.ParseExpression();
- }
- P.Expect(Scanner.RBRACK);
- P.Ecart();
-}
-
-
-func (P *Parser) ParseInvocation() {
- P.Trace("Invocation");
- P.Expect(Scanner.LPAREN);
- if P.tok != Scanner.RPAREN {
- P.ParseExpressionList();
- }
- P.Expect(Scanner.RPAREN);
- P.Ecart();
-}
-
-
-func (P *Parser) ParsePrimaryExpr() {
- P.Trace("PrimaryExpr");
- P.ParseOperand();
- for {
- switch P.tok {
- case Scanner.PERIOD:
- P.ParseSelectorOrTypeAssertion();
- case Scanner.LBRACK:
- P.ParseIndexOrSlice();
- case Scanner.LPAREN:
- P.ParseInvocation();
- default:
- P.Ecart();
- return;
- }
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseUnaryExpr() {
- P.Trace("UnaryExpr");
- switch P.tok {
- case Scanner.ADD: fallthrough;
- case Scanner.SUB: fallthrough;
- case Scanner.NOT: fallthrough;
- case Scanner.XOR: fallthrough;
- case Scanner.LSS: fallthrough;
- case Scanner.GTR: fallthrough;
- case Scanner.MUL: fallthrough;
- case Scanner.AND:
- P.Next();
- P.ParseUnaryExpr();
- P.Ecart();
- return;
- }
- P.ParsePrimaryExpr();
- P.Ecart();
-}
-
-
-func Precedence(tok int) int {
- // TODO should use a map or array here for lookup
- switch tok {
- case Scanner.LOR:
- return 1;
- case Scanner.LAND:
- return 2;
- case Scanner.EQL, Scanner.NEQ, Scanner.LSS, Scanner.LEQ, Scanner.GTR, Scanner.GEQ:
- return 3;
- case Scanner.ADD, Scanner.SUB, Scanner.OR, Scanner.XOR:
- return 4;
- case Scanner.MUL, Scanner.QUO, Scanner.REM, Scanner.SHL, Scanner.SHR, Scanner.AND:
- return 5;
- }
- return 0;
-}
-
-
-func (P *Parser) ParseBinaryExpr(prec1 int) {
- P.Trace("BinaryExpr");
- P.ParseUnaryExpr();
- for prec := Precedence(P.tok); prec >= prec1; prec-- {
- for Precedence(P.tok) == prec {
- P.Next();
- P.ParseBinaryExpr(prec + 1);
- }
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseExpression() {
- P.Trace("Expression");
- indent := P.indent;
- P.ParseBinaryExpr(1);
- if indent != P.indent {
- panic "imbalanced tracing code";
- }
- P.Ecart();
-}
-
-
-func (P *Parser) ParseProgram() {
- P.Trace("Program");
- P.Expect(Scanner.PACKAGE);
- P.ParseIdent();
- for P.tok == Scanner.IMPORT {
- P.ParseImportDecl();
- P.Optional(Scanner.SEMICOLON);
- }
- for P.tok != Scanner.EOF {
- P.ParseDeclaration();
- P.Optional(Scanner.SEMICOLON);
- }
- P.Ecart();
-}
diff --git a/usr/gri/src/scanner.go b/usr/gri/src/scanner.go
deleted file mode 100644
index 94d8f1915..000000000
--- a/usr/gri/src/scanner.go
+++ /dev/null
@@ -1,777 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package Scanner
-
-export
- ILLEGAL, EOF, IDENT, STRING, NUMBER,
- COMMA, COLON, SEMICOLON, PERIOD,
- LPAREN, RPAREN, LBRACK, RBRACK, LBRACE, RBRACE,
- ASSIGN, DEFINE,
- INC, DEC, NOT,
- AND, OR, XOR,
- ADD, SUB, MUL, QUO, REM,
- EQL, NEQ, LSS, LEQ, GTR, GEQ,
- SHL, SHR,
- ADD_ASSIGN, SUB_ASSIGN, MUL_ASSIGN, QUO_ASSIGN, REM_ASSIGN,
- AND_ASSIGN, OR_ASSIGN, XOR_ASSIGN, SHL_ASSIGN, SHR_ASSIGN,
- LAND, LOR,
- BREAK, CASE, CHAN, CONST, CONTINUE, DEFAULT, ELSE, EXPORT, FALLTHROUGH, FALSE,
- FOR, FUNC, GO, GOTO, IF, IMPORT, INTERFACE, IOTA, MAP, NEW, NIL, PACKAGE, RANGE,
- RETURN, SELECT, STRUCT, SWITCH, TRUE, TYPE, VAR
-
-
-const (
- ILLEGAL = iota;
- EOF;
- IDENT;
- STRING;
- NUMBER;
-
- COMMA;
- COLON;
- SEMICOLON;
- PERIOD;
-
- LPAREN;
- RPAREN;
- LBRACK;
- RBRACK;
- LBRACE;
- RBRACE;
-
- ASSIGN;
- DEFINE;
-
- INC;
- DEC;
- NOT;
-
- AND;
- OR;
- XOR;
-
- ADD;
- SUB;
- MUL;
- QUO;
- REM;
-
- EQL;
- NEQ;
- LSS;
- LEQ;
- GTR;
- GEQ;
-
- SHL;
- SHR;
-
- ADD_ASSIGN;
- SUB_ASSIGN;
- MUL_ASSIGN;
- QUO_ASSIGN;
- REM_ASSIGN;
-
- AND_ASSIGN;
- OR_ASSIGN;
- XOR_ASSIGN;
-
- SHL_ASSIGN;
- SHR_ASSIGN;
-
- LAND;
- LOR;
-
- // keywords
- KEYWORDS_BEG;
- BREAK;
- CASE;
- CHAN;
- CONST;
- CONTINUE;
- DEFAULT;
- ELSE;
- EXPORT;
- FALLTHROUGH;
- FALSE;
- FOR;
- FUNC;
- GO;
- GOTO;
- IF;
- IMPORT;
- INTERFACE;
- IOTA;
- MAP;
- NEW;
- NIL;
- PACKAGE;
- RANGE;
- RETURN;
- SELECT;
- STRUCT;
- SWITCH;
- TRUE;
- TYPE;
- VAR;
- KEYWORDS_END;
-)
-
-
-var Keywords *map [string] int;
-
-
-export TokenName
-func TokenName(tok int) string {
- switch (tok) {
- case ILLEGAL: return "illegal";
- case EOF: return "eof";
- case IDENT: return "ident";
- case STRING: return "string";
- case NUMBER: return "number";
-
- case COMMA: return ",";
- case COLON: return ":";
- case SEMICOLON: return ";";
- case PERIOD: return ".";
-
- case LPAREN: return "(";
- case RPAREN: return ")";
- case LBRACK: return "[";
- case RBRACK: return "]";
- case LBRACE: return "LBRACE";
- case RBRACE: return "RBRACE";
-
- case ASSIGN: return "=";
- case DEFINE: return ":=";
-
- case INC: return "++";
- case DEC: return "--";
- case NOT: return "!";
-
- 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 "<";
- case LEQ: return "<=";
- case GTR: return ">";
- case GEQ: return ">=";
-
- case SHL: return "<<";
- case SHR: return ">>";
-
- case ADD_ASSIGN: return "+=";
- case SUB_ASSIGN: return "-=";
- case MUL_ASSIGN: return "+=";
- case QUO_ASSIGN: return "/=";
- case REM_ASSIGN: return "%=";
-
- case AND_ASSIGN: return "&=";
- case OR_ASSIGN: return "|=";
- case XOR_ASSIGN: return "^=";
-
- case SHL_ASSIGN: return "<<=";
- case SHR_ASSIGN: return ">>=";
-
- case LAND: return "&&";
- case LOR: return "||";
-
- case BREAK: return "break";
- case CASE: return "case";
- case CHAN: return "chan";
- case CONST: return "const";
- case CONTINUE: return "continue";
- case DEFAULT: return "default";
- case ELSE: return "else";
- case EXPORT: return "export";
- case FALLTHROUGH: return "fallthrough";
- case FALSE: return "false";
- case FOR: return "for";
- case FUNC: return "func";
- case GO: return "go";
- case GOTO: return "goto";
- case IF: return "if";
- case IMPORT: return "import";
- case INTERFACE: return "interface";
- case IOTA: return "iota";
- case MAP: return "map";
- case NEW: return "new";
- case NIL: return "nil";
- case PACKAGE: return "package";
- case RANGE: return "range";
- case RETURN: return "return";
- case SELECT: return "select";
- case STRUCT: return "struct";
- case SWITCH: return "switch";
- case TRUE: return "true";
- case TYPE: return "type";
- case VAR: return "var";
- }
-
- return "???";
-}
-
-
-func is_whitespace (ch int) bool {
- return ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t';
-}
-
-
-func is_letter (ch int) bool {
- return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 128 ;
-}
-
-
-func digit_val (ch int) int {
- if '0' <= ch && ch <= '9' {
- return ch - '0';
- }
- if 'a' <= ch && ch <= 'f' {
- return ch - 'a' + 10;
- }
- if 'A' <= ch && ch <= 'F' {
- return ch - 'A' + 10;
- }
- return 16; // larger than any legal digit val
-}
-
-
-export Scanner
-type Scanner struct {
- filename string; // error reporting only
- nerrors int; // number of errors
- errpos int; // last error position
-
- src string;
- pos int; // current reading position
- ch int; // one char look-ahead
- chpos int; // position of ch
-}
-
-
-// Read the next Unicode char into S.ch.
-// S.ch < 0 means end-of-file.
-//
-func (S *Scanner) Next () {
- const (
- Bit1 = 7;
- Bitx = 6;
- Bit2 = 5;
- Bit3 = 4;
- Bit4 = 3;
-
- // TODO 6g constant evaluation incomplete
- T1 = 0x00; // (1 << (Bit1 + 1) - 1) ^ 0xFF; // 0000 0000
- Tx = 0x80; // (1 << (Bitx + 1) - 1) ^ 0xFF; // 1000 0000
- T2 = 0xC0; // (1 << (Bit2 + 1) - 1) ^ 0xFF; // 1100 0000
- T3 = 0xE0; // (1 << (Bit3 + 1) - 1) ^ 0xFF; // 1110 0000
- T4 = 0xF0; // (1 << (Bit4 + 1) - 1) ^ 0xFF; // 1111 0000
-
- Rune1 = 1 << (Bit1 + 0*Bitx) - 1; // 0000 0000 0111 1111
- Rune2 = 1 << (Bit2 + 1*Bitx) - 1; // 0000 0111 1111 1111
- Rune3 = 1 << (Bit3 + 2*Bitx) - 1; // 1111 1111 1111 1111
-
- Maskx = 0x3F; // 1 << Bitx - 1; // 0011 1111
- Testx = 0xC0; // Maskx ^ 0xFF; // 1100 0000
-
- Bad = 0xFFFD; // Runeerror
- );
-
- src := S.src; // TODO only needed because of 6g bug
- lim := len(src);
- pos := S.pos;
-
- // 1-byte sequence
- // 0000-007F => T1
- if pos >= lim {
- S.ch = -1; // end of file
- S.chpos = lim;
- return;
- }
- c0 := int(src[pos]);
- pos++;
- if c0 < Tx {
- S.ch = c0;
- S.chpos = S.pos;
- S.pos = pos;
- return;
- }
-
- // 2-byte sequence
- // 0080-07FF => T2 Tx
- if pos >= lim {
- goto bad;
- }
- c1 := int(src[pos]) ^ Tx;
- pos++;
- if c1 & Testx != 0 {
- goto bad;
- }
- if c0 < T3 {
- if c0 < T2 {
- goto bad;
- }
- r := (c0 << Bitx | c1) & Rune2;
- if r <= Rune1 {
- goto bad;
- }
- S.ch = r;
- S.chpos = S.pos;
- S.pos = pos;
- return;
- }
-
- // 3-byte sequence
- // 0800-FFFF => T3 Tx Tx
- if pos >= lim {
- goto bad;
- }
- c2 := int(src[pos]) ^ Tx;
- pos++;
- if c2 & Testx != 0 {
- goto bad;
- }
- if c0 < T4 {
- r := (((c0 << Bitx | c1) << Bitx) | c2) & Rune3;
- if r <= Rune2 {
- goto bad;
- }
- S.ch = r;
- S.chpos = S.pos;
- S.pos = pos;
- return;
- }
-
- // bad encoding
-bad:
- S.ch = Bad;
- S.chpos = S.pos;
- S.pos += 1;
- return;
-}
-
-
-func Init () {
- Keywords = new(map [string] int);
-
- for i := KEYWORDS_BEG; i <= KEYWORDS_END; i++ {
- Keywords[TokenName(i)] = i;
- }
-}
-
-
-// Compute (line, column) information for a given source position.
-func (S *Scanner) LineCol(pos int) (line, col int) {
- line = 1;
- lpos := 0;
-
- src := S.src;
- if pos > len(src) {
- pos = len(src);
- }
-
- for i := 0; i < pos; i++ {
- if src[i] == '\n' {
- line++;
- lpos = i;
- }
- }
-
- return line, pos - lpos;
-}
-
-
-func (S *Scanner) Error(pos int, msg string) {
- const errdist = 10;
- if pos > S.errpos + errdist || S.nerrors == 0 {
- line, col := S.LineCol(pos);
- print S.filename, ":", line, ":", col, ": ", msg, "\n";
- S.nerrors++;
- S.errpos = pos;
- }
-}
-
-
-func (S *Scanner) Open (filename, src string) {
- if Keywords == nil {
- Init();
- }
-
- S.filename = filename;
- S.nerrors = 0;
- S.errpos = 0;
-
- S.src = src;
- S.pos = 0;
- S.Next();
-}
-
-
-// TODO this needs to go elsewhere
-func IntString(x, base int) string {
- neg := false;
- if x < 0 {
- x = -x;
- if x < 0 {
- panic "smallest int not handled";
- }
- neg = true;
- }
-
- hex := "0123456789ABCDEF";
- var buf [16] byte;
- i := 0;
- for x > 0 || i == 0 {
- buf[i] = hex[x % base];
- x /= base;
- i++;
- }
-
- s := "";
- if neg {
- s = "-";
- }
- for i > 0 {
- i--;
- s = s + string(int(buf[i]));
- }
- return s;
-}
-
-
-func CharString(ch int) string {
- s := string(ch);
- switch ch {
- case '\a': s = `\a`;
- case '\b': s = `\b`;
- case '\f': s = `\f`;
- case '\n': s = `\n`;
- case '\r': s = `\r`;
- case '\t': s = `\t`;
- case '\v': s = `\v`;
- case '\\': s = `\\`;
- case '\'': s = `\'`;
- }
- return "'" + s + "' (U+" + IntString(ch, 16) + ")";
-}
-
-
-func (S *Scanner) Expect (ch int) {
- if S.ch != ch {
- S.Error(S.chpos, "expected " + CharString(ch) + ", found " + CharString(S.ch));
- }
- S.Next(); // make always progress
-}
-
-
-func (S *Scanner) SkipWhitespace () {
- for is_whitespace(S.ch) {
- S.Next();
- }
-}
-
-
-func (S *Scanner) SkipComment () {
- // '/' already consumed
- if S.ch == '/' {
- // comment
- S.Next();
- for S.ch != '\n' && S.ch >= 0 {
- S.Next();
- }
-
- } else {
- /* comment */
- pos := S.chpos - 1;
- S.Expect('*');
- for S.ch >= 0 {
- ch := S.ch;
- S.Next();
- if ch == '*' && S.ch == '/' {
- S.Next();
- return;
- }
- }
- S.Error(pos, "comment not terminated");
- }
-}
-
-
-func (S *Scanner) ScanIdentifier () int {
- beg := S.pos - 1;
- for is_letter(S.ch) || digit_val(S.ch) < 10 {
- S.Next();
- }
- end := S.pos - 1;
-
- var tok int;
- var present bool;
- tok, present = Keywords[S.src[beg : end]];
- if !present {
- tok = IDENT;
- }
-
- return tok;
-}
-
-
-func (S *Scanner) ScanMantissa (base int) {
- for digit_val(S.ch) < base {
- S.Next();
- }
-}
-
-
-func (S *Scanner) ScanNumber (seen_decimal_point bool) int {
- if seen_decimal_point {
- S.ScanMantissa(10);
- goto exponent;
- }
-
- if S.ch == '0' {
- // int or float
- S.Next();
- if S.ch == 'x' || S.ch == 'X' {
- // hexadecimal int
- S.Next();
- S.ScanMantissa(16);
- } else {
- // octal int or float
- S.ScanMantissa(8);
- if digit_val(S.ch) < 10 || S.ch == '.' || S.ch == 'e' || S.ch == 'E' {
- // float
- goto mantissa;
- }
- // octal int
- }
- return NUMBER;
- }
-
-mantissa:
- // decimal int or float
- S.ScanMantissa(10);
-
- if S.ch == '.' {
- // float
- S.Next();
- S.ScanMantissa(10)
- }
-
-exponent:
- if S.ch == 'e' || S.ch == 'E' {
- // float
- S.Next();
- if S.ch == '-' || S.ch == '+' {
- S.Next();
- }
- S.ScanMantissa(10);
- }
- return NUMBER;
-}
-
-
-func (S *Scanner) ScanDigits(n int, base int) {
- for digit_val(S.ch) < base {
- S.Next();
- n--;
- }
- if n > 0 {
- S.Error(S.chpos, "illegal char escape");
- }
-}
-
-
-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
-
- case 'U':
- S.ScanDigits(8, 16);
- return ""; // TODO fix this
-
- default:
- S.Error(pos, "illegal char escape");
- }
-}
-
-
-func (S *Scanner) ScanChar () int {
- // '\'' already consumed
-
- ch := S.ch;
- S.Next();
- if ch == '\\' {
- S.ScanEscape();
- }
-
- S.Expect('\'');
- return NUMBER;
-}
-
-
-func (S *Scanner) ScanString () int {
- // '"' already consumed
-
- pos := S.chpos - 1;
- for S.ch != '"' {
- ch := S.ch;
- S.Next();
- if ch == '\n' || ch < 0 {
- S.Error(pos, "string not terminated");
- break;
- }
- if ch == '\\' {
- S.ScanEscape();
- }
- }
-
- S.Next();
- return STRING;
-}
-
-
-func (S *Scanner) ScanRawString () int {
- // '`' already consumed
-
- pos := S.chpos - 1;
- for S.ch != '`' {
- ch := S.ch;
- S.Next();
- if ch == '\n' || ch < 0 {
- S.Error(pos, "string not terminated");
- break;
- }
- }
-
- S.Next();
- return STRING;
-}
-
-
-func (S *Scanner) Select2 (tok0, tok1 int) int {
- if S.ch == '=' {
- S.Next();
- return tok1;
- }
- return tok0;
-}
-
-
-func (S *Scanner) Select3 (tok0, tok1, ch2, tok2 int) int {
- if S.ch == '=' {
- S.Next();
- return tok1;
- }
- if S.ch == ch2 {
- S.Next();
- return tok2;
- }
- return tok0;
-}
-
-
-func (S *Scanner) Select4 (tok0, tok1, ch2, tok2, tok3 int) int {
- if S.ch == '=' {
- S.Next();
- return tok1;
- }
- if S.ch == ch2 {
- S.Next();
- if S.ch == '=' {
- S.Next();
- return tok3;
- }
- return tok2;
- }
- return tok0;
-}
-
-
-func (S *Scanner) Scan () (tok, beg, end int) {
- S.SkipWhitespace();
-
- ch := S.ch;
- tok = ILLEGAL;
- beg = S.chpos;
-
- switch {
- case is_letter(ch): tok = S.ScanIdentifier();
- case digit_val(ch) < 10: tok = S.ScanNumber(false);
- default:
- S.Next(); // always make progress
- switch ch {
- case -1: tok = EOF;
- case '"': tok = S.ScanString();
- case '\'': tok = S.ScanChar();
- case '`': tok = S.ScanRawString();
- case ':': tok = S.Select2(COLON, DEFINE);
- case '.':
- if digit_val(S.ch) < 10 {
- tok = S.ScanNumber(true);
- } else {
- tok = PERIOD;
- }
- case ',': tok = COMMA;
- case ';': tok = SEMICOLON;
- case '(': tok = LPAREN;
- case ')': tok = RPAREN;
- case '[': tok = LBRACK;
- case ']': tok = RBRACK;
- case '{': tok = LBRACE;
- case '}': tok = RBRACE;
- case '+': tok = S.Select3(ADD, ADD_ASSIGN, '+', INC);
- case '-': tok = S.Select3(SUB, SUB_ASSIGN, '-', DEC);
- case '*': tok = S.Select2(MUL, MUL_ASSIGN);
- case '/':
- if S.ch == '/' || S.ch == '*' {
- S.SkipComment();
- // cannot simply return because of 6g bug
- tok, beg, end = S.Scan();
- return tok, beg, end;
- }
- tok = S.Select2(QUO, QUO_ASSIGN);
- case '%': tok = S.Select2(REM, REM_ASSIGN);
- case '^': tok = S.Select2(XOR, XOR_ASSIGN);
- case '<': tok = S.Select4(LSS, LEQ, '<', SHL, SHL_ASSIGN);
- case '>': tok = S.Select4(GTR, GEQ, '>', SHR, SHR_ASSIGN);
- case '=': tok = S.Select2(ASSIGN, EQL);
- case '!': tok = S.Select2(NOT, NEQ);
- case '&': tok = S.Select3(AND, AND_ASSIGN, '&', LAND);
- case '|': tok = S.Select3(OR, OR_ASSIGN, '|', LOR);
- default:
- S.Error(beg, "illegal character " + CharString(ch));
- tok = ILLEGAL;
- }
- }
-
- return tok, beg, S.chpos;
-}
diff --git a/usr/gri/src/scope.go b/usr/gri/src/scope.go
deleted file mode 100644
index 13a14ce49..000000000
--- a/usr/gri/src/scope.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package Scope
-
-import Globals "Globals"
-
-type Scope Globals.Scope
-
-func New(parent *Scope) *Scope {
- panic "UNIMPLEMENTED";
- return nil;
-}
diff --git a/usr/gri/src/test_parser.go b/usr/gri/src/test_parser.go
deleted file mode 100644
index 78d8d8711..000000000
--- a/usr/gri/src/test_parser.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import Scanner "scanner"
-import Parser "parser"
-
-
-func Parse(filename, src string, verbose int) {
- S := new(Scanner.Scanner);
- S.Open(filename, src);
-
- P := new(Parser.Parser);
- P.Open(S, verbose);
-
- P.ParseProgram();
-}
-
-
-func main() {
- verbose := 0;
- for i := 1; i < sys.argc(); i++ {
- switch sys.argv(i) {
- case "-v":
- verbose = 1;
- continue;
- case "-vv":
- verbose = 2;
- continue;
- }
-
- src, ok := sys.readfile(sys.argv(i));
- if ok {
- print "parsing " + sys.argv(i) + "\n";
- Parse(sys.argv(i), src, verbose);
- } else {
- print "error: cannot read " + sys.argv(i) + "\n";
- }
- }
-}
diff --git a/usr/gri/src/test_scanner.go b/usr/gri/src/test_scanner.go
deleted file mode 100644
index 5ebff817b..000000000
--- a/usr/gri/src/test_scanner.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import Scanner "scanner"
-
-
-func Scan(filename, src string) {
- S := new(Scanner.Scanner);
- S.Open(filename, src);
- for {
- tok, beg, end := S.Scan();
- print Scanner.TokenName(tok), "\t ", src[beg : end], "\n";
- if tok == Scanner.EOF {
- return;
- }
- }
-}
-
-
-func main() {
- for i := 1; i < sys.argc(); i++ {
- var src string;
- var ok bool;
- src, ok = sys.readfile(sys.argv(i));
- if ok {
- print "scanning " + sys.argv(i) + "\n";
- Scan(sys.argv(i), src);
- } else {
- print "error: cannot read " + sys.argv(i) + "\n";
- }
- }
-}
diff --git a/usr/gri/src/type.go b/usr/gri/src/type.go
deleted file mode 100644
index 975adec68..000000000
--- a/usr/gri/src/type.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package Type
-
-import Globals "globals"
-
-const /* form */ (
- // internal types
- UNDEF = iota; BAD; NIL;
- // basic types
- BOOL; UINT; INT; FLOAT; STRING;
- // 'any' type
- ANY;
- // composite types
- ARRAY; STRUCT; INTERFACE; MAP; CHANNEL; FUNCTION; POINTER; REFERENCE;
-)
-
-
-const /* flag */ (
- SEND = 1 << iota; // chan>
- RECV; // chan< or method
-)
-
-
-type Type Globals.Type
-
-
-func NewType(form int) *Type {
- panic "UNIMPLEMENTED";
- return nil;
-}