Ejemplo n.º 1
0
        private ScopedProgram Block()
        {
            if (!Accept(Symbol.Begin))
            {
                return(null);
            }

            ScopedProgram block = new ScopedProgram();

            while (true)
            {
                IStatement stm = Statement();
                if (stm == null)
                {
                    throw new SyntaxException("beginning of a statement", current);
                }
                block.Add(stm);
                if (!Accept(Symbol.SemiColon))
                {
                    Require(Symbol.End);
                    break;
                }
                if (Accept(Symbol.End))
                {
                    break;
                }
            }

            return(block);
        }
Ejemplo n.º 2
0
 public Procedure(Identifier Identifier, Parameters Parameters, ScopedProgram Block, MiniPascalType Type)
 {
     identifier      = Identifier;
     this.Parameters = Parameters;
     block           = Block;
     ReturnType      = Type;
 }
Ejemplo n.º 3
0
 private Procedure ProcedureStatement()
 {
     if (Accept(Symbol.Procedure))
     {
         Identifier ident = Identifier();
         Require(Symbol.ClosureOpen);
         Parameters parameters = ReadParameters();
         Require(Symbol.ClosureClose);
         Require(Symbol.SemiColon);
         ScopedProgram block = Block();
         block.AddParameters(parameters);
         return(new Procedure(ident, parameters, block, null));
     }
     return(null);
 }
Ejemplo n.º 4
0
        private AbstractSyntaxTree Program()
        {
            Require(Symbol.Program);
            Identifier ident = Identifier();

            if (ident == null)
            {
                throw new SyntaxException("Program must have a name");
            }
            Require(Symbol.SemiColon);
            ScopedProgram block = Block();

            if (block == null)
            {
                throw new SyntaxException("Program must start with a block");
            }
            Require(Symbol.Period);
            return(new AbstractSyntaxTree(block, ident));
        }
Ejemplo n.º 5
0
 private Procedure ReadFunction()
 {
     if (Accept(Symbol.Function))
     {
         Identifier ident = Identifier();
         Require(Symbol.ClosureOpen);
         Parameters parameters = ReadParameters();
         Require(Symbol.ClosureClose);
         Require(Symbol.Colon);
         MiniPascalType type = ReadType();
         if (type == null)
         {
             throw new SyntaxException(expType, current);
         }
         Require(Symbol.SemiColon);
         ScopedProgram block = Block();
         block.AddParameters(parameters);
         return(new Procedure(ident, parameters, block, type));
     }
     return(null);
 }
Ejemplo n.º 6
0
        private IStatement StructuredStatement()
        {
            ScopedProgram block = Block();

            if (block != null)
            {
                return(block);
            }
            If ifStm = IfStatement();

            if (ifStm != null)
            {
                return(ifStm);
            }
            While whileStm = ReadWhile();

            if (whileStm != null)
            {
                return(whileStm);
            }
            return(null);
        }