Пример #1
0
        public override bool Std(out Stmt s)
        {
            SimpleToken caseToken = Tokenizer.GetToken();	// CASE
            int caseIndent = caseToken.Column;
            Expr caseExpr = ParseExpression(Tokenizer, 13);
            int endLineNumber = Tokenizer.Current.LineNumber;	// end of the CASE <expr>
            Tokenizer.Advance("(eol)");
            ArrayList matchExprListList = new ArrayList();
            ArrayList matchStmtListList = new ArrayList();
            ArrayList otherStmtList = new ArrayList();
            ArrayList matchTokenList = new ArrayList();
            ArrayList matchEndLineNumberList = new ArrayList();

            int matchIndent = Tokenizer.Current.Column;
            if (matchIndent <= caseIndent)
                throw new ParseException("No cases encountered", Tokenizer.Current);
            bool otherEncountered = false;
            while (Tokenizer.Current.Column == matchIndent)
            {
                if (otherEncountered)
                {
                    throw new ParseException("OTHER must be last case", Tokenizer.Current);
                }
                matchTokenList.Add(Tokenizer.Current);
                if (Tokenizer.Current.Text.ToUpper() == "OTHER")
                {
                    otherEncountered = true;
                    Tokenizer.Advance("OTHER");
                    Tokenizer.Advance(":");
                    matchEndLineNumberList.Add(Tokenizer.Current.LineNumber);

                    if (Tokenizer.Current.Text == "(eol)")
                        Tokenizer.Advance();
                    otherStmtList = ParseStatements(Tokenizer, matchIndent);
                }
                else
                {
                    ArrayList matchExprList = new ArrayList();
                    while (true)	// parse match expressions
                    {
                        Expr e = ParseExpression(Tokenizer, 13);
                        if (Tokenizer.Current.Text == "..")
                        {
                            Tokenizer.Advance("..");
                            Expr f = ParseExpression(Tokenizer, 13);
                            matchExprList.Add(new PairOfExpr(e, f));
                        }
                        else
                        {
                            matchExprList.Add(e);
                        }
                        if (Tokenizer.Current.Text != ",")
                            break;
                        Tokenizer.Advance(",");
                    }
                    Tokenizer.Advance(":");
                    matchEndLineNumberList.Add(Tokenizer.Current.LineNumber);

                    matchExprListList.Add(matchExprList);

                    if (Tokenizer.Current.Text == "(eol)")
                        Tokenizer.Advance();
                    matchStmtListList.Add(ParseStatements(Tokenizer, matchIndent));
                }
            }
            s = new CaseStmt(caseToken, endLineNumber, caseExpr, matchExprListList, matchStmtListList, otherStmtList, matchTokenList, matchEndLineNumberList);
            return true;
        }
Пример #2
0
 public override bool Std(out Stmt s)
 {
     Tokenizer.Advance();	// past WAIT*
     ArrayList argList = ParseArgumentList(Tokenizer);
     int nExpected = 0;
     switch (Text.ToUpper())
     {
         case "WAITCNT": nExpected = 1; break;
         case "WAITPEQ": nExpected = 3; break;
         case "WAITPNE": nExpected = 3; break;
         case "WAITVID": nExpected = 2; break;
     }
     if (argList.Count != nExpected)
         throw new ParseException("Expected this many arguments: " + nExpected.ToString(), Tokenizer.Current);
     s = new WaitStmt(this, Tokenizer.Current.LineNumber, argList);
     Tokenizer.Advance("(eol)");
     return true;
 }
Пример #3
0
 public override bool Std(out Stmt s)
 {
     SimpleToken abortToken = Tokenizer.GetToken();
     Expr abortExpr = null;
     if (Tokenizer.Current.Text != "(eol)")
     {
         abortExpr = ParseExpression(Tokenizer, 13);
     }
     s = new AbortStmt(abortToken, Tokenizer.Current.LineNumber, abortExpr);
     Tokenizer.Advance("(eol)");
     return true;
 }
Пример #4
0
 public virtual bool Std(out Stmt s)
 {
     s = null;
     return false;
 }
Пример #5
0
        public override bool Std(out Stmt s)
        {
            s = null;
            if (this.Column != 0)
                throw new ParseException("VAR must be in 1st column", this);
            Tokenizer.Advance("VAR");
            if (!(Tokenizer.Current is SizeToken))
                Tokenizer.Advance("(eol)");

            while (Tokenizer.Current is SizeToken)
            {
                SizeToken sizeToken = Tokenizer.GetToken() as SizeToken;
                if (sizeToken == null)
                    throw new ParseException("Expected BYTE|WORD|LONG", sizeToken);
                while (true)
                {
                    IdToken varName = Tokenizer.GetToken() as IdToken;
                    if (varName == null)
                        throw new ParseException("Expected VAR name", varName);
                    ArrayList countExprList = new ArrayList();
                    if (Tokenizer.Current.Text == "[")
                    {
                        Tokenizer.Advance("[");
                        while (true)
                        {
                            countExprList.Add(ParseExpression(Tokenizer, 13));
                            if (Tokenizer.Current.Text != ",")
                                break;
                            Tokenizer.Advance(",");
                        }
                        Tokenizer.Advance("]");
                    }
                    SymbolTable.AddVarSymbol(varName, sizeToken, countExprList);
                    if (Tokenizer.Current.Text != ",")
                        break;
                    Tokenizer.Advance(",");
                }
                Tokenizer.Advance("(eol)");
            }
            return true;
        }
Пример #6
0
        public override bool Std(out Stmt s)
        {
            int indent = Tokenizer.Current.Column;
            SimpleToken token = Tokenizer.GetToken();	// REPEAT
            int endLineNumber = token.LineNumber;
            RepeatType type;
            bool whileNotUntil = true;

            Expr repeatExpr = null;
            Expr fromExpr = null;
            Expr toExpr = null;
            Expr stepExpr = null;

            if (Tokenizer.Current.Text != "(eol)")
            {
                if (Tokenizer.Current.Text.ToUpper() == "WHILE" || Tokenizer.Current.Text.ToUpper() == "UNTIL")
                {
                    type = RepeatType.WhileLoop;
                    whileNotUntil = Tokenizer.GetToken().Text.ToUpper() == "WHILE";
                    repeatExpr = ParseExpression(Tokenizer, 13);
                }
                else
                {
                    repeatExpr = ParseExpression(Tokenizer, 13);
                    if (Tokenizer.Current.Text == "(eol)")
                    {
                        type = RepeatType.NTimes;
                    }
                    else
                    {
                        type = RepeatType.FromTo;
                        Tokenizer.Advance("FROM");
                        fromExpr = ParseExpression(Tokenizer, 13);
                        Tokenizer.Advance("TO");
                        toExpr = ParseExpression(Tokenizer, 13);
                        if (Tokenizer.Current.Text != "(eol)")
                        {
                            Tokenizer.Advance("STEP");
                            stepExpr = ParseExpression(Tokenizer, 13);
                        }
                    }
                }
            }
            else
            {
                type = RepeatType.Plain;
            }
            endLineNumber = Tokenizer.Current.LineNumber;
            Tokenizer.Advance("(eol)");

            ArrayList statementsList = ParseStatements(Tokenizer, indent);

            if (type == RepeatType.Plain && Tokenizer.Current.Column == indent &&
                (Tokenizer.Current.Text.ToUpper() == "WHILE" || Tokenizer.Current.Text.ToUpper() == "UNTIL"))
            {
                type = RepeatType.LoopWhile;
                whileNotUntil = Tokenizer.GetToken().Text.ToUpper() == "WHILE";
                repeatExpr = ParseExpression(Tokenizer, 13);
                /// probably have to get start/end info for WHILE|UNTIL <expr>, tag it onto RepeatStmt somehow;;;
                Tokenizer.Advance("(eol)");
            }
            if (type != RepeatType.FromTo)
            {
                s = new RepeatStmt(token, endLineNumber, type, repeatExpr, statementsList, whileNotUntil);
            }
            else
            {
                s = new RepeatFromToStmt(token, endLineNumber, repeatExpr, fromExpr, toExpr, stepExpr, statementsList);
            }
            return true;
        }
Пример #7
0
        public override bool Std(out Stmt s)
        {
            Token returnToken = Tokenizer.GetToken();	// "RETURN"
            if (Tokenizer.Current.Text != "(eol)")
            {
                Expr e = ParseExpression(Tokenizer, 13);
                s = new ReturnStmt(returnToken, Tokenizer.Current.LineNumber, e);
            }
            else
                s = new ReturnStmt(returnToken, returnToken.LineNumber, null);

            Tokenizer.Advance("(eol)");
            return true;
        }
Пример #8
0
        public override bool Std(out Stmt s)
        {
            s = null;

            ArrayList localNameList = new ArrayList();
            ArrayList localCountList = new ArrayList();
            // I *should* make a name/countExpr structure, but I'm too lazy,
            // so for now I'll keep name and count expressions in parallel arraylists.

            localNameList.Add(null);	// placeholder for result variable
            localCountList.Add(null);	// and its count expression.

            if (this.Column != 0)
                throw new ParseException("PUB/PRI must be in 1st column", this);
            Tokenizer.Advance();	// past "PUB" or "PRI"
            SimpleToken token = Tokenizer.GetToken();
            IdToken methodName = token as IdToken;
            if (methodName == null)
                throw new ParseException("Expected method name", token);

            int nParams = 0;

            if (Tokenizer.Current.Text == "(")	// Parse parameter list.
            {
                Tokenizer.Advance("(");
                while (true)
                {
                    IdToken paramToken = Tokenizer.Current as IdToken;
                    if (paramToken == null)
                        throw new ParseException("Expected parameter name", Tokenizer.Current);
                    Tokenizer.Advance();
                    localNameList.Add(paramToken);
                    localCountList.Add(null);
                    ++nParams;
                    if (Tokenizer.Current.Text != ",")
                        break;
                    Tokenizer.Advance(",");
                }
                Tokenizer.Advance(")");
            }
            if (Tokenizer.Current.Text == ":") // Parse result variable.
            {
                Tokenizer.Advance(":");
                Token t = Tokenizer.GetToken();
                IdToken resultToken = t as IdToken;
                if (resultToken == null)
                {
                    if (t.Text.ToUpper() == "RESULT")
                        resultToken = new IdToken(t);
                    else
                        throw new ParseException("Expected result variable", t);
                }
                localNameList[0] = resultToken;
            }
            if (Tokenizer.Current.Text == "|") // Parse local variables.
            {
                Tokenizer.Advance("|");
                while (true)
                {
                    IdToken localToken = Tokenizer.GetToken() as IdToken;
                    if (localToken == null)
                        throw new ParseException("Expected local variable name", Tokenizer.Current);
                    localNameList.Add(localToken);
                    if (Tokenizer.Current.Text == "[")
                    {
                        Tokenizer.Advance("[");
                        localCountList.Add(ParseExpression(Tokenizer, 13));
                        Tokenizer.Advance("]");
                    }
                    else
                    {
                        localCountList.Add(null);
                    }
                    if (Tokenizer.Current.Text != ",")
                        break;
                    Tokenizer.Advance(",");
                }
            }
            int endLineNumber = Tokenizer.Current.LineNumber;

            Tokenizer.Advance("(eol)");

            ArrayList statementList = ParseStatements(Tokenizer, -1);

            SymbolTable.AddMethod(methodName, isPub, nParams, localNameList, localCountList, statementList, endLineNumber);
            return true;
        }
Пример #9
0
 public override bool Std(out Stmt s)
 {
     SimpleToken rebootToken = Tokenizer.GetToken();
     s = new RebootStmt(rebootToken, Tokenizer.Current.LineNumber);
     Tokenizer.Advance("(eol)");
     return true;
 }
Пример #10
0
        public override bool Std(out Stmt s)
        {
            int indent = Tokenizer.Current.Column;
            SimpleToken token = Tokenizer.GetToken();	// NEXT | CONTINUE

            s = new NextQuitStmt(token, Tokenizer.Current.LineNumber);
            Tokenizer.Advance("(eol)");
            return true;
        }
Пример #11
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;
        }
Пример #12
0
        public override bool Std(out Stmt s)
        {
            int indent = Tokenizer.Current.Column;
            Token IfToken = Tokenizer.GetToken();	// "IF" (or "IFNOT" or "ELSEIF" or "ELSEIFNOT")

            Expr condExpr = ParseExpression(Tokenizer, 13);
            int endLineNumber = Tokenizer.Current.LineNumber;
            Tokenizer.Advance("(eol)");

            SimpleToken elseToken = null;
            int elseEndLineNumber = 0;

            ArrayList ifStatementsList = ParseStatements(Tokenizer, indent);

            ArrayList elseStatementsList = null;
            if (Tokenizer.Current.Column == indent)
            {
                if (Tokenizer.Current.Text.ToUpper() == "ELSE")
                {
                    elseToken = Tokenizer.GetToken();
                    elseEndLineNumber = Tokenizer.Current.LineNumber;
                    Tokenizer.Advance("(eol)");
                    elseStatementsList = ParseStatements(Tokenizer, indent);
                }
                else if (Tokenizer.Current.Text.ToUpper() == "ELSEIF" || Tokenizer.Current.Text.ToUpper() == "ELSEIFNOT")
                {
                    Stmt elseifStmt;
                    Std(out elseifStmt);
                    elseStatementsList = new ArrayList();
                    elseStatementsList.Add(elseifStmt);
                }
            }
            s = new IfStmt(IfToken, endLineNumber, elseToken, elseEndLineNumber, condExpr, ifStatementsList, elseStatementsList);
            return true;
        }
Пример #13
0
 public override bool Std(out Stmt s)
 {
     SimpleToken fillMoveToken = Tokenizer.GetToken();
     ArrayList argList = ParseArgumentList(Tokenizer);
     if (argList.Count != 3)
         throw new ParseException("Expected three arguments", Tokenizer.Current);
     s = new FillMoveStmt(fillMoveToken, Tokenizer.Current.LineNumber, argList);
     Tokenizer.Advance("(eol)");
     return true;
 }
Пример #14
0
        public override bool Std(out Stmt s)
        {
            s = null;
            bool afterRes = false;

            Tokenizer.SetLocalLabelParsingEnable(true);

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

            while (!(Tokenizer.Current is BlockDesignatorToken) && Tokenizer.Current.Text != "(eof)")
            {
                IdToken labelToken = null;
                if (Tokenizer.Current is IdToken)
                {
                    labelToken = Tokenizer.GetToken() as IdToken;
                }
                if (Tokenizer.Current.Text.ToUpper() == "ORG")
                {
                    SimpleToken orgToken = Tokenizer.GetToken();
                    if (labelToken != null)
                        SymbolTable.AddDatLabelEntry(4, labelToken, false);
                    Expr orgExpr = null;
                    if (Tokenizer.Current.Text != "(eol)")
                        orgExpr = ParseExpression(Tokenizer, 13);
                    else
                        Tokenizer.PrintWarning("ORG without address (defaults to 0)", Tokenizer.Current);
                    SymbolTable.AddDatOrgEntry(orgToken, orgExpr, Tokenizer.Current.LineNumber);
                    Tokenizer.Advance("(eol)");
                    afterRes = false;
                    continue;
                }
                else if (Tokenizer.Current.Text.ToUpper() == "ORGX")
                {
                    SimpleToken orgxToken = Tokenizer.GetToken();
                    if (labelToken != null)
                        SymbolTable.AddDatLabelEntry(0, labelToken, false);
                    SymbolTable.AddDatOrgxEntry(orgxToken);
                    Tokenizer.Advance("(eol)");
                    afterRes = false;
                    continue;
                }
                else if (Tokenizer.Current.Text.ToUpper() == "RES")
                {
                    SimpleToken resToken = Tokenizer.GetToken();
                    if (labelToken != null)
                        SymbolTable.AddDatLabelEntry(4, labelToken, false);
                    Expr e = null;
                    if (Tokenizer.Current.Text != "(eol)")
                        e = ParseExpression(Tokenizer, 13);
                    else
                        Tokenizer.PrintWarning("RES without count (defaults to 1)", Tokenizer.Current);
                    SymbolTable.AddDatResEntry(resToken, e, Tokenizer.Current.LineNumber);

                    Tokenizer.Advance("(eol)");
                    afterRes = true;
                    continue;
                }
                else if (Tokenizer.Current.Text.ToUpper() == "FIT")
                {
                    SimpleToken fitToken = Tokenizer.GetToken();
                    if (labelToken != null)
                        SymbolTable.AddDatLabelEntry(0, labelToken, false);
                    Expr e = null;
                    if (Tokenizer.Current.Text != "(eol)")
                        e = ParseExpression(Tokenizer, 13);
                    SymbolTable.AddDatFitEntry(fitToken, e);
                    Tokenizer.Advance("(eol)");
                    continue;
                }
                else if (Tokenizer.Current.Text.ToUpper() == "FILE")
                {
                    if (afterRes)
                        Tokenizer.PrintWarning("FILE after RES", Tokenizer.Current);
                    SimpleToken fileToken = Tokenizer.GetToken();
                    if (labelToken != null)
                        SymbolTable.AddDatLabelEntry(0, labelToken, false);
                    SimpleToken filenameToken = Tokenizer.Current;
                    string filename = "";
                    while (true)
                    {
                        Expr e = ParseExpression(Tokenizer, 13);
                        filename += (char)(Expr.EvaluateIntConstant(e));
                        if (Tokenizer.Current.Text != ",")
                            break;
                        Tokenizer.Advance(",");
                    }
                    try
                    {
                        filenameToken.Text = filename;
                        string path = Options.TryPaths(filenameToken);
                        FileStream fs = new FileStream(path + filename, FileMode.Open);
                        BinaryReader br = new BinaryReader(fs);
                        byte[] bytes = br.ReadBytes((int)fs.Length);
                        SymbolTable.AddDatFileEntry(fileToken, filenameToken, bytes, Tokenizer.Current.LineNumber);
                    }
                    catch (Exception e)
                    {
                        throw new ParseException(e.Message, filenameToken);
                    }
                    Tokenizer.Advance("(eol)");
                    continue;
                }
                if (Tokenizer.Current.Text == "(eol)")
                {
                    if (labelToken != null)
                        SymbolTable.AddDatLabelEntry(0, labelToken, true);
                }
                else if (Tokenizer.Current is SizeToken)
                {
                    if (afterRes)
                        Tokenizer.PrintWarning("Data after RES", Tokenizer.Current);
                    SizeToken alignmentToken = Tokenizer.GetToken() as SizeToken;
                    int alignment = SizeSpecifier(alignmentToken.Text);

                    SimpleToken firstToken = alignmentToken;

                    if (labelToken != null)
                    {
                        SymbolTable.AddDatLabelEntry(alignment, labelToken, false);
                        firstToken = labelToken;
                    }

                    if (Tokenizer.Current.Text != "(eol)")
                    {
                        while (true)
                        {
                            int size = alignment;
                            if (Tokenizer.Current is SizeToken)
                            {
                                SizeToken sizeToken = Tokenizer.GetToken() as SizeToken;
                                size = SizeSpecifier(sizeToken.Text);
                                if (size < alignment)
                                    throw new ParseException("Size override must be larger", sizeToken);
                            }
                            Expr dataExpr = ParseExpression(Tokenizer, 13);
                            Expr countExpr = null;
                            if (Tokenizer.Current.Text == "[")
                            {
                                Tokenizer.Advance("[");
                                countExpr = ParseExpression(Tokenizer, 13);
                                Tokenizer.Advance("]");
                            }
                            SymbolTable.AddDatDataEntry(alignment, size, dataExpr, countExpr, firstToken);
                            if (Tokenizer.Current.Text != ",")
                                break;
                            Tokenizer.Advance(",");
                        }
                    }
                    else
                    {
                        SymbolTable.AddDatDataEntry(alignment, alignment, new IntExpr(null, 0), new IntExpr(null, 0), firstToken);
                    }
                    SymbolTable.AddDatSourceReference(Tokenizer.Current);
                }
                else	// assembly language
                {
                    if (labelToken != null)						// handle label if there is one
                        SymbolTable.AddDatLabelEntry(4, labelToken, false);

                    SimpleToken token = Tokenizer.Current;

                    int cond = 0x0f;			// default is IF_ALWAYS
                    CondToken condToken = null;
                    if (Tokenizer.Current is CondToken)
                    {
                        condToken = Tokenizer.GetToken() as CondToken;
                        cond = condToken.CondValue;
                    }
                    if (!(Tokenizer.Current is IPropInstruction))
                        throw new ParseException("Expected instruction mnemonic", Tokenizer.Current);

                    if (afterRes)
                        Tokenizer.PrintWarning("Assembly language after RES", Tokenizer.Current);

                    string mnemonic = Tokenizer.Current.Text.ToUpper();
                    IPropInstruction instruction = Tokenizer.GetToken() as IPropInstruction;
                    if (instruction.Propcode == 0)
                    {
                        if (condToken != null)
                            throw new ParseException("Condition not allowed on NOP", condToken);
                        cond = 0;
                    }
                    Expr eD = null;
                    Expr eS = null;
                    bool immediate = false;
                    if (instruction.InstructionType == InstructionTypeEnum.D || instruction.InstructionType == InstructionTypeEnum.DS)
                    {
                        eD = ParseExpression(Tokenizer, 13);
                    }
                    if (instruction.InstructionType == InstructionTypeEnum.DS)
                    {
                        Tokenizer.Advance(",");
                    }
                    if (instruction.InstructionType == InstructionTypeEnum.S || instruction.InstructionType == InstructionTypeEnum.DS)
                    {
                        if ((mnemonic == "JMP" || mnemonic == "DJNZ" || mnemonic == "TJNZ" || mnemonic == "TJZ") && Tokenizer.Current.Text != "#")
                            Tokenizer.PrintWarning(mnemonic + " with non-immediate operand", Tokenizer.Current);
                        if (Tokenizer.Current.Text == "#" || mnemonic == "CALL")
                        {
                            Tokenizer.Advance("#");
                            immediate = true;
                        }
                        eS = ParseExpression(Tokenizer, 13);
                    }
                    if (mnemonic == "CALL")
                    {
                        if (!(eS is IdExpr))
                            throw new ParseException("Expected label", eS.Token);
                        eD = new IdExpr(new SimpleToken(Tokenizer, SimpleTokenType.Id, eS.Token.Text + "_ret", eS.Token.LineNumber, eS.Token.Column));
                    }
                    bool memoryInstruction = mnemonic.StartsWith("RD") || mnemonic.StartsWith("WR");
                    int effect = 0;	// bit 0 - WR
                    // bit 1 - WC
                    // bit 2 - WZ
                    // bit 3 - NR
                    if (Tokenizer.Current is EffectToken && instruction.Propcode != 0)	// No effects allowed on NOP
                    {
                        while (true)
                        {
                            Token effectToken = Tokenizer.GetToken();
                            int e = (effectToken as EffectToken).Effect;
                            if (e == 1)		// WR
                            {
                                if (memoryInstruction)
                                    throw new ParseException("Memory instructions cannot use WR/NR", effectToken);
                                effect &= 7;	// clear NR bit
                            }
                            else if (e == 8)	// NR?
                            {
                                if (memoryInstruction)
                                    throw new ParseException("Memory instructions cannot use WR/NR", effectToken);
                                effect &= 0xe;	// clear WR bit
                            }
                            effect |= e;
                            if (Tokenizer.Current.Text == "(eol)")
                                break;
                            Tokenizer.Advance(",");
                        }
                    }
                    SymbolTable.AddDatInstructionEntry(instruction, cond, eD, eS, immediate, effect, token, Tokenizer.Current.LineNumber);
                }
                Tokenizer.Advance("(eol)");
            }
            Tokenizer.SetLocalLabelParsingEnable(false);
            return true;
        }
Пример #15
0
        public override bool Std(out Stmt s)
        {
            s = null;
            if (this.Column != 0)
                throw new ParseException("CON must be in 1st column", this);
            Tokenizer.Advance();	// past "CON"
            if (Tokenizer.Current.Text == "(eol)")
                Tokenizer.Advance("(eol)");

            Expr conOrgExpr = new IntExpr(new SimpleToken(Tokenizer, SimpleTokenType.IntLiteral, "0", 0, 0, 0), 0);

            while (true)
            {
                if (Tokenizer.Current.Text == "#")
                {
                    Tokenizer.Advance("#");
                    conOrgExpr = ParseExpression(Tokenizer, 13);
                }
                else if (Tokenizer.Current is IdToken)
                {
                    IdToken constantName = Tokenizer.GetToken() as IdToken;
                    if (Tokenizer.Current.Text == "=")
                    {
                        Tokenizer.Advance("=");
                        SymbolTable.AddConSymbol(constantName, ParseExpression(Tokenizer, 13));
                    }
                    else
                    {
                        SymbolTable.AddConSymbol(constantName, conOrgExpr);
                        if (Tokenizer.Current.Text == "[")
                        {
                            Tokenizer.Advance("[");
                            Expr incrExpr = ParseExpression(Tokenizer, 13);
                            Tokenizer.Advance("]");

                            conOrgExpr = new BinaryExpr(
                                new SimpleToken(Tokenizer, SimpleTokenType.Op, "+", 0, 0),
                                666, // fake opcode
                                conOrgExpr, incrExpr);
                        }
                        else
                        {
                            Expr incrExpr = new IntExpr(new SimpleToken(Tokenizer, SimpleTokenType.IntLiteral, "(1)", 0, 0, 1), 1);

                            conOrgExpr = new BinaryExpr(
                                new SimpleToken(Tokenizer, SimpleTokenType.Op, "+", 0, 0),
                                666, // fake opcode
                                conOrgExpr, incrExpr);
                        }
                    }
                }
                else
                    break;
                if (Tokenizer.Current.Text == ",")
                    Tokenizer.Advance(",");
                else
                    Tokenizer.Advance("(eol)");
            }
            return true;
        }
Пример #16
0
 public override bool Std(out Stmt s)
 {
     Tokenizer.Advance();
     ArrayList argList = ParseArgumentList(Tokenizer);
     if (argList.Count != 1)
         throw new ParseException("Expected one argument", Tokenizer.Current);
     s = new CogstopStmt(this, Tokenizer.Current.LineNumber, argList);
     Tokenizer.Advance("(eol)");
     return true;
 }