コード例 #1
0
ファイル: Parser.cs プロジェクト: PixarV/peg-spo
        public NonTerminal SubprogramHead(SubprogramType subprogramType)
        {
            var identifier = Identifier();
            var parameters = new List <NonTerminal>();

            CheckType(TokenType.LeftParenthesis, true);

            while (Peek().TokenType != TokenType.RightParenthesis)
            {
                var declaration = Declaration();
                parameters.Add(declaration);
                CheckSymbol(TokenType.RightParenthesis, TokenType.Semicolon);
            }

            Eat();

            Type returnType = null;

            if (subprogramType == SubprogramType.Function)
            {
                CheckType(TokenType.Colon, true);
                returnType = Type();
            }

            CheckType(TokenType.Semicolon, true);

            return(new SubprogramHead(subprogramType, identifier, parameters, returnType));
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: PixarV/peg-spo
        public NonTerminal Subprogram(SubprogramType type)
        {
            var subprogramHead     = SubprogramHead(type);
            var declarations       = Declarations();
            var compoundStatements = CompoundStatement();

            return(new Subprogram(subprogramHead, declarations, compoundStatements));
        }
コード例 #3
0
 public SubprogramHead(SubprogramType subprogramType, Identifier identifier, List <NonTerminal> parameters,
                       Type returnType)
 {
     SubprogramType = subprogramType;
     Identifier     = identifier;
     Parameters     = parameters;
     ReturnType     = returnType;
 }