Exemple #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);
        }
Exemple #2
0
 public Procedure(Identifier Identifier, Parameters Parameters, ScopedProgram Block, MiniPascalType Type)
 {
     identifier      = Identifier;
     this.Parameters = Parameters;
     block           = Block;
     ReturnType      = Type;
 }
 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);
 }
Exemple #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));
        }
 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);
 }
        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);
        }