예제 #1
0
        public pStatus Parse(string line, int linenumber)
        {
            bool finishInternal = false;
            bool doEsle = false;

            if (nested != null)
            {
                pStatus stat= nested.Parse(line, linenumber);
                if (stat==pStatus.Working || stat == pStatus.SyntaxError)
                {
                    return stat;
                }
                else if (stat == pStatus.Finished)
                {
                    finishInternal = true;

                }
            }
            else
            {
                //short f=0;
            }

            int part = indent.doIndentation(line);
            if (part < 0)
            {
                return pStatus.Finished;
            }

            string shortString = line.Trim(StringUtil.whitespace);

            if (finishInternal)
            {
                CodeBlock b = nested.getBlock();
                doEsle = elseMatcher.match(shortString);
                if (doEsle)
                {
                    shortString = elseMatcher.getArgs()["condition"];
                    if (shortString.StartsWith(" "))
                    {
                        shortString = shortString.Substring(1);
                    }
                }

                if (lastBlockKind == BlockKind.Condition)
                {
                    if (doEsle)
                    {
                        b.add(new Opcode(opcodeType.jump, new ArgumentValue(addressMode.constint, substitutionType.EndIf, ClassDatabase.integer)));
                    }
                }
                else
                {
                    b.add(new Opcode(opcodeType.jump, new ArgumentValue(addressMode.constint, substitutionType.BlockStart, ClassDatabase.integer)));
                }
                internalBlock.add(b);
                nested = null;

                if (!doEsle)
                {
                    block.add(internalBlock);
                    internalBlock = null;
                }
                else
                {

                }

            }

            if (parseParts.Count > 0)
            {
                parseParts.Clear();
            }

            if (localVariableMathcer.match(shortString))
            {
                Dictionary<string, string> args = localVariableMathcer.getArgs();
                if (locals.ContainsKey(args["name"]))
                {
                    ArgumentValue argva = EvalExpression(args["expression"]);
                    LocalVariable lvar = locals[args["name"]];
                    if (lvar.kind.isParent(argva.getKind()))
                    {
                        block.add(Phrase.assign.toSubstituedPhrase(new[] { argva, new ArgumentValue(addressMode.frameint, getFramePos(lvar.index)) },
                            null));
                    }

                    indent.expect(false, true, true);
                }
                else
                {
                    ArgumentValue k = EvalExpression(args["expression"]);
                    block.add(Phrase.assign.toSubstituedPhrase(new[] { k,
                    new ArgumentValue(addressMode.frameint, getFramePos(locals.Count)),
                    }, null));
                    locals.Add(args["name"], new LocalVariable(locals.Count, k.getKind()));

                    indent.expect(false, true, true);
                }
            }
            else if (ifMatcher.match(shortString))
            {

                lastBlockKind = BlockKind.Condition;
                setUpCondition(ifMatcher.getArgs()["condition"]);
            }
            else if (whileMatcher.match(shortString))
            {
                lastBlockKind = BlockKind.Loop;
                setUpCondition(whileMatcher.getArgs()["condition"]);
            }
            else if (doEsle && shortString == ":")
            {
                setUpCondition();
            }
            else if (doEsle)
            {
                throw new Errors.SyntaxError("else without a valid condition");
            }
            else
            {

                EvalExpression(shortString, false);
                indent.expect(false, true, true);
            }
            return pStatus.Working;
        }
예제 #2
0
 public void setUpCondition()
 {
     if (internalBlock == null)
     {
         internalBlock = new ifElseCodeBlock();
     }
     nested = new CodeParser(cdtb, fdtb, sdtb, indent, locals);
     internalBlock.addIfRange(internalBlock.Count, internalBlock.Count);
 }
예제 #3
0
        public pStatus Parse2(string line, int linenumber)
        {
            if (isComment(line))
            {
                return pStatus.Working;
            }
            if (Phate2Block != null)
            {
                pStatus result= Phate2Block.Parse(line, linenumber);
                if (result == pStatus.Finished)
                {
                    key.setBlock(Phate2Block.getBlock());
                    Phate2Block = null;
                }
                else
                {
                    return result;
                }
            }

            if (startLines.ContainsKey(linenumber))
            {
                manager.clear();
                manager.expect(true, false, false);
                manager.doIndentation(line);
                Phate2Block = new CodeParser(databases, startLines[linenumber], manager);
                key = startLines[linenumber];

            }
            return pStatus.Working;
        }