예제 #1
0
        private StatementNode Declarar()
        {
            if (token.type != TokenType.DECL_KW)
            {
                throw new SyntaxErrorException("decl keyword expected on row " + token.row +
                                               " and column " + token.column);
            }
            GetNextToken();
            if (
                token.type != TokenType.ID &&
                token.type != TokenType.BOOL_KW &&
                token.type != TokenType.INT_KW
                )
            {
                throw new SyntaxErrorException("type identifier expected on row " + token.row +
                                               " and column " + token.column);
            }
            var varType = new VarTypeNode(token.lexema);

            GetNextToken();
            if (token.type != TokenType.ID)
            {
                throw new SyntaxErrorException("identifier expected on row " + token.row +
                                               " and column " + token.column);
            }
            var varID = new  IDNode(token.lexema);

            GetNextToken();
            var rankSpecifier = OptionalRankSpecifier(new List <int>());

            if (token.type != TokenType.END_STATEMENT)
            {
                throw new SyntaxErrorException("; expected on row " + token.row +
                                               " and column " + token.column);
            }
            GetNextToken();
            return(new DeclarationStatement(varType, varID, rankSpecifier));
        }
예제 #2
0
 public DeclarationStatement(VarTypeNode varType, IDNode varID, List <int> rankSpecifier)
 {
     this.varType       = varType;
     this.varID         = varID;
     this.rankSpecifier = rankSpecifier;
 }