Example #1
0
 public ParseException(string message, Tokenizer tokenizer, int lineNumber, int column)
     : base(message)
 {
     this.tokenizer = tokenizer;
     this.lineNumber = lineNumber;
     this.column = column;
 }
Example #2
0
 public ObjectFileSymbolTable(Tokenizer tokenizer)
 {
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "TRUE", 0, 0)),
         new IntExpr(null, -1));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "FALSE", 0, 0)),
         new IntExpr(null, 0));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "POSX", 0, 0)),
         new IntExpr(null, 2147483647));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "NEGX", 0, 0)),
         new IntExpr(null, -2147483648));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "PI", 0, 0)),
         new FloatExpr(null, (float)Math.PI));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "RCFAST", 0, 0)),
         new IntExpr(null, 0x001));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "RCSLOW", 0, 0)),
         new IntExpr(null, 0x002));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "XINPUT", 0, 0)),
         new IntExpr(null, 0x004));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "XTAL1", 0, 0)),
         new IntExpr(null, 0x008));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "XTAL2", 0, 0)),
         new IntExpr(null, 0x010));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "XTAL3", 0, 0)),
         new IntExpr(null, 0x020));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "PLL1X", 0, 0)),
         new IntExpr(null, 0x040));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "PLL2X", 0, 0)),
         new IntExpr(null, 0x080));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "PLL4X", 0, 0)),
         new IntExpr(null, 0x100));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "PLL8X", 0, 0)),
         new IntExpr(null, 0x200));
     AddBuiltInConSymbol(new IdToken(new SimpleToken(tokenizer, SimpleTokenType.Id, "PLL16X", 0, 0)),
         new IntExpr(null, 0x400));
 }
Example #3
0
        static void Compile(string filename, Hashtable defines)
        {
            SimpleToken st = new SimpleToken(null, SimpleTokenType.Id, filename, 0, 0);
            Tokenizer tokenizer = new Tokenizer(st, defines);
            tokenizer.Go();

            GlobalSymbolTable.CompileAll();
            GlobalSymbolTable.EliminateDuplicateObjects();
            byte[] memory = new byte[Options.memorySize];
            GlobalSymbolTable.ToMemory(memory);
            Dis.Mem = memory;
            if (Options.saveBinary)
            {
                string outputFilename = filename.Substring(0, filename.Length - 5) + ".binary";
                if (Options.outputFilename != "")
                {
                    outputFilename = Options.outputFilename;
                    if (!outputFilename.ToUpper().EndsWith(".BINARY"))
                        outputFilename += ".binary";
                }
                int n = GlobalSymbolTable.varAddress;
                if ((n & 0xffff) != (memory[8] + (memory[9] << 8)))
                {
                    throw new Exception("internal error writing .binary file; please report");
                }
                Console.WriteLine("writing {0} bytes to {1}", n, outputFilename);
                BinaryWriter bw = new BinaryWriter(new FileStream(outputFilename, FileMode.Create));
                bw.Write(memory, 0, n);
            }
            else	// save .eeprom
            {
                string outputFilename = filename.Substring(0, filename.Length - 5) + ".eeprom";
                if (Options.outputFilename != "")
                {
                    outputFilename = Options.outputFilename;
                    if (!outputFilename.ToUpper().EndsWith(".EEPROM"))
                        outputFilename += ".eeprom";
                }
                Console.WriteLine("writing 32768 bytes to {0}", outputFilename);
                BinaryWriter bw = new BinaryWriter(new FileStream(outputFilename, FileMode.Create));
                bw.Write(memory);
            }
            if (Options.saveDat)
            {
                string outputFilename = filename.Substring(0, filename.Length - 5) + ".dat";
                if (Options.outputFilename != "")
                {
                    outputFilename = Options.outputFilename;
                    if (!outputFilename.ToUpper().EndsWith(".DAT"))
                        outputFilename += ".dat";
                }
                int start = (memory[0x12] + memory[0x13]) * 4;
                int n = memory[0x14] + memory[0x15] * 256 // assumes 1st PUB's code immediately follows DAT
                    - start;
                start += 0x0010;
                Console.WriteLine("writing {0} bytes to {1}", n, outputFilename);
                BinaryWriter bw = new BinaryWriter(new FileStream(outputFilename, FileMode.Create));
                bw.Write(memory, start, n);
            }
            if (Options.saveSob)
                GlobalSymbolTable.WriteSobs();
        }
Example #4
0
 public static ArrayList ParseStatements(Tokenizer Tokenizer, int indent)
 {
     ArrayList statementList = new ArrayList();
     while (true)
     {
         if (Tokenizer.Current.Text == "(eof)")
             break;
         if (Tokenizer.Current is BlockDesignatorToken)
             break;
         if (Tokenizer.Current.Column <= indent)
             break;
         statementList.Add(ParseStatement(Tokenizer));
     }
     return statementList;
 }
Example #5
0
 public static Stmt ParseStatement(Tokenizer Tokenizer)
 {
     Stmt s;
     if (Tokenizer.Current.Std(out s))
     {
         return s;
     }
     else
     {
         SimpleToken token = Tokenizer.Current;
         Expr e = ParseExpression(Tokenizer, 13);
         s = new ExprStmt(token, Tokenizer.Current.LineNumber, e);
         Tokenizer.Advance("(eol)");
         return s;
     }
 }
Example #6
0
 public static Expr ParseExpression(Tokenizer Tokenizer, int rbp)
 {
     Token t = Tokenizer.Current;
     Tokenizer.Advance();
     Expr left = t.Nud();
     while (rbp > Tokenizer.Current.Lbp)
     {
         t = Tokenizer.Current;
         Tokenizer.Advance();
         left = t.Led(left);
     }
     return left;
 }
Example #7
0
 public static Stmt ParseBlock(Tokenizer Tokenizer)
 {
     Stmt s;
     if (!(Tokenizer.Current is BlockDesignatorToken))
         throw new ParseException("Unexpected " + Tokenizer.Current.Text, Tokenizer.Current);
     Tokenizer.Current.Std(out s);
     return s;
 }
Example #8
0
 public static ArrayList ParseArgumentList(Tokenizer Tokenizer)
 {
     ArrayList argList = new ArrayList();
     if (Tokenizer.Current.Text != "(")
         return argList;
     Tokenizer.Advance("(");
     while (true)
     {
         argList.Add(ParseExpression(Tokenizer, 13));
         if (Tokenizer.Current.Text != ",")
             break;
         Tokenizer.Advance(",");
     }
     Tokenizer.Advance(")");
     return argList;
 }
Example #9
0
        public override bool Std(out Stmt s)
        {
            s = null;

            if (this.Column != 0)
                throw new ParseException("OBJ must be in 1st column", this);
            Tokenizer.Advance();	// past "OBJ".
            if (Tokenizer.Current.Text == "(eol)")
                Tokenizer.Advance("(eol)");

            while (Tokenizer.Current is IdToken)
            {
                IdToken objName = Tokenizer.GetToken() as IdToken;

                Expr countExpr = null;
                if (Tokenizer.Current.Text == "[")
                {
                    Tokenizer.Advance("[");
                    countExpr = ParseExpression(Tokenizer, 13);
                    Tokenizer.Advance("]");
                }

                Tokenizer.Advance(":");
                string filename = "";
                int lineNumber = Tokenizer.Current.LineNumber;
                int column = Tokenizer.Current.Column;

                while (Tokenizer.Current is IntToken)
                {
                    IntToken intToken = Tokenizer.GetToken() as IntToken;
                    filename += (char)intToken.IntValue;
                    if (Tokenizer.Current.Text != ",")
                        break;
                    Tokenizer.Advance(",");
                }
                if (filename == "")
                    throw new ParseException("Expected object file name", Tokenizer.Current);
                filename.Trim();
                if (!filename.ToUpper().EndsWith(".SPIN"))
                    filename += ".spin";
                // filename always includes .spin suffix.

                SimpleToken filenameToken = new SimpleToken(Tokenizer, SimpleTokenType.Id, filename, lineNumber, column);
                bool needsVarSpace = true;
                if (Tokenizer.Current.Text.ToUpper() == "POINTER")
                {
                    Tokenizer.Advance();
                    needsVarSpace = false;
                }
                Tokenizer.Advance("(eol)");
                SymbolTable.AddObjSymbol(objName, filenameToken, countExpr, needsVarSpace);
                Tokenizer tokenizer = new Tokenizer(filenameToken, Tokenizer.Defines);
                tokenizer.Go();
            }
            return true;
        }
Example #10
0
 public SimpleToken(Tokenizer tokenizer, SimpleTokenType type, string text, int lineNumber, int column, int intValue, float floatValue)
 {
     this.tokenizer = tokenizer;
     this.type = type;
     this.text = text;
     this.lineNumber = lineNumber;
     this.column = column;
     this.intValue = intValue;
     this.floatValue = floatValue;
 }
Example #11
0
 public SimpleToken(Tokenizer tokenizer, SimpleTokenType type, string text, int lineNumber, int column, int intValue)
     : this(tokenizer, type, text, lineNumber, column, intValue, 0.0f)
 {
 }